Results 1 to 10 of 10

Thread: [RESOLVED] Textbox(a).text is it possible?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Resolved [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.

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    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
    thanks
    amrita

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    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.

  4. #4
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Textbox(a).text is it possible?

    Use something like the following

    vb Code:
    1. CType(Me.Controls.Find("TextBox" & CStr(1), True)(0), TextBox).Text = " 1"
    2.         CType(Me.Controls.Find("TextBox" & CStr(2), True)(0), TextBox).Text = " 2"
    3.         CType(Me.Controls.Find("TextBox" & CStr(3), True)(0), TextBox).Text = " 3"
    thanks
    amrita

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    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

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    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.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    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

  8. #8
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Textbox(a).text is it possible?

    Assuming all the TextBoxes are contained within the Form you could just do this:

    vb.net Code:
    1. For Each c As Control In Me.Controls
    2.     If TypeOf c Is TextBox Then
    3.         c.Text = InputBox("Input anything")
    4.     End If
    5. Next

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    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..

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Textbox(a).text is it possible?

    Quote Originally Posted by amrita View Post
    Use something like the following

    vb Code:
    1. CType(Me.Controls.Find("TextBox" & CStr(1), True)(0), TextBox).Text = " 1"
    2.         CType(Me.Controls.Find("TextBox" & CStr(2), True)(0), TextBox).Text = " 2"
    3.         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
  •  



Click Here to Expand Forum to Full Width