[RESOLVED] Textbox(a).text is it possible?
i have a sample code
that is a wrong code but ill just put it so that you will understand what im trying to do.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim totjob As Integer = totjobtb.Text
Dim Input As Integer
Dim a As Integer
For start As Integer = 1 To totjob Step 1
Input = Microsoft.VisualBasic.InputBox("Input anything")
a += 1
TextBox(a).text = Input
' i set a as integer as of now it should be textbox1.text
Next
End Sub
is it possible to create a loop then the input (in the inputbox) will go to different textboxes.
for example:
"Input anything" Hey!
textbox1.text: Hey
next loop
"Input anything" Wuhuuu!
textbox2.text: Wuhuuu!
and so on..
if i am failed to explain it very well please let me know.
Re: Textbox(a).text is it possible?
use find control method
CType(Me.Controls.Find("TextBox" & CStr(a), True)(0), Windows.Forms.Controls.Textbox).Text
Re: Textbox(a).text is it possible?
Hello! Thanks for your reply. I am not familiar in that method but i will try to research it. Thanks.
Re: Textbox(a).text is it possible?
Use something like the following
vb Code:
CType(Me.Controls.Find("TextBox" & CStr(1), True)(0), TextBox).Text = " 1"
CType(Me.Controls.Find("TextBox" & CStr(2), True)(0), TextBox).Text = " 2"
CType(Me.Controls.Find("TextBox" & CStr(3), True)(0), TextBox).Text = " 3"
Re: Textbox(a).text is it possible?
You don't actually have to use CStr, you could just use a.ToString.
Re: Textbox(a).text is it possible?
Okay Okay, Haha. Thanks again to you amrita and Shaggy Hiker. Im trying. I'll post the result after 6 hours?? haha. Because this is my first time to use Find Control method.
Re: Textbox(a).text is it possible?
Actually, I don't think you need .Find, either. Every control has a COntrols collection, as does the form. You are using .Find to find a control in that collection. You should be able to just use the control name:
Me.Controls("TextBox" & a.ToString)
Should do the same thing.
Re: Textbox(a).text is it possible?
Assuming all the TextBoxes are contained within the Form you could just do this:
vb.net Code:
For Each c As Control In Me.Controls
If TypeOf c Is TextBox Then
c.Text = InputBox("Input anything")
End If
Next
Re: Textbox(a).text is it possible?
Hello ForumAccount your code is very good! Thanks! Im trying to understand Ctype here http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx i dont think that it will be easy for a beginner like me. Thanks. I will just edit your code so that it will start in textbox1.text then textbox2.text then textbox3.text and so on.. :)
Re: Textbox(a).text is it possible?
Quote:
Originally Posted by
amrita
Use something like the following
vb Code:
CType(Me.Controls.Find("TextBox" & CStr(1), True)(0), TextBox).Text = " 1"
CType(Me.Controls.Find("TextBox" & CStr(2), True)(0), TextBox).Text = " 2"
CType(Me.Controls.Find("TextBox" & CStr(3), True)(0), TextBox).Text = " 3"
Hello Amrita. Thanks! Its working now. I just change some of your code and apply mine and its now working! Thanks Thanks Thanks!
I also want to thank Shaggy Hiker and ForumAccount.