adding stuff to a combobox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dfg

    adding stuff to a combobox

    Hi everyone. I am having a problem reading the contents of a file into
    a ComboBox. I end up with only the last item being read into the list.
    Can someone show me what is wrong?

    Thanks.

    test.txt contents:
    "1994 Ford F150 Pickup"
    "1987 GMC 2500"
    "1986 Hyundai Pony"
    "1996 Honda Civic"
    "1990 Pontiac Sunfire"

    My Code is as follows:

    Private Sub Form_Load()
    Dim intRetVal As Integer
    Dim strEntries As String

    On Error GoTo FileError
    Open "a:\test.tx t" For Input As #1

    Do Until EOF(1)
    Input #1, strEntries
    cboVehicle.Text = strEntries 'How can i add to the box?
    Loop

    Exit Sub

    FileError:
    If Err.Number = 71 Then
    intRetVal = MsgBox("Disk Not Ready", vbExclamation + vbOKCancel, _
    "File Access Error")
    If intRetVal = vbCancel Then
    Unload Me
    Else
    Resume
    End If
    Else
    Err.Raise Err.Number
    End If

    End Sub

  • Randy Birch

    #2
    Re: adding stuff to a combobox

    hfile = freefile
    open xxxx etc as #hfile

    do while not eof(hfile)

    input #hfile, buff
    combo1.additem buff

    loop

    --

    Randy Birch
    MVP Visual Basic

    Please respond only to the newsgroups so all can benefit.


    "dfg" <dfg@dfg.net> wrote in message
    news:knfsb.3715 83$6C4.176195@p d7tw1no...
    : Hi everyone. I am having a problem reading the contents of a file into
    : a ComboBox. I end up with only the last item being read into the list.
    : Can someone show me what is wrong?
    :
    : Thanks.
    :
    : test.txt contents:
    : "1994 Ford F150 Pickup"
    : "1987 GMC 2500"
    : "1986 Hyundai Pony"
    : "1996 Honda Civic"
    : "1990 Pontiac Sunfire"
    :
    : My Code is as follows:
    :
    : Private Sub Form_Load()
    : Dim intRetVal As Integer
    : Dim strEntries As String
    :
    : On Error GoTo FileError
    : Open "a:\test.tx t" For Input As #1
    :
    : Do Until EOF(1)
    : Input #1, strEntries
    : cboVehicle.Text = strEntries 'How can i add to the box?
    : Loop
    :
    : Exit Sub
    :
    : FileError:
    : If Err.Number = 71 Then
    : intRetVal = MsgBox("Disk Not Ready", vbExclamation + vbOKCancel,
    _
    : "File Access Error")
    : If intRetVal = vbCancel Then
    : Unload Me
    : Else
    : Resume
    : End If
    : Else
    : Err.Raise Err.Number
    : End If
    :
    : End Sub
    :


    Comment

    Working...