Results 1 to 10 of 10

Thread: get more than 1 textbox in loop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Resolved get more than 1 textbox in loop

    i want to try something like this


    for i = 1 to 10
    mes="tekst" + i
    msgbox mes.text
    next i


    but thoes not work

    what is the wright code
    Last edited by davyquyo; Oct 26th, 2004 at 08:21 AM.

  2. #2
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Do you want to add i (so a number between 1 and 10) to lots of textboxs at once, or are you trying to do something else?
    Don't Rate my posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    yes i'm trying to get a lot of textboxes at once

  4. #4
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    VB Code:
    1. Dim i as integer
    2. Dim Ctrl As Control
    3. For i = 1 to 10    
    4.     For Each Ctrl In Controls
    5.         If TypeName(Ctrl) = "Textbox" Then
    6.             Ctrl.Text = Ctrl.Text & i
    7.         End If
    8.     Next Ctrl
    9. Next i

    Will go through every textbox on a form and append i to it, so you'll end up with,

    TextBox112345678910

    in all of them. (hopefully, should work properly )
    Don't Rate my posts.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    can't i just have an endruslt like this

    textbox1
    textbox2
    textbox3 ....

  6. #6
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    You sure can.

    VB Code:
    1. Dim i As Integer
    2.     Dim Ctrl As Control
    3.     i = 1
    4.     For Each Ctrl In Controls
    5.  
    6.         If TypeName(Ctrl) = "Textbox" Then
    7.             Ctrl.Text = "textbox" & i
    8.             i = i + 1
    9.         End If
    10.     Next Ctrl
    Don't Rate my posts.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    i can't let it work

    i try't this

    Function dagenotitie()
    Dim i As Integer
    Dim result As Control
    For i = 1 To 31
    result = "nummer" & i
    result.Caption = i
    Next i
    End Function

    wan't work either

    result = nothing

  8. #8
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    VB Code:
    1. Dim i As Integer
    2. Dim result As Control
    3. For Each result In Controls
    4.    For i = 1 To 31
    5.      result = "nummer" & i
    6.      result.Caption = i
    7.    Next i
    8. Next result

    Your missing a For Loop that goes through all of the controls. Result will = nothing because you haven't assigned anything to it. It gets assigned a control here,
    For Each result In Controls
    Don't Rate my posts.

  9. #9
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    alternative

    VB Code:
    1. For i = 1 To 10
    2.     MsgBox Me.Controls("tekst" + i).Text
    3. Next i

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Re: alternative

    Originally posted by Deepak Sakpal
    VB Code:
    1. For i = 1 To 10
    2.     MsgBox Me.Controls("tekst" + i).Text
    3. Next i
    this was wrong

    Originally posted by Deepak Sakpal
    VB Code:
    1. For i = 1 To 10
    2.     MsgBox Me.Controls("tekst" & i).Text
    3. Next i
    this works perfect

    thanks

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