Hi,
I have to do search engine for shop (my course assessment) it have to search produckts by code and description. I dont really know how to do it. Can someone help me?

that what i have:

Private Sub Command1_Click()

Dim code(6) As String
Dim description(6) As String
Dim price(6) As Currency


code(1) = A349
code(2) = B359
code(3) = C369
code(4) = D379
code(5) = E389
code(6) = F399

description(1) = Keyring
description(2) = Mug
description(3) = Scarf
description(4) = Pen
description(5) = Doll
description(6) = Pencil

price(1) = 5.99
price(2) = 9.99
price(3) = 14.5
price(4) = 2.49
price(5) = 7.99
price(6) = 0.85

End Sub

Recommended Answers

All 10 Replies

update:

Private Sub Command1_Click(ByVal item As String, byred)

item = Text3.Text
If Option2.Value = True Then
Call codesearch(x, Position)
Else
Call description(x, Position)
End If

quanity = Text2.Text
cost = quanity * price





End Sub

Private Sub codesearch()

End Sub

Private Sub Form_Load()
code(1) = A349
code(2) = B359
code(3) = C369
code(4) = D379
code(5) = E389
code(6) = F399

description(1) = Keyring
description(2) = Mug
description(3) = Scarf
description(4) = Pen
description(5) = Doll
description(6) = Pencil

price(1) = 5.99
price(2) = 9.99
price(3) = 14.5
price(4) = 2.49
price(5) = 7.99
price(6) = 0.85
End Sub

can u change that pseudocode to code?

Get code

Loop through itemarray from 1 to 6
	
If code = itemarray(current value) 
Set Position = current value
Set Counter = 6
End loop

You need to look up the For Loop structure in help and or your book...

For VariableName = 1 To 6
  'do search here (use if statement)
Next VariableName

Good Luck

I dont know nothing about programing. I have problem solving unit involve with software develeopment. I need to write this progra to pass my course and get on HNC technicial support. Maybe someone can write this for me for money?

I think you want declare those variables as public then
put this in form load

code(1) = "A349"
        code(2) = "B359"
        code(3) = "C369"
        code(4) = "D379"
        code(5) = "E389"
        code(6) = "F399"

        description(1) = "Keyring"
        description(2) = "Mug"
        description(3) = "Scarf"
        description(4) = "Pen"
        description(5) = "Doll"
        description(6) = "Pencil"

        price(1) = 5.99
        price(2) = 9.99
        price(3) = 14.5
        price(4) = 2.49
        price(5) = 7.99
        price(6) = 0.85

then add 3 text and one command button

Private Sub Command1_Click() 
  Dim i As Integer
        For i = 1 To 6
            If Text1.Text = code(i) Then
                Text2.Text = description(i)
                Text3.Text = price(i)
            End If

        Next
End Sub

then try !

ok, i have done something like that:

Dim ItemCode(6) As String
Dim Description(6) As String
Dim price(6) As Currency
Option Explicit

Private Sub Command1_Click()
Dim Quantity As Integer
Dim SaleCost As Currency

ItemCode = Text3.Text
Quantity = Text2.Text

If Option2.Value = True Then
Call ItemCodeSearch
Else
Call DescriptionSearch
End If

Let SaleCost = price * Quantity

End Sub
Private Sub ItemCodeSearch(ByRef ItemCode As String, ByRef position As Integer)

For Counter = 1 To 6
If ItemCode = ItemCode(Counter) Then
position = Counter
Counter = 6
Next Counter
End Sub
Private Sub DescriptionSearch(ByRef Description As String, ByRef position As Integer)

For Counter = 1 To 6
If Description = Description(Counter) Then
position = Counter
Counter = 6
Next Counter

End Sub
Private Sub Form_Load()
ItemCode(1) = "A349"
ItemCode(2) = "B359"
ItemCode(3) = "C369"
ItemCode(4) = "D379"
ItemCode(5) = "E389"
ItemCode(6) = "F399"

Description(1) = "keyring"
Description(2) = "mug"
Description(3) = "scarf"
Description(4) = "pen"
Description(5) = "doll"
Description(6) = "pencil"

