msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

VBA user, first time on Vbasic. Need help referencing a con

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
adam_kroger



Joined: 10 Oct 2007
Posts: 2

PostPosted: Tue Oct 09, 2007 8:04 pm    Post subject: VBA user, first time on Vbasic. Need help referencing a con Reply with quote

SItuation: I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I
want to be able to reference them using a For/Next loop. In VBA I
would use something like this:
for i = 1 to 6
me.controls("LIS" & i).Value = ""
next i

Nedless to say, the Controls("LIS" & i).text doesn't work...

What do I need to do differently?

ALSO, in VBA if I wanted an expression to be resolved before being
addressed by the rest of the line I could enclose it in [ ] or use
evaluate(). Is there something similar in VBasic.

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Randy Birch



Joined: 04 Oct 2007
Posts: 1768

PostPosted: Wed Oct 10, 2007 12:26 am    Post subject: Re: VBA user, first time on Vbasic. Need help referencing a Reply with quote

In visual basic, you create a control array - drop 1 control on the form,
name it as desired, copy, paste, select Yes to the dialog, and paste more
until the desired number is achieved.

All controls now share the same event, and are differentiated by the index
passed as a parameter to the event. Elsewhere in the code, you can now loop
using the index to reference the specific controls, e.g.,

for cnt = thetextboxname.lbound to thetextboxname.ubound
thetextboxname(cnt)="whatever"
next

So if the text box was called txtClient:

for cnt = txtClient.lbound to txtClient.ubound
txtClient(cnt).Text = "whatever"
next


--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.


wrote in message @r29g2000hsg.googlegroups.com...
SItuation: I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I
want to be able to reference them using a For/Next loop. In VBA I
would use something like this:
for i = 1 to 6
me.controls("LIS" & i).Value = ""
next i

Nedless to say, the Controls("LIS" & i).text doesn't work...

What do I need to do differently?

ALSO, in VBA if I wanted an expression to be resolved before being
addressed by the rest of the line I could enclose it in [ ] or use
evaluate(). Is there something similar in VBasic.
Back to top
View user's profile Send private message
Ralph



Joined: 04 Oct 2007
Posts: 4148

PostPosted: Wed Oct 10, 2007 12:44 am    Post subject: Re: VBA user, first time on Vbasic. Need help referencing a Reply with quote

I bet he is using dotNet.
Back to top
View user's profile Send private message
adam_kroger



Joined: 10 Oct 2007
Posts: 2

PostPosted: Wed Oct 10, 2007 7:39 pm    Post subject: Re: VBA user, first time on Vbasic. Need help referencing a Reply with quote

I am using 2005 and (according to the documentation)the control arrays
have been removed in this version so that solution will not work. Is
there a method that will force "LIS" & i to resolve into LIS1 before
the me.controls().text is read? or will that type process only
function in script based program language? Alternately is ther a way
to bind the TextBox to a variable so that changes to one can be done
by changing the other (i.e the .ControlSource or .BoundValue in VBA)?

Perhaps a bit more backbround might help... The program determines
the gaps between dates and gives the results. The interface has 22
Masked TextBoxes (forcing Date entries)in groupings of 6,5,5,2,2 and 2
singles, and 31 Labels (for reporting results) in groups of 5 + 1 for
the total; using naming conventions as specified above. I need to be
able to cycle through them to either read the data into array
variables for manipulations and comparisons, or to "reset" them to
blank. I could probably get by on this project with naming them
absolutely, but in my next project, it won't be anywhere near as
straightforward.

I am trying to turn processes I have written in Excel using VBA and
UserForms into stand-alone programs. I am using VisualBasic 2005
Express Edition.

Thanks

On Oct 9, 7:26 pm, "Randy Birch" wrote:
> In visual basic, you create a control array - drop 1 control on the form,

>>

>
> @r29g2000hsg.googlegroups.com...
> SItuation: I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I
> want to be able to reference them using a For/Next loop. In VBA I
> would use something like this:
> for i = 1 to 6
> me.controls("LIS" & i).Value = ""
> next i
>
> Nedless to say, the Controls("LIS" & i).text doesn't work...
>
> What do I need to do differently?
>
> ALSO, in VBA if I wanted an expression to be resolved before being
> addressed by the rest of the line I could enclose it in [ ] or use
> evaluate(). Is there something similar in VBasic.
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Wed Oct 10, 2007 7:46 pm    Post subject: Re: VBA user, first time on Vbasic. Need help referencing a Reply with quote

wrote in message @v3g2000hsg.googlegroups.com...
>I am using 2005 and (according to the documentation)the control arrays
> have been removed in this version

It'd be more correct to say that VB-style control arrays were never added to
that language. That isn't VB.


--
You need to ask in a newsgroup with "dotnet" in the name. This group is for
VB 6.0 and earlier and does not include VB.Net or VB 200x.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group