-
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!
-
i am new to this but would this work at the end
Put #1, , StrData
Close #1
-
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!
-
well as u can tell from the above reply i was way off
:)
hey i said i was new
:)
but i tried
-
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?
-
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]
-
Do I really need the option explict?
-
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!
-
How would I be able to open a file in one form and close it in another?
-
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!
-