Searching \ for '[EE]: vb6 solution to share' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=vb6+solution+share
Search entire site for: 'vb6 solution to share'.

Exact match. Not showing close matches.
PICList Thread
'[EE]: vb6 solution to share'
2003\02\18@161758 by Chris Loiacono

flavicon
face
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
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.

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

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\19@030259 by hael Rigby-Jones

picon face
> -----Original Message-----
> From: Chris Loiacono [SMTP:spam_OUTchrisTakeThisOuTspamMAIL2ASI.COM]
> Sent: Tuesday, February 18, 2003 9:17 PM
> To:   .....PICLISTKILLspamspam@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}

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 listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\19@082143 by Chris Loiacono

flavicon
face
A good point to mention, sorry I neglected to do so.
Actually, it rounds the intermediate result then shifts it into place to
make the low bit.

This was intended to take a distance of desired travel in decimal inches -
input thru a text box and converted to the number of motor steps. In my app,
I multiply the distance by a number = the number of steps per inch in a
linear motion system, which can be a 16 bit integer. This passes the high &
low bytes out (via MSCOMM) to be summed in the PIC code on the receiving
end. The result is always the closest step position. It rounds to the
closest step. With a 200 step motor and an 18 thread lead, this gets
position within .00028 inches every time...

c

> Note that this solution rounds any fractional parts of 'Value' to the
> nearest integer rather than truncating them.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\02\19@183907 by Mike Singer

picon face
Chris Loiacono wrote:
> This was intended to take a distance of desired travel in
> decimal inches - input thru a text box and converted to
> the number of motor steps. In my app, I multiply the
> distance by a number = the number of steps per inch in
> a linear motion system, which can be a 16 bit integer.
> This passes the high & low bytes out (via MSCOMM) to
> be summed in the PIC code on the receiving end.
  Have not red previous posts of this thread, sorry.
How about going this way:

- two text boxes: left box for two digits at the left of a decimal
 delimiter; right box for two digits at the right of it. (Label box
 with a decimal delimiter is placed between them).

- when either text box gets a focus ("GotFocus" event) then
 its content should be selected:

Private Sub Text1_GotFocus()
 Text1.SelStart = 0   Text1.SelLength = Len(Text1.Text) End Sub
  - changing the content of Text1 box we fire sub Text1_Change():

Private Sub Text1_Change()
If Len(Text1) = 2 Then
 Byte1 = (Asc(Left(Text1, 1)) - 48) * 16 + Asc(Right(Text1, 1)) - 48
End If
End Sub

  Byte1 is a byte to hold two decimal digits at the left of a
delimiter;
  (Don't forget to declare it:        Dim Byte1 As Byte)

  Left(Text1, 1) is left char of Text1 textbox;

  Asc(Left(Text1, 1)) is ASC code of the char: 48 for "0" , 57 for "9";
  Thus (Asc(Left(Text1, 1)) - 48) gives 0 for "0" , 9 for "9";

  (Asc(Left(Text1, 1)) - 48) * 16 converts left char of Text1 into 4
  most significant bits of byte variable Byte1.
  Asc(Right(Text1, 1)) - 48 converts right char of Text1 into 4
  least significant bits of byte variable Byte1.

  Get Byte2 in a similar way from Text2 textbox.
  Send them to PIC.    Nobody needs to be 100% Scott Dattalo (1 ScDat) to get a PIC    convert two bytes holding 4 decimal digits into something    appropriate. (0.1% ScDat is pretty enough, I think :-)

  Mike.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...