VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Read / Write Combo Boxs

by T-Unit (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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")

Rate Read / Write Combo Boxs

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

Download this snippet    Add to My Saved Code

Read / Write Combo Boxs Comments

No comments have been posted about Read / Write Combo Boxs. Why not be the first to post a comment about Read / Write Combo Boxs.

Post your comment

Subject:
Message:
0/1000 characters