Displaying data in VB (URGENT)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Baladin
    New Member
    • Feb 2008
    • 14

    Displaying data in VB (URGENT)

    Code:
    dim Str1(0 to 5) as string
    for i = 1 to 10
        str1(i)= Me.controls("textbox" & i). text
    next
    Is there a way of reversing this? as in:

    Code:
    dim Str1(0 to 5) as string
    for i = 1 to 10
        Me.controls("textbox" & i). text = str1(i)
    next
    (This code doesnt work, apperently it is read only)

    I would also like to use : .Hide() and .Show() in the same way

    (Using VB 2008 express)
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    I asume you want to set the value of each text box to the value in the array?

    such as
    textbox1.text = str1(1)
    textbox2.text = str1(2)

    ????

    if so this works for me:
    [code=vbnet]
    Dim i As Integer
    Dim Str1(0 To 5) As String
    Str1(0) = 0
    Str1(1) = 1
    Str1(2) = 2
    Str1(3) = 3
    Str1(4) = 4
    Str1(5) = 5

    For i = 1 To 5
    Me.Controls("te xtbox" & i).Text = Str1(i)
    Next
    [/code]

    Comment

    • Baladin
      New Member
      • Feb 2008
      • 14

      #3
      hmmm... it didnt work last time, but does now?!?, maybe i spelt something wrong, ah well thanks anyway

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #4
        Originally posted by Baladin
        Code:
        dim Str1(0 to 5) as string
        for i = 1 to 10
            str1(i)= Me.controls("textbox" & i). text
        next
        Is there a way of reversing this? as in:

        Code:
        dim Str1(0 to 5) as string
        for i = 1 to 10
            Me.controls("textbox" & i). text = str1(i)
        next
        (This code doesnt work, apperently it is read only)

        I would also like to use : .Hide() and .Show() in the same way

        (Using VB 2008 express)
        Your FOR should go from 0 to 5, otherwise you'll have a runtime error, since there's no Str1(6). You're leaving an space between the dot and the Text property, which by the way IS NOT read only (i dont think that's any problem). So i'd say changing the ranges will do. Otherwise, i'd say is a VB2008 express issue.

        Kad [haven't checked the 2008 xpress yet u.u ]

        Comment

        Working...