Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old November 8th, 2004, 05:56 AM
oakld oakld is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Drogheda, Ireland
Posts: 4 oakld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Variables by step: var1, var2, var3,..., var[i]

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
Comments on this post
JimmyGosling agrees!

Reply With Quote
  #2  
Old November 8th, 2004, 08:59 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 4
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
------------------------------------

Reply With Quote
  #3  
Old November 9th, 2004, 02:43 AM
oakld oakld is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Drogheda, Ireland
Posts: 4 oakld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy But TextBox and other objects?

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

Reply With Quote
  #4  
Old November 9th, 2004, 12:24 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
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

Reply With Quote
  #5  
Old November 11th, 2004, 03:52 AM
oakld oakld is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Drogheda, Ireland
Posts: 4 oakld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
Originally Posted by Doug G
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.

Reply With Quote
  #6  
Old November 11th, 2004, 08:53 AM
dimd80 dimd80 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Greece, Athens
Posts: 29 dimd80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 21 m 41 sec
Reputation Power: 0
Send a message via Yahoo to dimd80
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
Attached Files
File Type: zip test2.zip (13.4 KB, 225 views)

Reply With Quote
  #7  
Old November 19th, 2004, 08:39 AM
oakld oakld is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Drogheda, Ireland
Posts: 4 oakld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Thanks

I'm working back on the app after some time. Your example is very nice and helpful. Thank you very much.

Reply With Quote
  #8  
Old November 19th, 2004, 04:47 PM
indulgence indulgence is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 15 indulgence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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
         

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Variables by step: var1, var2, var3,..., var[i]


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway