BBC BASIC for Windows
Programming >> BBC BASIC language >> Converting Variable Types
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1434698726

Converting Variable Types
Post by DJ-Dwayne on Jun 19th, 2015, 07:25am

.....Is there a command to to do this?

I'm new here and to bbfw

I'm sending numbers from my Arduino over the com port ready to be read from bbfw.

I've got it basically working, but there's a problem. The ending variables in bbfw aren't numeric, so I can't do any maths with them.

I don't know if i'm sending the data incorrectly from my Arduino board or i'm reading it wrong in bbfw. ???

I hope I don't get in trouble, but i'll show the code from both the Arduino and bbfw.

The Arduino Code....
Code:
int value;


void setup() {

  pinMode(13, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  value = random(1, 100); //select a random number between 0 and 100:
  Serial.print(value);
  Serial.write(13);//end data(CR);
} 



The BBC Basic Code....
Code:
  

      MODE7
      VDU 23,1,0;0;0;0; : REM Disable cursor
      VDU4

      arduino%=OPENUP("COM18: baud=9600 parity=N data=8 stop=1")
      PRINT "Com 18 Opened as Channel ";arduino%

  140 INPUT#arduino%,number$ :REM Get Data being sent

      VDU30
      PRINT TAB(6,1)"  ";
      VDU30
      PRINT TAB(0,1)"DATA=";number$

      GOTO 140
 

NOTE.....please excuse the naughty "goto" command :-*

Now....I can only use the "number$" type variable to get the numbers I want.
e.g.

number$="55" (Correct but unusable for Maths)

but if i took away the $ sign, I get something in the order of...

number = 9.25474568E-24 (WTF?????)


Maybee i'm not understanding strings v's bytes or something over serial.

I'm stumped just trying to explain the problem....PLEASE HELP.

Re: Converting Variable Types
Post by DJ-Dwayne on Jun 19th, 2015, 07:55am

Grrr...
found the answer.

VAL

staring me right in the face.
Is there a better way or not?
Re: Converting Variable Types
Post by dfeugey on Jun 19th, 2015, 09:36am

I don't think so.
Re: Converting Variable Types
Post by DJ-Dwayne on Jun 19th, 2015, 10:12am

on Jun 19th, 2015, 09:36am, dfeugey wrote:
I don't think so.


?????
Please explain.
I just went....
Code:
number2 = VAL(number$) 

I can now do maths with it.
Or is there a better way?
Please tell ???
Re: Converting Variable Types
Post by rtr2 on Jun 19th, 2015, 2:47pm

on Jun 19th, 2015, 10:12am, DJ-Dwayne wrote:
Or is there a better way?

VAL is the correct way.

Richard.
Re: Converting Variable Types
Post by dfeugey on Jun 20th, 2015, 08:44am

Quote:
Please explain.

Easy smiley
Is there a better way? > I don't think so.
That's the only and right way to do it.
Re: Converting Variable Types
Post by rtr2 on Jun 20th, 2015, 11:43am

Just to add that VAL is affected by the *lowercase setting:

Code:
      *lowercase on
      PRINT VAL("1e3")
      *lowercase off
      PRINT VAL("1e3") 

Richard.