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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store text box values in certain location? 1

Status
Not open for further replies.

Ciralia

Programmer
Oct 22, 2002
51
US
If I have two text boxes where one lets the user enter what location to store a value in, and the other text box would be the value to store. I created several text boxes in which act as storage. So, for example if the user enters in one text box " 1 " for the location, and for the other text box they enter " 2 ", is it possible to take the value 2, and store it in text box 1 when they click a command button? This program acts the way memory would in a computer by storing values in certain locations.
 
You can store values related to a textbox in
text1.tag
Tom
 
I've never used that before, could someone explain to me what it does?
 

Ciralia, have you read FAQ222-2244 item 15 yet?

The tag property of controls is like a varient storage space where you can put a value.

Good Luck

 
Yes I have read that, but the answers other people gave for this particular topic have not worked for me yet. So, I am seeking another opinion. Let me rephrase what I said earlier to make it easier to understand.

I have a textbox called txtInput on Form1, and a label call lblTEST on Form2. Without loading Form2, I need to have the label on Form2 to change when the user clicks a button on Form1. I have already tried this piece of code:

Form2.lblTEST.Caption = txtInput.Text

This gives me an error that the method of data member is not found. Therefore, there must be another way to code this.
 

If that ...
[tt]
Form2.lblTEST.Caption = txtInput.Text
[/tt]
was in form1 it should work because form2 should load automatically once there is a reference to it. Now if that code is in form2 then it would need to be...
[tt]
Form2.lblTEST.Caption = Form1.txtInput.Text
[/tt]

Good Luck

 
That piece of code is in a button on Form1. But it does not work. When the program opens, Form1 is the first thing that is shown. I'm wondering if it has something to do with the loading or unloading of the different forms. However, when I type the code out, right after lblTEST. it gives me a short list of options. These options are: Count, Item, LBound, UBound. But it does not offer the Caption option?
 

Ahhh ... then it is part of an array of controls. You need to ...
[tt]
Form2.Label1(Index).Caption = Form1.Text1.Text
[/tt]
to make it work.

Good Luck

 
Well what I have right now is not an array. But I might change it to be one. How would I do that?
 

GoTo the form design window and select the label you are trying to update its caption. Look in the properties window and look at index. If index is anything but blank it is part of an array or listed as such. Do the same for the text box ...
[tt]
Form2.Label1.Caption = Form1.Text1(Index).Text
[/tt]
One or both of them are part of an array and that is where you are having your problems with the error message.

Now there are two simple ways to create an array. The first is to place a control on your form, select it, CTRL+C, CTRL+V, and you will be asked if you want to create an array. Reply yes and you will will have two controls with the same name. The first one that you copied will be index = 0 and the pasted one will be index = 1.

The second way is to place a control in your form and then goto properties window and for the index enter zero (0). If you enter another number when you goto paste a new control VB will try to fill up from zero (0) the indexes. Meaning if you put a two and then paste vb will make the new control with a index of zero and you will end up with one control with an index of zero and one with an index of 2. Then if you paste again the new control will have an index of 1, and the next would have an index of 3.

Good Luck

 
Apparently, you don't need an array. I think it was an array because you accidently created a copy of it at some time, deleted it, and didn't realize that it was still an array. Of course, I could be wrong, but in that case, all you have to do is delete the object and re-create it. it is not too much work to change the properties, and it would save you from possible debugging involving the array...
 
Yes that was it vb5prgrmr, the index was not blank. After I deleted that value, my original line of code to change the caption worked. yay =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top