|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Passing variable then looping
I have an item reference that comes into my program andI then index a table to create say 2 two items.
E.g. Users on say Amazon buys 2 DVDs for 1. The code might be '241', I then need to split this into two lines in a database to end to the warehouse/courier. So it would be 'DVD1' and 'DVD2' I keep getting an error when trying to do it so have split it out without a database as per below and am still having problems. I checked the variables are passed back as well. Option Explicit Private Sub Command1_Click() ' Dim vitem1 As String Dim vitem2 As String Call PrcVariable(vitem1, vitem2) ' Dim Counter1 As Long ' For Counter1 = 1 To 2 '2 might become a variable later in life but for now hard code is ok ' Text1.Text = vitem(Counter1 - 1) ' Next Counter1 End Sub Private Sub PrcVariable(vitem1, vitem2) vitem1 = "1" vitem2 = "2" End Sub |
|
#2
|
|||
|
|||
|
Is vitem an array? If yes, where are you filling the array?
|
|
#3
|
|||
|
|||
|
Quote:
My mistake on the version above. When it calls it should call with the productID and the look for the new products... Code:
Option Explicit
Private Sub Command3_Click()
'
Dim vitem1 As String
Dim vitem2 As String
Dim ItemID As String
ItemID = "241"
Call PrcVariable(ItemID, vitem1, vitem2)
'
Dim Counter3 As Long
'
For Counter3 = 1 To 2
'
Text1.Text = vitem(Counter3 - 1)
'
Next Counter3
End Sub
Private Sub PrcVariable(vitem1, vitem2)
'Then here I would use a database to find the 241 code and extract the two codes I want: (in this case ahrd coded for the test version)
vitem1 = "DVD1"
vitem2 = "DVD2"
End Sub
Last edited by Phoenix_riser : August 10th, 2007 at 08:53 AM. |
|
#4
|
|||
|
|||
|
vitem(Counter3 - 1) will still give an error. What is the exact problem/error that you are facing.
|
|
#5
|
|||
|
|||
|
Quote:
The error is "wrong number of arguments" There is a reason I need the two loops (in reality it is more but 2 will do for the test version) If the above code works then I can put in the database links, rather than hard coding. How do I stop that error? vitem(Counter3) has been tried as COunter3, COunter3 - 1 and Counter3 + 1 just to double check with no joy. Any thoughts? |
|
#6
|
|||
|
|||
|
That error is coming because, the arrary vitem() doesnot have any array elements. You are trying to assign a value from the array element that does not exist. Try some thing like this
|
|
#7
|
|||
|
|||
|
Thank you, working version...
Code:
Option Explicit
Private Sub Command1_Click()
Dim vitem1 As String
Dim vitem2 As String
Dim vitem(0) As String
Dim itemDeal
'
Call PrcVariable(vitem1, vitem2)
'
Dim Counter1 As Long
'
For Counter1 = 1 To 2 '2 might become a variable later in life but for now hard code is ok'
'
If (Counter1) = 1 Then
itemDeal = vitem1 End If
'
If (Counter1) = 2 Then
itemDeal = vitem2
End If
'
Next Counter1
'
End Sub
Private Sub PrcVariable(vitem1, vitem2)
'Then here I would use a database to find the 241 code and extract the two codes I want: (in this case ahrd coded for the test version)
vitem1 = "DVD1"
vitem2 = "DVD2"
End Sub
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Passing variable then looping |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|