1 Replies - 1529 Views - Last Post: 02 May 2007 - 06:20 AM Rate Topic: -----

#1 renault_sauber  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-February 07

save data to file direct using mscomm1

Posted 02 May 2007 - 04:31 AM

Hi guys,

i wrote a program here to collect data and save the data to file where i can open the file later.

here the program i've wrote.
Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub

Private Sub Timer1_Timer()
Dim InputString
If MSComm1.InBufferCount = 256 Then
Close #1
Open "c:\test.cli" For Output As #1
InputString = MSComm1.Input
For x = 1 To 256
A$ = Mid$(InputString, x, 1)
Print #1, Asc(A$)
Next x
End If
Close #1

End Sub


It require only time and mscomm to the form.
The result expected should store the data collect from port 1 and save it in file "test.cli" in c directory. No error occured during run. The only problem is that there is no file "test.cli" on c directory. please help. Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: save data to file direct using mscomm1

#2 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: save data to file direct using mscomm1

Posted 02 May 2007 - 06:20 AM

your code was hard to read because you are only declaring 1 variable but using 3. The first problem should be where you are attempting to close a file that is not open. To test for how many files are open, use the FreeFile function built into VB to see if there is a file open. If so, then close all files that you have open. Such as this:
If FreeFile <> 1 then
do
  close #1
loop until freefile = 1
endif



then continue your code from the first close #1 statement. What may be happening here is the close statement waits for something to open #1, therefore when the open statement processes it's closed as soon as it opens, therefore nothing is created. The other issue that i see is that you are writing a string as asc(A$), which is just writing the character number.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1