Hie
how do you call a text file in vb using textbox and command button
how do you call a text file in vb using textbox and command button
Private Function Open_File()
Dim STRTEMP As String
TextBox.Text = ""
On Error GoTo Cancel_Function
With CommonDialog
.CancelError = True
.Filter = "Text (.txt)|*.txt"
.InitDir = Environ$("USERPROFILE") & "\My Documents"
.DialogTitle = "Open a file..."
.ShowOpen
On Error GoTo Error_Open_File
Open .FileName For Input As #1
Do Until EOF(1)
Input #1, STRTEMP
TextBox.Text = TextBox.Text & STRTEMP
Loop
Close #1
Caption = Left(Caption, 26) & ": " & .FileName
End With
Exit Function
Error_Open_File:
Close #1
MsgBox "There is an error opening the file"
Exit Function
Cancel_Function:
End Function
Private Sub Form_Load()
Dim FileIn As Integer
FileIn = FreeFile
On Error GoTo Error_Laden
Open App.Path & "\document.txt" For Input As #FileIn
Do While Not EOF(FileIn)
Input #FileIn, inputdata
TEXTBOX.text = TEXTBOX.text & inputdata & vbCrLf
Loop
Close #FileIn
Exit Sub
Error_Laden:
Close #FileIn
MsgBox ("Error loading !")
End Sub
Comment