Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleInitialize a ComboBox using values from a TextBox
KeywordsListItem, list, ComboBox, TextBox, add
CategoriesControls
 
Use InStr to search the text for carriage returns. Copy the TextBox's lines into the ComboBox.
 
Private Sub Command1_Click()
Dim pos As Integer
Dim txt As String
Dim entry As String

    Combo1.Clear

    txt = Text1.Text
    Do While Len(txt) > 0
        pos = InStr(txt, vbCrLf)
        If pos > 0 Then
            entry = Left$(txt, pos - 1)
            txt = Mid$(txt, pos + 2)
        Else
            entry = txt
            txt = ""
        End If
        txt = Trim$(txt)
        If Len(txt) > 0 Then Combo1.AddItem entry
    Loop

    Text1.Text = ""
    Combo1.ListIndex = 0
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated