Results 1 to 4 of 4

Thread: Multiline Text to Combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    belgium
    Posts
    74

    Question

    How can I put the text which is in a multiline textbox into a combobox.

    Each line in the textbox must be a new item in the combobox.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    ' Is this what you are after
    ' Need VB6 for this split

    Code:
    Private Sub Command1_Click()
        Dim x As Variant
        x = Text1
        x = Split(x, vbCrLf)
        For i = LBound(x) To UBound(x)
          Combo1.AddItem x(i)
        Next i
    
    End Sub
    
    Private Sub Form_Load()
        Dim i
        For i = 1 To 5
        Text1 = Text1 & i & vbCrLf
    Next i
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Joe was too fast, as usual, but I'll post my code anyway.

    Code:
    Private Sub Command1_Click()
        Dim strArray() As String
        Dim x As Integer
        
        strArray = Split(Text1.Text, vbCrLf)
        For x = 0 To UBound(strArray)
            Combo1.AddItem strArray(x)
        Next x
    End Sub

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    ' this one for VB5 -
     
    Private Sub Command1_Click()
        Dim x As Variant
        x = Text1
        x = Split2(x, vbCrLf)
        For i = LBound(x) To UBound(x)
          Combo1.AddItem x(i)
        Next i
    
    End Sub
    
    Private Sub Form_Load()
        Dim i
        For i = 1 To 5
        Text1 = Text1 & i & vbCrLf
    Next i
    
    End Sub
    
    'split function for VB5 and under   vb6 has the function
    'posted originally by Aaron Young
    
    Public Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
        Dim sParts() As String
        Dim lParts As Long
        Dim lPos As Long
        
        lPos = InStr(sString, sSeparator)
        While lPos
            ReDim Preserve sParts(lParts)
            sParts(lParts) = Left(sString, lPos - 1)
            sString = Mid(sString, lPos + Len(sSeparator))
            lPos = InStr(sString, sSeparator)
            lParts = lParts + 1
        Wend
        If Len(sString) Then
            ReDim Preserve sParts(lParts)
            sParts(lParts) = sString
        End If
        Split2 = IIf(lParts, sParts, Array())
    End Function
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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