Welcome to Dream.In.Code
Become a VB Expert!

Join 149,482 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,410 people online right now. Registration is fast and FREE... Join Now!




save data to file direct using mscomm1

 
Reply to this topicStart new topic

save data to file direct using mscomm1

renault_sauber
2 May, 2007 - 03:31 AM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2007
Posts: 4


My Contributions
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.
CODE

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
User is offlineProfile CardPM
+Quote Post

tody4me
RE: Save Data To File Direct Using Mscomm1
2 May, 2007 - 05:20 AM
Post #2

Only Jenny Craig makes thin clients...
Group Icon

Joined: 12 Apr, 2006
Posts: 1,349



Thanked: 5 times
Dream Kudos: 100
My Contributions
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:
CODE

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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:32PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month