|
-
Dec 13th, 2010, 08:52 AM
#1
Thread Starter
Addicted Member
[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.
-
Dec 13th, 2010, 09:06 AM
#2
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
-
Dec 13th, 2010, 09:07 AM
#3
Thread Starter
Addicted Member
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.
-
Dec 13th, 2010, 09:10 AM
#4
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"
-
Dec 13th, 2010, 09:28 AM
#5
Re: Textbox(a).text is it possible?
You don't actually have to use CStr, you could just use a.ToString.
My usual boring signature: Nothing
 
-
Dec 13th, 2010, 09:30 AM
#6
Thread Starter
Addicted Member
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.
-
Dec 13th, 2010, 09:38 AM
#7
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.
My usual boring signature: Nothing
 
-
Dec 13th, 2010, 09:43 AM
#8
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
-
Dec 13th, 2010, 09:56 AM
#9
Thread Starter
Addicted Member
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..
-
Dec 13th, 2010, 10:29 AM
#10
Thread Starter
Addicted Member
Re: Textbox(a).text is it possible?
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|