QUOTE(oXiDe @ 18 Nov, 2007 - 10:34 AM)

hi im making a project that needs to load text from .txt files into combo boxes. Here was my failed try.
CODE
Private Sub LoadSC_CDKeys()
Dim SCCDKey As String
Open App.Path & "\CD Keys\StarCraft.txt" For Input As #12
Do Until EOF(12)
Line Input #12, SCCDKey
End Sub
and also if someone could post the code that would refresh a form by clicking on a cmd button, i would be forever thankful :l
I just noticed this editor removes indentation. Oops. Need a new editor
CODE
Option Explicit
Private Sub Command1_Click()
'I'm passing the combo box so its name
'doesn't need to be hard coded in the LoadSC_CDKeys sub
Call LoadSC_CDKeys(Combo1)
End Sub
Private Sub LoadSC_CDKeys(TheCombo As ComboBox)
Dim iFile As Integer
Dim sCDKeys() As String
Dim iItem As Integer
'Instead of hardcoding a file number (12 in your case)
'use Freefile to ask VB which numbers are available
iFile = FreeFile
'Notice I've changed your path, so I can test the code
Open "C:\Temp\StarCraft.txt" For Input As iFile
'Read the entire file and break it all up into
'an array in one line of code
sCDKeys = Split(Input$(LOF(iFile), iFile), vbCrLf)
'Close the file
Close iFile
'Now, fill the combo and get outta here
With TheCombo
.Clear 'get rid of anything currently loaded
'Loop thru the array, adding as we go
For iItem = 0 To UBound(sCDKeys)
If Len(sCDKeys(iItem)) > 0 Then 'no blanks allowed
.AddItem sCDKeys(iItem)
End If
Next
'Now, select the first item in the combo
If .ListCount > 0 Then
.ListIndex = 0
End If
End With
End Sub
Ken Halter - MS-MVP-VB
Please always use code tags when posting your code =>
This post has been edited by PsychoCoder: 18 Nov, 2007 - 10:13 AM