View Full Version : [Visual Basic 6] Text file won't load
Ashleys165
02-12-2012, 04:57 PM
Private Sub Command11_Click()
Dim strFile As String
strFile = SelectFileToLoad(CD)
If Len(strFile) > 1 Then
Call TextFileToList(strFile, ListofUsernames)
Else
MsgBox "Please Select a File!", vbInformation, "Error!"
End If
End Sub
I have a text file with a list of user names, and yet it won't load into my list box 'ListofUsernames'
Joshsadf
02-12-2012, 05:21 PM
I have a handy class I use for listboxes. Someone gave it to me long ago on SD.
[Only registered and activated users can see links]
Add it to the project.
Add the Microsoft Common Dialog Control Component 6.0. (Add it to the form and name it 'comDia')
Add this code to the very top of your code.
Dim clsList As New clsList
Add this code to your Form_Load
clsList.BindList yourlistbox
And for loading and saving, use these, you can change them around a little bit.
Private Sub cmdLoad_Click()
On Error GoTo ErrHand
With comDia
.DialogTitle = "Load List"
.Filter = "Text Files|*.txt"
.CancelError = True
.ShowOpen
clsList.LoadListFromFile .FileName
End With
ErrHand:
End Sub
Private Sub cmdSave_Click()
On Error GoTo ErrHand
With comDia
.DialogTitle = "Save List"
.Filter = "Text Files|*.txt"
.CancelError = True
.ShowSave
If Dir(.FileName) <> "" Then
ans = MsgBox("The file " & .FileTitle & " already exists." & vbCrLf & _
"Are you sure you want to overwrite it?", vbYesNo, "Confirm Overwrite")
If ans = vbNo Then Exit Sub
End If
clsList.SaveListToFile .FileName
End With
ErrHand:
End Sub
End Sub
Ashleys165
02-12-2012, 06:14 PM
Josh
Runtime error when the form loads.... should I make any special changes to this
clsList.BindList yourlistbox?
Like perhaps
clsList.BindList list1? :confused:
Joshsadf
02-12-2012, 07:21 PM
Yea change 'yourlistbox' to whatever you name your listbox.
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.