Dobrý den, potřeboval bych načíst *.txt se strukturou:
slovo1
slovo2
slovo3
...
do ComboBoxu, prosím o radu jak na to,
Děkuji
#1 Martin
'---------------------------------------------------------------------------------------
' Module : Txt2Ctrl
' Author : pee-jay_cz
' Date : 5.6.2015
' Purpose : How to Load Text from a File into a Control in VB6/VBA.
'---------------------------------------------------------------------------------------
Option Explicit
Private Sub cmd1_Click()
TextToControl "C:\Test.txt", pic1 ' "pic1.AutoRedraw = True" lze nastavit bud v IDE nebo 'on the run.'
TextToControl "C:\Test.txt", lbl1
TextToControl "C:\Test.txt", txt1 ' "txt1.MultiLine = True" musi byt nastaveno v IDE, nelze zmenit 'on the run'.
TextToControl "C:\Test.txt", cbo1
TextToControl "C:\Test.txt", lst1
End Sub
Public Sub TextToControl(ByRef FileName As String, ByRef obj As Object)
'----------------------------------------------------
' NACET ZE SOUBORU
If Len(Dir$(FileName)) = 0 Then
MsgBox "Chyba souboru." & vbNewLine & _
"Soubor " & Chr$(34) & FileName & Chr$(34) & " nelze nalézt.", _
vbInformation
Exit Sub
End If
Dim fNum As Long
fNum = FreeFile
Open FileName For Binary As #fNum
If LOF(fNum) = 0 Then
MsgBox "Chyba souboru." & vbNewLine & _
"Soubor " & Chr$(34) & FileName & Chr$(34) & " je prázdný.", _
vbInformation
'Exit Sub
End If
Dim Buffer As String
Buffer = Space$(LOF(fNum))
Get #fNum, 1, Buffer
Close #fNum
' KONEC NACTU SOUBORU
'----------------------------------------------------
Dim i As Long
Select Case TypeName(obj)
Case "PictureBox"
obj.Cls
obj.Print Buffer
Case "Label"
obj.Caption = Buffer
Case "TextBox"
obj.Text = Buffer
Case "ComboBox", "ListBox"
Dim Lines() As String
Lines = Split(Buffer, vbNewLine)
obj.Clear
For i = LBound(Lines) To UBound(Lines)
obj.AddItem Lines(i)
Next i
If TypeName(obj) = "ComboBox" Then obj.ListIndex = 0 Else obj.ListIndex = -1
Erase Lines
Case Else
MsgBox "Chyba objektu." & vbNewLine & _
"Objekt " & Chr$(34) & obj.Name & Chr$(34) & " není podporovaný (" & TypeName(obj) & ").", _
vbInformation
End Select
Buffer = vbNullString
End Sub
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku