im a little confused is the code suppose to be:
- me.controls("text 4" + "text8" + "text12" & format(loopcounter))
...
No, the way it works is that you supply the name of the control, such as Controls("Text1"), to access the control. The business with sticking together "text" and a variable is just to build the name. This has nothing to do with adding up the values, it's just a way of accessing the control to get what's in it, without having to write individual chunks of code for each one. I wouldn't worry about this, though. It's just a way of simulating a control array. You won't need it in VB6.
... or you mentioned control arrays how would that be done, if you don't mind telling me. or explaining to me because you said it might be alot easier ( or something along them lines) to do.
Yes, a control array will make your life much easier. The quick and simple way to create a control array is this...
- Place an ordinary control on the form (in your case, let's use a textbox).
- Set the name to what you want to use - for example, textQty (or whatever).
- Copy the control (select it and hit Ctrl-C, or whatever you prefer).
- Paste it back onto the same form.
- VB will ask you whether you want to create a control array - say "yes".
That's it, you now have a control array containing two textboxes. The textboxes still work exactly the same, of course. The only difference is that any code which refers to them has to specify which one, using an index. In other words, rather than
txQty.Text you use the syntax
txQty(n).Text. Any event procedures are shared by all the controls in the array. In other words, there is one txQty_Click event procedure, which is called when you click any of the textboxes in that array. The event procedures will now include an extra
Index parameter, to indicate which one actually triggered the event.
In case you need it, each control also has an
Index property, indicating which place it holds in the array.
Sorry if this all sounds complicated. It's actually
very simple to do. Just remember that when writing code to use these controls, the differences are just the same as when using an ordinary variable array instead of a plain variable.