|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Hello,
could anybody help me with Visual Basic syntax? I can't get to know how to go through a variables or field names in a loop, i.e: while i<10 myform.TextBox[i].Value = myvariable[i] i = i+1 wend Can't find anything in docs! Thank you. Oak |
|
#2
|
|||
|
|||
|
3 Examples of the same thing
Private Sub Command1_Click() Dim var(9) For i = 0 To 9 Text1(i) = var(i) Next i End Sub --------------------------------- Private Sub Command1_Click() Dim var(9) i = 0 While i < 10 Text1(i) = var(i) i = i + 1 Wend End Sub ------------------------------------ Private Sub Command1_Click() Dim var(9) i = 0 Do Text1(i) = var(i) i = i + 1 Loop While i < 10 End Sub ------------------------------------ ![]() |
|
#3
|
|||
|
|||
|
Thank you for your reply,
but it doesn't (if I understand it well) solve my problem. I need to access objects, i.e. TextBox1, TextBox2, TextBox3, ..., TextBoxi. But the way you described works only for arrays, right? I tried this syntax on objects before and it didn't work. Thanks, Oak |
|
#4
|
|||
|
|||
|
Are you trying to get something like
textbox1 textbox2 textbox3 not textbox(1), textbox(2) ... You could loop through your form's controls and pull out the name of every textbox. Otherwise, another option is to use the MS Script control and use VBScript which supports an Execute function, where you can build an executable string in code and then run it.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#5
|
|||
|
|||
|
Hello,
yes that's right. Since you can't name your objets as textbox(1), textbox(2) ..., you have to compose names like TextBox1, etc. In other programing languages its pretty simple - say in PHP I'd do it like this: i = 0; while (i < 10) { myValue = $("textbox".$i); } In PHP you can't assign value to the already made object, so the example is reversed (objects value is assigned to array during form processing). I have a form of 50 rows per 5 objects (part list) and I need a way to access them effectively. The AutoVBA is a bit limited, I can't (it seems) use advanced objects as a tablebox, etc. So any ideas? Thank you Oak Quote:
|
|
#6
|
|||
|
|||
|
Unzip 14kb Access 2003 English
Unzip the attachment . Is 14kb (Unzipped ~ 178kb).
Written with Access 2003 english. I wish i was helpfull dimd80 Athens Greece |
|
#7
|
|||
|
|||
|
I'm working back on the app after some time. Your example is very nice and helpful. Thank you very much.
|
|
#8
|
|||
|
|||
|
In VB you can have Control Arrays. Simply put, you can have 5 Textboxes with the same name - but different indexes. These Textboxes would share common callbacks, and can be easily refrenced similar to the array example given above
Code:
For i = 0 To 4
TextBoxArr(i).Text = "example"
Next
'or in a Do -or- While Loop
i = 0
While i <= 4
TextBoxArr(i).Text = "example"
i += 1
Wend
Do While i <= 4
TextBoxArr(i).Text = "example"
i += 1
Loop
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Variables by step: var1, var2, var3,..., var[i] |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|