How do I load a normal text file into a TextBox, like a readme file for instance?
And how would I go about counting the number of characters?
Thanks.
-Git
Printable View
How do I load a normal text file into a TextBox, like a readme file for instance?
And how would I go about counting the number of characters?
Thanks.
-Git
And number of characters:Code:'Module
'Not my code (It's not good enough hehe ;) )
Function ReadTextFileContents(filename As String) As String
Dim fnum As Integer, isOpen As Boolean
On Error GoTo Error_Handler
' get the next free file number
fnum = FreeFile()
Open filename For Input As #fnum
' if execution flow got here, the file has been open without error
isOpen = True
' read the entire contents in one single operation
ReadTextFileContents = Input(LOF(fnum), fnum)
' intentionally flow into the error handler to close the file
Error_Handler:
' raise the error (if any), but first close the file
If isOpen Then Close #fnum
If Err Then Err.Raise Err.number, , Err.Description
End Function
'Form
Private Sub Command1_Click()
Text1.Text = ReadTextFileContents("C:/readme.txt")
End Sub
Hop this is what you wanted,Code:Private Sub Command2_Click()
MsgBox("Length in characters: " & Len(Text1.Text), 64, "Info")
End Sub
Me
Thanks. =)
There's an error though :
C2.Caption = Len(Text1.Text), 64, "Info"
All it says is 'Expected: End Of Statement' on the first comma.
Any idea what's wrong?
-Git
Code to open file:
Regarding your number of character's problem:Code:Open "C:\Windows\Desktop\ttt.txt" For Input As #1
Text1 = Input(LOF(1), 1)
Close #1
Code:MsgBox ("File is " & Len(Text1) & " chars long")
The codeQuote:
Originally posted by git
Thanks. =)
There's an error though :
C2.Caption = Len(Text1.Text), 64, "Info"
All it says is 'Expected: End Of Statement' on the first comma.
Any idea what's wrong?
-Git
is for use only in a MsgBox - if you are only going toCode:Len(Text1.Text), 64, "Info"
caption it, use
you don't need the .Text, either. It is the default propertyCode:C2.Caption = Str(Len(Text1.Text))
of a text control.
Yeah, 64 is just a quick way to set the parameters for the MsgBox and "Info" is the MsgBox's title. Sorry if that mislead you.
Ok, thanks all! =)
-Git