String To Integer/Real Help

Hi, sorry if this seem a bit of a simple ? but i only have a need to write very basic code .

I have to write a small programme to read a serial output from a device and represent the level data on a touch screen.

The screen can only show levels that are real/integer values.

I have stripped the relevant byte of level information with

ZONE1LEVEL:=(RECEIVEDDATA[6]);

I then try and ZONE1LEVEL:=STRINGTOINT byte 6 from above data, but ZONE1LEVEL always = 0.

With my limited knowledge stringtoint will result in 0 if the data to be converted is not something or other.

Byte 6 above will be in the range of #00 to #64

Any help greatly received.

Comments

  • : Hi, sorry if this seem a bit of a simple ? but i only have a need to
    : write very basic code .
    :
    : I have to write a small programme to read a serial output from a
    : device and represent the level data on a touch screen.
    :
    : The screen can only show levels that are real/integer values.
    :
    : I have stripped the relevant byte of level information with
    :
    : ZONE1LEVEL:=(RECEIVEDDATA[6]);
    :
    : I then try and ZONE1LEVEL:=STRINGTOINT byte 6 from above data, but
    : ZONE1LEVEL always = 0.
    :
    : With my limited knowledge stringtoint will result in 0 if the data
    : to be converted is not something or other.
    :
    : Byte 6 above will be in the range of #00 to #64
    :
    : Any help greatly received.
    :
    :
    StringToInt() will convert a string representing a number into that number. Thus:
    [code]
    StringToInt('456');
    [/code]
    gives an integer 456 as output. What you're trying to do is to convert a char into a byte. This doesn't involve a convertion function, but simple type casting:
    [code]
    var
    s: string;
    b: byte;
    begin
    s := 'Hello World';
    writeln(StringToInt(s)); // Error: 'Hello World' is not a number
    writeln((byte) s[1]); // The number 72 (ASCII code for H)
    end;
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion