Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through Controls to set values

Status
Not open for further replies.

icodian

IS-IT--Management
Aug 28, 2001
74
US
I have an old program that I am working to upgrade. The old language was based on VB but was proprietary from what I understand. I am now using VBScript built into the application I am customizing.

In the old app, I had the following loop written to loop through 12 controls and assign values.

for i = 1 to 12
setpropertyof "txtAlloc" & cStr(i), "Text", ""
next i

The names of the 12 controls were 'txtAlloc1,' 'txtAlloc2,' 'txtAlloc3,' etc....

This would loop through them all and set the Text property to blank for all of them. Simple.

Moving to VBScript, I need to accomplish the same thing. I don't have the option of using a control array in the app I am using. Also, I have to do this sort of thing soooo many times, I can't have 12 IF statements every time I need to do it.

Does anyone have any suggestions on the syntax to perform the same functionality in VBScript?

Thanks for any help!
 
Are you specifically doing this using HTML controls?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I don't believe so. I am not including the script in HTML. This is a business management software that uses VBScript for its base. It has its own client that is used for the scripts...so it depends on the types of controls they allow you to use... Not sure if that answers your question.
 
Take a look at the Eval function or the Execute statement.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Are you sure that it's VBScript rather than VBA? The easy way to tell is that VBScript does not allow you to assign a datatype to a variable - they are all assumed to be variants.

If it is then the calling mechanism of the script would normally include some degree of visibility of the hosting application such as a reference to the form or forms so that the script can interact with the application. If this is the case there may be a collection of controls associated with each form that you can use.

If however the interface is really VBA then there will be a Controls collection that you can reference.
 
Yes, it is VBScript... I have been trying to locate a way to refer to a collection of controls on the form without success.

Regarding the Eval/Execute functions. I have looked into these but am not able to tell how these could help me with the current problem. Any suggestions there?

Thanks!
 
this is the VB way of doing it,.,i think
For Each aControl In Frm.Controls
If Left(aControl.Name, 6) = "txtfrm" Then

End If
Next

phv's comment on execute

strX = "hello"
param = "strX=""hello world"""
Execute param
Msgbox strX

Execute "setpropertyof ""txtAlloc"" & cStr(i), ""Text"", """

or something like that, i am sure i have the " wrong


so you might want something like



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top