Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Diem Tran   on Jan 02 In MS Office Category.

  
Question Answered By: Luis Fischer   on Jan 02

I have no working knowledge of the MSComm methods of serial I/O. I
have seen references to it and may try it using your example  as a
start, but I digress.
I don't read here too often now that I have things under control, so
Send my Yahoo account (noskosteve) an email and I'll be glad to send
my spreadsheet, but be forewarned it is complex and the serial I/O
Comm Module is complex as well. I do, however, comment the begeebers
out of my code. anyway...

On to your problem - You must look in the code  to see what is
highlighted. To see it, click on the DEBUG choice when the error
dialog comes up. Whatever gave VBA heartburn will be highlited.
Sometimes the location of the root cause is far ahead of this
location, but it may be the only clue you get in this game.

I don't understand the need to combine bytes. I would only be able
to speculate that 'MSComm1.CommEvent' goes True when a serial byte
is received (by the OS) and stuffed into the VBA serial buffer. If
your code loops fast enough, you catch each individual byte
in 'sData'. But you say it works for a while I have also noticed
that VBS tends to "soft-fail" at times, thus masking your coding
problem. Again, only guessing, but it can be something like this:
Let's say sData has only one byte, VBS may not alert you to the fact
that 'Mid$(sData, 2, 1))' does not exist and proceed to load a blank
into 'lLowByte" ... which may be ok until some condition gets a choke-
hold on the VBA compiler and triggers angry mister error generator.

This may be part of understanding MSComm, but each serial input  is
only one byte. My code is fast enough, so I get individual bytes.

3- Pepper yout code with Debug.Print statements and spend lots of
time staring at the results in the immediate window to track variable
values and code progression. Mine has so many (and I don't want to
delete them for fear of future need), it frequently takes me
considerable time to figure out what the heck I'm looking at and
there I am in the execution, so I also prefix variables with the name
of the variable  and location in the code. Like this:

Placed appropriately:
Debug.Print "*Get-Data Sub Entry"

Debug.Print "* Get-Data Sub, sData=" ; sData

Debug.Print "* Get-Data Sub EXIT"

[[ notice the indented structure that mimics nesting.]]

OR

Debug.Print "* Get-Data Sub, sData=" ; Mid(sData,1,1);"-";Mid(sData
(2,1)' etc


Something...
I think all my such statements have "ActiveSheet" as prefixes for
cell references, where yours below doesn't:
ActiveSheet.Cells(r, 1) = Readable / 1000

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on newbie questions Or get search suggestion and latest updates.


Tagged: