Hi guys its me again i have another problem this is related on my previous topic which is making a label during run time. Now that i have learned how to make a label at run time i also made a textbox during run time which is the same concept with on how to make label during run time(thanks to andre and jx_man). next thing i would do is to get the value what the user have inputed on the textbox which is made during runtime.and display it when i click the get button.

hope you could help me on this one again..by the way heres the link of my prevoius topic

http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/352903

thanks
regardz

androidz

Recommended Answers

All 40 Replies

Actually, quite an easy one. Remember that you have loaded the text boxes with indexes, so you can use something like -

Dim sMyString As String

sMyString = Text1(2).Text 'Where (2) refers to the control loaded.

'This code MUST come AFTER you have loaded the text boxes, otherwise an error will be raised...

andre already answered it..it should works for you :)

So why reply again?:)

ok i will try that one you mean the 2 there is constant?or do i have to replace it?

if my code looks like this

for j = 0 to m_equation - 1
   set txt = me.controls.add("vb.textbox","txtm", & j)  '--does the txt is the control or the txtm?
 next j

so it should look like this:
txtm(txt).text or txtm(2).text?

txtm is the actual text box with all of its indexes, depending on how many you have added, starting at 0 to the amount of text boxes -1. Remember that txtm(0) is the first tex box.

So it should look like the following... Here you will need to know what each textbox receives, which you should because you have created them.;)

ttxm(0) = whatever it was suppose to get before you created it

Use the "j" to determine which is which because "j" adds the index.

Post some code of WHAT the text box will receive so I can see what you need to capture where.

txttm is txt name..
so it should like andre code.. txtm(0).text, txtm(1).Text, txtm(2).Text , and so on.

ah,,andre answered it first :)

commented: Stop posting the bleeding obvious -- it helps no one. -3

hehehe, again, how many beers have you had so far.:) I had 4 and now I'm busy with my first drink. Hey hey its Friday. I'm off now JX, see if you can help the poster to a solution please, thanks.

haha...actualy,,till now your post is good and i believe its make the thread solved :)
and i'm going off too..its late the night

Did the code work for you androidz?

nope i got an error sub or function not defined..

if my code looks like this:

for j = 0 to m_jobs -1 '--m_jobs represents the variable of what the user will input if the user will input 2 then there are two textboxes will be made..
         set txt = me.controls.add("vb.textbox","txtm" & j)
               with txt
                   '-- textbox properties here --
                    .top
                    .height
                    .move
                end with  
                a = txt.Text '--no value
            next j

now this one will made a textbox that has no value yet..the user will input a value into the textbox and after that i made a button named load..after i clicked the button it should get the value of the textbox that was inputed by the user..i tried your code but it will give me error but i tried another one and put it in the code in making a texbox which is a = txt.text but it has no value..i want to get the value inputed by the user after the textbox has been made and depends on how many textbox are being made..hope you could help me on this one tnx

Remember that each textbox that was added has an index now, in other words, txt(0), txt(1) etc. You need to call the index as well -

My1stString = txt(0).Text
My2ndString = txt(1).Text

and so on. If you do not include the index, the error as above will be raised.

To clarify more, you will have say 6 text boxes after your code as above. They are ALL named txt, but with indexes from 0 to 5....

but how could i call the variable for index?coz i will put the code in the load button. coz it depends on how many textbox the user wants. i put a ctr variable that counts how many textboxes have been made during run time and then i used it in the load button
my code looks like this

for ctr = 0 to ctr
            a = txt(j).text '--this will give me an error
      next ctr

nope i got an error sub or function not defined..

if my code looks like this:

for j = 0 to m_jobs -1 '--m_jobs represents the variable of what the user will input if the user will input 2 then there are two textboxes will be made..
         set txt = me.controls.add("vb.textbox","txtm" & j)
               with txt
                   '-- textbox properties here --
                    .top
                    .height
                    .move
                end with  
                a = txt.Text '--no value
            next j

now this one will made a textbox that has no value yet..the user will input a value into the textbox and after that i made a button named load..after i clicked the button it should get the value of the textbox that was inputed by the user..i tried your code but it will give me error but i tried another one and put it in the code in making a texbox which is a = txt.text but it has no value..i want to get the value inputed by the user after the textbox has been made and depends on how many textbox are being made..hope you could help me on this one tnx

Don't try to get value of textboxes when you created it, but in another events like button press.
example :
user input 2 for m_jobs, so program will create 2 textboxes during run time.
then you can get value of from textboxes after user input on it and click on button.

Private Sub load_Click()
  a = txt(0).Text
  b = txt(1).Text
End Sub

but how could i call the variable for index?coz i will put the code in the load button. coz it depends on how many textbox the user wants. i put a ctr variable that counts how many textboxes have been made during run time and then i used it in the load button

since you didn't know how much textboxes will made then you can store value of textboxes on list.

Private Sub load_Click()
   Dim i as Integer
   List1.Clear
   for i = 0 to ctr - 1
       List11.AddItem (txt(i).Text)
   next i
End Sub

after it you can access value of textbox from list
value of index 0 in list is your value of textbox with index 0

for ctr = 0 to ctr -1 'ADD the minus 1 here.
            a = txt(j).text '--this will give me an error
      next ctr

Your error was raised because you were calling to a textbox that did not exist at the end. You need to add the -1 to start the index at 0 (zero).

hi guys sorry for the late response i was not able to reply on that time cause i was sick..to the topic i still didn't get it i got an error wrong arguments on txt it was highlighted.

post your last code and what the error tell to you?

for ctr = 0 to ctr -1            
 a = txt(j).text   'the "txt" is highlighted here and the error says wrong number of arguments    
  next ctr

ctr is a user input.. txt(j).Text , what is j ?? j is not using in your looping. so it will give u an error.
if you want to use j then your code should be like this :

Dim j as Integer
For j = 0 To ctr - 1
    a = txt(j).Text   
Next j

but if you want to use ctr in your looping then your code should be like this :

For ctr = 0 To ctr - 1
    a = txt(ctr).Text  ' j changed with ctr
Next ctr

@Jx, have a look at page 1 to see where "j" originates from. You are confusing the OP, he already has "j" in his code, now you want him to change it?, unless of course he never dimensioned "j" as per your code.;)

j on first page is for adding text boxes during run time. and on the second page, he tried to get value from textboxes while the textboxes adding on the form.
If we try to get textbox value while textbox created then we never get user input.
On page two he said to get user input and when he press a button then he will get textbox value.
If he put the code on the button event then where is j come from? ;)

Yeah, you're right. It seems it was my turn to have blonde moment, sorry.:)

sorry for the confusions..i was sick that time..^_^..
well my problem was, is how to get that value of the texbox after the user inputed a value. back to my other post that was how to load or to make a textbox during run time now that the textbox has been loaded the next problem is how can i get that value that the user inputted on that textbox.

What text will be added, give us some samples or some code, it will be better than to guess what exactly will be entered. :)

the user will input numeric numbers. i still got error on the code you give.

for ctr = 0 to ctr- 1 'ctr here has already a value as you can see on my post i made a ctr for counter to determined how many textboxes will be made depends on the how many they want.my ctr variable was place on the code where the textbox have been during runtime.

anyone can help me with this? im still stuck

are you read my posts and any codes that i provides?

yup i followed the code you posted but it still give me an error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.