|
-
Aug 13th, 2000, 05:20 AM
#1
Thread Starter
Addicted Member
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
-
Aug 13th, 2000, 06:24 AM
#2
Fanatic Member
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
And number of characters:
Code:
Private Sub Command2_Click()
MsgBox("Length in characters: " & Len(Text1.Text), 64, "Info")
End Sub
Hop this is what you wanted,
Me
-
Aug 13th, 2000, 06:40 AM
#3
Thread Starter
Addicted Member
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
-
Aug 13th, 2000, 08:24 AM
#4
Code to open file:
Code:
Open "C:\Windows\Desktop\ttt.txt" For Input As #1
Text1 = Input(LOF(1), 1)
Close #1
Regarding your number of character's problem:
Code:
MsgBox ("File is " & Len(Text1) & " chars long")
-
Aug 13th, 2000, 08:39 AM
#5
Hyperactive Member
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
The code
Code:
Len(Text1.Text), 64, "Info"
is for use only in a MsgBox - if you are only going to
caption it, use
Code:
C2.Caption = Str(Len(Text1.Text))
you don't need the .Text, either. It is the default property
of a text control.
-
Aug 13th, 2000, 12:35 PM
#6
Fanatic Member
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.
-
Aug 14th, 2000, 12:40 AM
#7
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|