# dealing/separating strings in BASIC

August 14, 2008

I didn't know whether to put this in absolute beginners or here..

anyways, what i'm trying to do is use my ADC port to get some values from one of my sensors and once i've done this i want this value to be displayed on a three digit seven segment display. I know how to right single numbers on the 7-segment display, but i wouldn't know how to deal with, say, a three digit number.

So i thought it might come in very handy **to separate the ADC value in three parts**. Example: say readadc gives 234, i want to have 3 variables which are equal to 2, 3 and 4. I know how to do it with other languages but not with basic. Not only though. **I also wanted to ask you if any command you actually use with BASIC can also be used by the BASIC offered by the picaxe**. (or can i only use the commands listed on the manual?)

thank you :)

## You can just write yourself

You can just write yourself out of it, knowing all non-integers are lost.

I would have to think about it but to give you a clue;

X = your number (234)

Y = x / 10 (y=23)

Y = Y * 10 (Y=230)

Z = x - Y (Z = 4, so Z = the rightmost number)

You may have to enter some if > 5 etc to make it all work :) But there may very well be a very simple form waiting for you once you get started to look for it :)

## Use the 'modulus' operator

To answer your second question, you can only use BASIC commands that PicAxe understands.

But, you are in luck. The PicAxe has a modulus operator. The '%' symbol is used to return the remainder of an integer division. So in your example above ...

X = 234

C = X % 10 ' 234 / 10 = 23 with remainder 4, so C = 4

X = X / 10 ' Now divide for real, X = 23

B = X % 10 ' 23 / 10 = 2 with remainder 3

X = X / 10 ' X = 2

A = X % 10 ' 2 / 10 = 0 with remainder of 2

So now, A = 2, B = 3, and C = 4.

You could also do this in a loop while X > 0.

## Wohoo! I did not know that,

Wohoo! I did not know that, thanks.

I read they are working on (brackets) in calculations and floating point as well!

Dont know what to use floating point for though, I kinda like it as it is :)