|
-
Apr 25th, 2002, 09:27 AM
#1
Thread Starter
Lively Member
byval statement
Can anyone tell me what is wrong with this sentence as I get an error and i can't figure it out:
private Function GetFileContents byval "c:\Q1.txt" as String as String
thanks.
-
Apr 25th, 2002, 09:32 AM
#2
VB Code:
s ="c:\Q1.txt"
Private Function GetFileContents(ByVal s As String) As String
End Function
it expects a variable, if you have a constant expression like "c:\Q1.txt" why don't u declare it in your function?
-
Apr 25th, 2002, 09:44 AM
#3
Thread Starter
Lively Member
Got another error somewhere now, but can't figure out (i'm still a beginner at vb6, unlike you experts!)
Here's the code - any suggestions?
Sub form_load()
s = "h:\proj\Q1.txt"
Private Function GetFileContents(ByVal s As String) As String
' if file does not exist, ignore the error and return an empty string
Dim iFile As Integer
On Error Resume Next
iFile = FreeFile
GetFileContents = Space
FileLen "h:\proj\Q1.txt"
Open "h:\proj\Q1.txt" For Binary As #iFile
Get #iFile, , GetFileContents
Close #iFile
' function call
Label1.Caption = GetFileContents
End Function
End Function
Thanks.
-
Apr 25th, 2002, 09:49 AM
#4
Bouncy Member
VB Code:
Sub form_load()
[b]Dim strContents As String[/b]
s = "h:\proj\Q1.txt"
[b]strContents = GetFileContents(s)
End Sub[/b]
Private Function GetFileContents(ByVal s As String) As String
' if file does not exist, ignore the error and return an empty string
Dim iFile As Integer
On Error Resume Next
iFile = FreeFile
GetFileContents = Space
FileLen "h:\proj\Q1.txt"
Open "h:\proj\Q1.txt" For Binary As #iFile
Get #iFile, , GetFileContents
Close #iFile
' function call
Label1.Caption = GetFileContents
End Function
-
Apr 25th, 2002, 09:53 AM
#5
Dont put any function into a sub or function,
handle one at a time.
We are all learning.
VB Code:
Sub form_load()
Dim s As String
s = "h:\proj\Q1.txt"
' function call
Label1.Caption = GetFileContents(s)
End Sub
Private Function GetFileContents(ByVal s As String) As String
' if file does not exist, ignore the error and return an empty string
Dim iFile As Integer
'On Error Resume Next
' not so good if an error occures , you are not sure the file will be closed.
On Error goto FuncErr
iFile = FreeFile
GetFileContents = Space
FileLen "h:\proj\Q1.txt"
Open "h:\proj\Q1.txt" For Binary As #iFile
Get #iFile, , GetFileContents
FuncEXit:
Close #iFile
Exit Function
FuncErr:
Resume FuncEXit
End Function
-
Apr 25th, 2002, 09:55 AM
#6
Bit too late.
Still some differences
-
Apr 25th, 2002, 09:56 AM
#7
Bouncy Member
Originally posted by Swatty
Bit too late.
Still some differences
-
Apr 25th, 2002, 10:03 AM
#8
Thread Starter
Lively Member
Does this code apply the same thing, it works, but if i want two separate .txt files to be read into two separate label boxes would I have to repeat the code but change the q2.txt and label2 or can i embed to existing code?
'Sub form_load()
'Dim filenum As Integer
'Dim filecontent As String
'filenum = FreeFile
'Open "h:\proj\Q1.txt" For Input As #1
'Input #1, filecontent
'Close #1
'Label1.Caption = filecontent
'End Sub
' code when the quit command button (cmd_quit) is selected
Sub cmd_quit_click()
End
End Sub
Thanks for your time and help again.
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
|