BBC BASIC for Windows
« Converting Variable Types »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:10pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Converting Variable Types  (Read 769 times)
DJ-Dwayne
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 4
xx Converting Variable Types
« Thread started 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.
« Last Edit: Jun 19th, 2015, 07:30am by DJ-Dwayne » User IP Logged

DJ-Dwayne
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 4
xx Re: Converting Variable Types
« Reply #1 on: Jun 19th, 2015, 07:55am »

Grrr...
found the answer.

VAL

staring me right in the face.
Is there a better way or not?
User IP Logged

dfeugey
Guest
xx Re: Converting Variable Types
« Reply #2 on: Jun 19th, 2015, 09:36am »

I don't think so.
User IP Logged

DJ-Dwayne
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 4
xx Re: Converting Variable Types
« Reply #3 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 ???
User IP Logged

rtr2
Guest
xx Re: Converting Variable Types
« Reply #4 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.
User IP Logged

dfeugey
Guest
xx Re: Converting Variable Types
« Reply #5 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.
« Last Edit: Jun 20th, 2015, 08:45am by dfeugey » User IP Logged

rtr2
Guest
xx Re: Converting Variable Types
« Reply #6 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls