|
-
Mar 14th, 2006, 01:07 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Calling a function and it's arguments
How would i go about calling this function
VB Code:
Private Function SaveFileFromTB(TxtBox As Object, _
FilePath As String, Optional Append As Boolean = False) _
As Boolean
Jenova
-
Mar 14th, 2006, 01:10 PM
#2
Fanatic Member
Re: Calling a function and it's arguments
If SaveFileFromTB(Text1,"c:\mypath") = True Then
' do something
Else
' do something else
End If
-
Mar 14th, 2006, 01:10 PM
#3
Hyperactive Member
Re: Calling a function and it's arguments
Dim ReturnValue as boolean
ReturnValue = SaveFileFromTB(textbox, "c:\Path")
-
Mar 14th, 2006, 01:11 PM
#4
Re: Calling a function and it's arguments
VB Code:
If SaveFileFromTB(Text1, MyPathString) Then
' do something
End if
' or
If SaveFileFromTB(Text1, MyPathString, True) Then
' do something
End if
-
Mar 14th, 2006, 01:15 PM
#5
Thread Starter
Hyperactive Member
Re: Calling a function and it's arguments
Sorry, should have explianed better. This is the function:
VB Code:
Private Function OpenFileToTB(TxtBox As Object, _
FilePath As String, Optional Append As Boolean = False) _
As Boolean
Dim iFile As Integer
Dim s As String
If Dir(FilePath) = "" Then Exit Function
On Error GoTo ErrorHandler:
s = TxtBox.Text
iFile = FreeFile
Open FilePath For Input As #iFile
s = Input(LOF(iFile), #iFile)
If Append Then
TxtBox.Text = TxtBox.Text & s
Else
TxtBox.Text = s
End If
LoadFileToTB = True
ErrorHandler:
If iFile > 0 Then Close #iFile
End Function
I need to call it from the form's load event. Or does anyone have an easier way to open a htm/txt file to a text box.
Last edited by Jenova; Mar 14th, 2006 at 01:18 PM.
-
Mar 14th, 2006, 01:18 PM
#6
Re: Calling a function and it's arguments
It is useless to call that function from the form's load event since it uses the contents of a textbox and that textbox can't at that point have anything in it.
-
Mar 14th, 2006, 01:49 PM
#7
Thread Starter
Hyperactive Member
Re: Calling a function and it's arguments
I am tring to open a htm file so it's practically source when viewed in my program. I am using this code to do it
VB Code:
Private Sub Form_Load()
On Error Resume Next
Dim handle As Integer
Dim file As String
handle = FreeFile
Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As handle
Do While Not EOF(handle)
Text1.TextRTF = file
Loop
Close #handle
End Sub
Slight drawback, it crashes when i run the program. Any ideas on how i can make this work
-
Mar 14th, 2006, 02:23 PM
#8
Re: Calling a function and it's arguments
Slight drawback, it crashes when i run the program.
It doesn't "crash", you have an infinite loop. EOF(handle) will never be true because you are not moving through the file.
You need to retrieve the file contents using Input or Line Input statements.
-
Mar 14th, 2006, 02:36 PM
#9
Re: Calling a function and it's arguments
The first thing you should do is to remove the On Error Resume Next line.
-
Mar 14th, 2006, 02:56 PM
#10
Thread Starter
Hyperactive Member
Re: Calling a function and it's arguments
Apologies.
On error resume next was to see if the that would solve it but i't didn't. Thanks for the advice on an infinite loop but if i use Line Input or Input then it will give me the last line of the HTML file which is </html>.
Jenova
-
Mar 14th, 2006, 03:00 PM
#11
Re: Calling a function and it's arguments
That's because in the code you posted you aren't appending the data so you just see the last line.
-
Mar 14th, 2006, 03:08 PM
#12
Thread Starter
Hyperactive Member
Re: Calling a function and it's arguments
lol sorted.
VB Code:
Private Sub Form_Load()
Dim handle As Integer
Dim file As String
handle = FreeFile
Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As handle
Do While Not EOF(handle)
file = Input(LOF(handle), #handle)
Text1.TextRTF = file
Loop
Close #handle
End Sub
Thanks guys
-
Mar 14th, 2006, 03:17 PM
#13
Re: Calling a function and it's arguments
You can now help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.
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
|