Results 1 to 3 of 3

Thread: Why ISnt this Working???[RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111

    Why ISnt this Working???[RESOLVED]

    Heres the COde

    VB Code:
    1. Private Sub cmdSaveInfo_Click()
    2.  Dim strInfo() As String ' My Array for Data
    3.  Dim strData As String ' Variable that Holds Data
    4.  Dim i As Integer
    5.  Dim x As Integer
    6.  
    7.   strData = "Zero One Two Three FOur Five Six Seven Eight Nine"
    8.    strInfo = Split(strData, " ")
    9.    For i = 0 To txtInfo.UBound
    10.      For x = 1 To UBound(strInfo)
    11.        txtInfo(i).Text = strInfo(x)
    12.      Next x
    13.    Next i
    14.  
    15. End Sub

    Note its only adding the Word "Nine" to all fo the textboxes instead of splitting each word and adding each word....

    vbMarkO

    EDIT#################################

    I figured it out this gets it done

    VB Code:
    1. Private Sub cmdSaveInfo_Click()
    2.  Dim strInfo() As String ' My Array for Data
    3.  Dim strData As String ' Variable that Holds Data
    4.  Dim i As Integer
    5.  
    6.  
    7.   For i = 0 To txtInfo.UBound
    8.      strData = strData & txtInfo(i).Text & " "
    9.    Next i
    10.    For i = 0 To txtInfo.UBound
    11.     txtInfo(i) = ""
    12.    Next i
    13.    strInfo = Split(strData, Space(1))
    14.    
    15.    For i = 0 To txtInfo.UBound
    16.      txtInfo(i).Text = strInfo(i)
    17.      
    18.    Next i
    19.  
    20. End Sub
    Last edited by vbMarkO; Mar 22nd, 2004 at 11:12 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    The reason is - you have 2 loops instead of only one.
    Try the following and let me know (btw - I only created 1 textbox in design with index = 0 and rest of them are created at runtime depending on size of you array):
    VB Code:
    1. Private Sub cmdSaveInfo_Click()
    2. '===============================
    3. Dim strInfo() As String ' My Array for Data
    4. Dim strData As String ' Variable that Holds Data
    5. Dim i As Integer
    6.  
    7.     strData = "Zero One Two Three FOur Five Six Seven Eight Nine"
    8.     strInfo = Split(strData, Space(1))
    9.     For i = 0 To UBound(strInfo)
    10.         If i > 0 Then
    11.             Load txtInfo(i)
    12.             txtInfo(i).Move txtInfo(i - 1).Left, txtInfo(i - 1).Top + txtInfo(i - 1).Height
    13.             txtInfo(i).Visible = True
    14.         End If
    15.         txtInfo(i).Text = strInfo(i)
    16.     Next i
    17.  
    18. End Sub

  3. #3
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Also remember, Arrays start at (0) not (1).

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