Shop OBEX P1 Docs P2 Docs Learn Events
Any Function similar to VB's CHR function? — Parallax Forums

Any Function similar to VB's CHR function?

MrdavidjenkinsMrdavidjenkins Posts: 49
edited 2005-07-20 22:04 in BASIC Stamp
----Is there a function like CHR that will convert a ascii character to a value?
---
I have a menu system that consists of a string of 20 characters Using a DATA string.·

Tx28· DATA·· "·····F257045 23· 150", CR,· 0
Tx29· DATA·· "·····25805E4 30· 132", CR,· 0
Tx30· DATA·· "·····25L8066 23· 150", CR,· 0

In this case, the first 12 characters are a product code, the 14th and 15 char are one parameter, the 17, 18 and 20 characters are a second parameter.· Both Parameters are numbers and need to be used in a formula.·

When I look up the product in the menu, I put these 20 characters into the scratch pad memory using the following:

LOOKUP (pulses), [noparse][[/noparse]tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8, tx9, tx10, tx11, tx12, tx13, tx14, tx15, tx16, tx17, tx18, tx19, tx20, tx21, tx22, tx23, tx24, tx25, tx26, tx27, tx28, tx29, tx30, tx31, tx32, tx33, tx34, tx35, tx36, tx37, tx38, tx39, tx40, TxP, TxP, TxP, TxP, TxP, TxP, TxP, txp, txp,· tx41, tx42, tx43, tx44, tx45, tx46, tx47, tx48, tx49, tx50, tx51, tx52, tx53, tx54, tx55, tx56, tx57, tx58, tx59, tx60, tx61, tx62, tx63, tx64, tx65, tx66, tx67, tx68, tx69, tx70], idx
idy = 0
·· DO
··· READ idx, char····················· ' Get next character
··· idx = idx + 1······················ ' Point to next location
··· IF (char = 0) THEN EXIT·······' If 0, we're done with block
··· DEBUG· char
··· idy = idy + 1
··· PUT idy, char
··· GET idy, char
· LOOP

This way, I have these characters in scratchpad locations 1 thru 20 and can pass them to and from the different 2k segments of my sx chip.

However, I need a way of taking a char like "3" and converting it to a value 3.·

Is there a function like CHR that will convert a ascii character to a value?· Then I plan on doing a bit of code like:

get 13, first
get 14, second
Temp = 10*CHR(first) + 1*CHR(second)


Thanks

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-20 21:57
    You can do it like this:

    · numVal = char - "0"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • MrdavidjenkinsMrdavidjenkins Posts: 49
    edited 2005-07-20 22:04
    Makes sense - thanks.
Sign In or Register to comment.