Search Tools Links Login

Read / Write Combo Boxs


Visual Basic 6, or VB Classic

This code will let you read in values from a file of your choice, probably a .ini or .txt into a combobox. It will also let you save the contents of the combobox to a file of your choice.
Example:
Call WriteCombo(combo1, "C:/example.ini")
or
Call ReadCombo(combo1, "C:/example.ini")

Original Author: T-Unit

Code

Public Sub ReadCombo(combobox As combobox, Filename As String)
  On Error GoTo Err
  Open Filename For Input As #1


  Do While Not EOF(1)
    Input #1, lstinput
    combobox.AddItem lstinput
  Loop
  Close #1
  Exit Sub
Err:
  MsgBox "Error In ReadCombo" & Chr(13) & Chr(13) & Err.Number _
  & " - " & Err.Description, vbCritical, "Error"
  Exit Sub
End Sub

Public Sub WriteCombo(combobox As combobox, Filename As String)

  If combobox.ListCount <= 0 Then
    MsgBox "Combobox is empty - cannot write To file!", vbCritical, "Error"
    End
  End If
  On Error GoTo Err
  Open Filename For Output As #1
  For i = 0 To combobox.ListCount - 1
    Print #1, combobox.List(i)
  Next
  Close #1
  Exit Sub
Err:
  MsgBox "Error In WriteCombo" & Chr(13) & Chr(13) & Err.Number _
  & " - " & Err.Description, vbCritical, "Error"
  Exit Sub
End Sub

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 111 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.