|
-
Jan 4th, 2001, 10:06 PM
#1
I'm using the following code for a file transfer:
Code:
Private Sub WinS_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
If WinS.Tag = "OK" Then
Open App.Path & "\File.exe" For Binary As #1
End If
MsgBox "Recieved"
WinS.Tag = ""
Dim StrData() As Byte
WinS.GetData StrData, vbString
Debug.Print StrData
Put #1, , StrData
End Sub
WinS.Tag = "OK" when the transfer button is pushed.
Here's the question. How can I close #1 when the whole file is completed. Help me please!
-
Jan 4th, 2001, 10:55 PM
#2
i am new to this but would this work at the end
Put #1, , StrData
Close #1
-
Jan 4th, 2001, 10:56 PM
#3
PowerPoster
conquerdude, your server (Transmit the file) should must inform the client (Receive the file) that the entire file is completed sent & the client will now save to close the file.
To do this, you need to involve some own protocol between the server and client communication and it may need a big modification in your existing coding. But that the way to do a file transfer with WinSock. Else you can look for the FileCopy function that come with Visual Basic.
Hope this little word can help you.
Cheers!
-
Jan 4th, 2001, 10:59 PM
#4
well as u can tell from the above reply i was way off

hey i said i was new

but i tried
-
Jan 4th, 2001, 11:19 PM
#5
So would i do this?
If I open #1 in one sub could I close it in another?
Example:
Code:
'This is just an example, not what I'm using
Private Sub Command1_Click()
Open "C:\Test.tst" For Input As #1
End Sub
Private Sub Command2_Click()
Close #1
End Sub
Would this work?
-
Jan 4th, 2001, 11:26 PM
#6
PowerPoster
Yes you can, but you need to declare like this way.
Code:
Option Explicit
Private TxFile As Long
Private Sub Command1_Click()
TxFile = FreeFile
Open "C:\Test.tst" For Binary Access Write As #TxFile
End Sub
Private Sub Command2_Click()
Close #TxFile
End Sub
[Edited by Chris on 01-04-2001 at 11:31 PM]
-
Jan 4th, 2001, 11:29 PM
#7
Do I really need the option explict?
-
Jan 4th, 2001, 11:33 PM
#8
PowerPoster
No, but with the Option Explicit the VB will check all the variable it is properly declared. Else it will propmt you about those undeclare variable and stop proceed to compile or run your coding.
I personal always include the Option Explicit in all my code.
Cheers!
-
Jan 4th, 2001, 11:38 PM
#9
How would I be able to open a file in one form and close it in another?
-
Jan 5th, 2001, 12:18 AM
#10
PowerPoster
All you need is add a Basic Module file as below will do.
Code:
Option Explicit
Private TxFile As Long
Public Sub OpenFile(ByVal lpSource As String)
TxFile = FreeFile
Open lpSource For Binary As #TxFile
End Sub
Public Sub CloseFile()
Close #TxFile
End Sub
Public Sub WriteFile(ByVal lpData As String)
Put #TxFile, , lpData
End Sub
Public Function ReadFile() As String
Dim str As String
str = String(LOF(TxFile), Chr(0))
Get #TxFile, 1, str
ReadFile = str
End Function
Then you can call the following function at anywhere anytime in your form:-
[*]OpenFile[*]CloseFile[*]ReadFile[*]WriteFile
Cheers!
-
Jan 5th, 2001, 12:22 AM
#11
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
|