How to display the file(*.txt) while clicking the command button
How to display the content of the file while clicking the button
Data\'s are stored in the t
Add a textbox to a form, make it multiline=true, add a button to the form. And in the buttons click handler add this:
Private Sub Button1_Click()
Dim iFile As Long
Dim strFilename As String
Dim strTheData as String
strFilename = "C:\1.txt"
iFile = FreeFile
Open strFilename For Input As #iFile
strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
Close #iFile
text1.text=strThedata
End Sub
This will read the text in the file and add it to the textbox.
Edit: Changed the line that reading the content to be more robust as pointed out by MarkJ in this answer (Cred goes to to MarkJ to pointing out that.)
No offence intended, but it sounds like you need a beginners tutorial on VB6. (I think this because you don't seem to be able to articulate exactly what you need help with, possibly because you don't know enough about what you're trying to do).
Googling for VB6 Tutorial will give lots of links, this one looks good
Hope this helps, and apologies if I'm wrong :)
Stefan's answer contains a flaw: the code to read a text file into a string isn't very robust. It's a very common mistake - the same flawed code is on some excellent VB6 web sites. His code is
Open strFilename For Input As #iFile
strTheData = Input$(LOF(iFile), #iFile)
Close #iFile
Unfortunately this throws an error 62 "input past end of file" if the text file contains ASCII zero characters. Also it doesn't work in all countries (it throws an error for most strings in double byte character sets like Chinese or Japanese).
Perhaps those problems are a bit obscure: but there's better code to do this job in the VB6 manual (here), it's also three lines, and it never fails.
Open strFilename For Input As #iFile
strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
Close #iFile
It looks more complicated: but actually the only difference is that the conversion from ANSI to Unicode is explicit rather than implicit. It runs just as fast, and it always works.
To just open a file using the current default file handler try using the ShellExecute API function.
Here's an example.