price(1) = 5.99
price(2) = 9.99
price(3) = 14.5
price(4) = 2.49
price(5) = 7.99
price(6) = 0.85

End Sub

now i have to display:
- whole order in textbox4 (Item Code - Description - Quanity - Price - Sale price)
- Discount VAT Total in textbox6
- Total cost in textbox5

Discount
Less than £15 then 0%
More than £14.99 and less than £30 then 5%
More than £29.99 then 10%

Calculate the VAT at 17.5%

update:

Dim ItemCode(6) As String
Dim Description(6) As String
Dim price(6) As Currency
Dim counter As Integer
Dim Quantity As Integer
Dim SaleCost As Currency
Dim item As String
Dim position As Integer
Dim desc As String

Option Explicit

Private Sub Command1_Click()

item = Text3.Text
Quantity = Text2.Text

If Option2.Value = True Then
Call ItemCodeSearch(item, position)
Else
Call DescriptionSearch(desc, position)
End If

SaleCost = price(position) * Quantity
Text4.Text = SaleCost



End Sub
Private Sub ItemCodeSearch(ByRef item As String, ByRef position As Integer)

For counter = 1 To 6
If item = ItemCode(counter) Then
position = counter
counter = 6
End If
Next counter
End Sub
Private Sub DescriptionSearch(ByRef desc As String, ByRef position As Integer)

For counter = 1 To 6
If desc = Description(counter) Then
position = counter
counter = 6
End If
Next counter

End Sub
Private Sub Form_Load()
ItemCode(1) = "A349"
ItemCode(2) = "B359"
ItemCode(3) = "C369"
ItemCode(4) = "D379"
ItemCode(5) = "E389"
ItemCode(6) = "F399"

Description(1) = "keyring"
Description(2) = "mug"
Description(3) = "scarf"
Description(4) = "pen"
Description(5) = "doll"
Description(6) = "pencil"

price(1) = 5.99
price(2) = 9.99
price(3) = 14.5
price(4) = 2.49
price(5) = 7.99
price(6) = 0.85

End Sub

but its display '0' in order

hi try to replace ur code with this:

Dim ItemCode(6) As String
Dim Description(6) As String
Dim price(6) As Currency
Dim Quantity As Integer
Dim SaleCost As Currency
Dim item As String
Dim position As Integer


Option Explicit

Private Sub Command1_Click()

item = Text3.Text
Quantity = Val(Text2.Text)

If Option2.Value = True Then
    Call CodeSearch(item)
Else
    Call DescriptionSearch(item)
End If

SaleCost = price(position) * Quantity
Text4.Text = ItemCode(position) & " - " & Description(position) & " - " & Quantity & " - " & price(position) & " - " & SaleCost
Text5.Text = SaleCost
Text6.Text = Discount(SaleCost)


End Sub

Private Function Discount(curr As Currency) As Currency
    Dim temp As Currency
    
    If curr < 15 Then
        temp = 0
    ElseIf (curr > 14.99) And (curr < 30) Then
        temp = 0.05
    ElseIf (curr > 29.99) Then
        temp = 0.1
    End If
    
    Discount = curr - (curr * temp)
        
End Function
Private Sub CodeSearch(ByVal code As String)
Dim i As Integer
For i = 1 To 6
    If ItemCode(i) = code Then
        position = i
        Exit For
    End If
Next i
End Sub

Private Sub DescriptionSearch(ByVal Desc As String)
Dim i As Integer
For i = 1 To 6
    If Description(i) = Desc Then
        position = i
        Exit For
    End If
Next i
End Sub

Private Sub Form_Load()
ItemCode(1) = "A349"
ItemCode(2) = "B359"
ItemCode(3) = "C369"
ItemCode(4) = "D379"
ItemCode(5) = "E389"
ItemCode(6) = "F399"

Description(1) = "keyring"
Description(2) = "mug"
Description(3) = "scarf"
Description(4) = "pen"
Description(5) = "doll"
Description(6) = "pencil"

price(1) = 5.99
price(2) = 9.99
price(3) = 14.5
price(4) = 2.49
price(5) = 7.99
price(6) = 0.85

End Sub

it works. thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.