> -----Original Message-----
> From: Chris Loiacono [SMTP:spam_OUTchrisTakeThisOuT
MAIL2ASI.COM]
> Sent: Tuesday, February 18, 2003 9:17 PM
> To: .....PICLISTKILLspam
@spam@MITVMA.MIT.EDU
> Subject: [EE]: vb6 solution to share
>
> Since I promised a couple folks that contacted me off list that I would
> share the working result of the vb challenge, here'tis:
>
> Dim Value As Single 'form input value - can be 16 bit floating point
> single
>
A VB 'Single' is a 32 bit floating point.
{Quote hidden}> Dim HVal As Long 'hi byte -doesn't need to be long, int
> works. Long is just
> a habit
> Dim LVal As Long 'low byte -doesn't need to be long either,
> int works.
> Still a habit
>
>
> HVal = Value/ 256
> LVal = Value Mod 256
> If LVal > 127 Then
> HVal = HVal - 1
>
> Then, go send HVal & LVal bytes out via MSComm.
>
HVal and LVal are not bytes though, I presume you are just sending the LSB
of each?
> This splits the 16 bit value into two bytes that you can send to a PIC
> serially.
> Then just reconstruct the word by doing HVal * 256 & summing with the LVal
> byte.
> Voila - a simple way to get a 16 bit value out of vb & into a PIC.
> Jen was a big help in making it so simple....
> Chris
>
Note that this solution rounds any fractional parts of 'Value' to the
nearest integer rather than truncating them.
Regards
Mike
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listserv
KILLspammitvma.mit.edu with SET PICList DIGEST in the body