ValueS()

Started by May 10, 2004

Hello,

My basicX reference material says that I can turn a string into a
single using the "ValueS" type conversion, however I can't find it in
context anywhere and the compiler complains when I try to use it.

Does this function exist -- or do I have to do the conversion
longhand? For some reason Honeywell decided that it would be cool to
drop preceeding zeroes so I can't count on knowing decimal position
before parsing the data string.

Any words of wisdom?

Thanks,

-Mason



Hi Mason,

I downloaded a document from NetMedia titled "Basic Express System Library 2.0 and page 128 shows
-------------------------
ValueS procedure

Call ValueS(StringVar, Value, Success)

Arguments:

ITEM TYPE DIRECTION DESCRIPTION
StringVar String Input Input string
Value Single Output Return Value
Success Boolean Output Success flag

Description:

Converts a string to a Single type. If no errors occur, the number is returned in Value and the Success flag is set to True. Otherwise Value is set to 0.0 and Success is set to False.

The number in the string must consist of numeric digits with optional signs for the number and exponent. A decimal point is also optional. Leading and trailing control characters (such as spaces or tabs) are ignored.

Example:

Dim Tx As String
Dim Value As Single
Dim Success As Boolean

Tx = " 123 "
Call ValueS(Tx, Value, Success) ' Value is 123.0, Success is True

Tx = "-4.5E+03"
Call ValueS(Tx, Value, Success) ' Value is -4500.0, Success is True

'Illegal characters.
Tx = "&HFF"
Call ValueS(Tx, Value, Success) ' Value is 0.0, Success is False
-

I have not used this procedure, but I feel that it should work. As with any new instruction, I would code a
series of small test programs to be sure that all possible uses of the instruction will produce a bug free program.

Eric
----- Original Message -----
From:
To:
Sent: Monday, May 10, 2004 8:00 PM
Subject: [BasicX] ValueS()
Hello,

My basicX reference material says that I can turn a string into a
single using the "ValueS" type conversion, however I can't find it in
context anywhere and the compiler complains when I try to use it.

Does this function exist -- or do I have to do the conversion
longhand? For some reason Honeywell decided that it would be cool to
drop preceeding zeroes so I can't count on knowing decimal position
before parsing the data string.

Any words of wisdom?

Thanks,

-Mason





Thanks lots Eric,

For some reason that procedure is not listed in the 2.1 (or the 1.46)
System Library. Worked like a charm though: call ValueS(H, CH, Success)

debug.print H; "h"
debug.print cstr(CH) 252.1h
252.1
252.1h
252.1
251.7h
251.7
251.9h
251.9
252.0h
252
252.0h
252
251.8h
251.8 /relief

I'm going to sleep well tonight -- thanks again,

-Mason --- In , "eserdahl@" <eserdahl@p...> wrote:
> Hi Mason,
>
> I downloaded a document from NetMedia titled "Basic Express System
Library 2.0 and page 128 shows
> --------------------------------
-----------------------------
> ValueS procedure
>
> Call ValueS(StringVar, Value, Success)
>
> Arguments:
>
> ITEM TYPE DIRECTION DESCRIPTION
> StringVar String Input Input string
> Value Single Output Return Value
> Success Boolean Output Success flag
>
> Description:
>
> Converts a string to a Single type. If no errors occur, the number
is returned in Value and the Success flag is set to True. Otherwise
Value is set to 0.0 and Success is set to False.
>
> The number in the string must consist of numeric digits with
optional signs for the number and exponent. A decimal point is also
optional. Leading and trailing control characters (such as spaces or
tabs) are ignored.
>
> Example:
>
> Dim Tx As String
> Dim Value As Single
> Dim Success As Boolean
>
> Tx = " 123 "
> Call ValueS(Tx, Value, Success) ' Value is 123.0, Success is True
>
> Tx = "-4.5E+03"
> Call ValueS(Tx, Value, Success) ' Value is -4500.0, Success is True
>
> 'Illegal characters.
> Tx = "&HFF"
> Call ValueS(Tx, Value, Success) ' Value is 0.0, Success is False
> --------------------------------
-----
>
> I have not used this procedure, but I feel that it should work. As
with any new instruction, I would code a
> series of small test programs to be sure that all possible uses of
the instruction will produce a bug free program.
>
> Eric
> ----- Original Message -----
> From: m0nk_x@y...
> To:
> Sent: Monday, May 10, 2004 8:00 PM
> Subject: [BasicX] ValueS() >
> Hello,
>
> My basicX reference material says that I can turn a string into a
> single using the "ValueS" type conversion, however I can't find
it in
> context anywhere and the compiler complains when I try to use it.
>
> Does this function exist -- or do I have to do the conversion
> longhand? For some reason Honeywell decided that it would be cool
to
> drop preceeding zeroes so I can't count on knowing decimal
position
> before parsing the data string.
>
> Any words of wisdom?
>
> Thanks,
>
> -Mason





Anybody have trouble when your String is either a "-" or "."??
String returns 0.0 and boolean is returning true for both cases...

Thad

Sample Code:
Sub Main()
Dim Entry as Byte
Dim StrNum as String
Dim Str as String
Dim StrS as Single
Dim ItsANum as Boolean
Dim N as Integer
StrNum = "555-1212..!"
N = 0
Do
Do
N = N + 1
Str = Mid(StrNum, N, 1)
If Str ="." Then
Call Sleep(0.5)
End If
Call ValueS(Str, StrS, ItsANum)
Entry = CByte(StrS)
Loop Until (ItsANum)
Debug.Print CStr(N) & " " & Str & " " & _
CStr(Entry)& " " & CStr(ItsANum);
Debug.Print
Loop Until (Str = "!")
End Sub

Output:
1 5 5 True
2 5 5 True
3 5 5 True
4 - 0 True
5 1 1 True
6 2 2 True
7 1 1 True
8 2 2 True
9 . 0 True

--- In , m0nk_x@y... wrote:
>
> Thanks lots Eric,
>
> For some reason that procedure is not listed in the 2.1 (or the
1.46)
> System Library. Worked like a charm though: > call ValueS(H, CH, Success)
>
> debug.print H; "h"
> debug.print cstr(CH) > 252.1h
> 252.1
> 252.1h
> 252.1
> 251.7h
> 251.7
> 251.9h
> 251.9
> 252.0h
> 252
> 252.0h
> 252
> 251.8h
> 251.8 > /relief
>
> I'm going to sleep well tonight -- thanks again,
>
> -Mason


From: Thad Larson <>

> Anybody have trouble when your String is either
> a "-" or "."?? String returns 0.0 and boolean is
> returning true for both cases...
> [...]
> Call ValueS(Str, StrS, ItsANum)

Yes, there is a bug in ValueS. In both cases, the strings are
illegal, and ItsANum should return false.

-- Frank Manning
-- NetMedia, Inc.



Frank Manning wrote:

> From: Thad Larson <>
>
> > Anybody have trouble when your String is either
> > a "-" or "."?? String returns 0.0 and boolean is
> > returning true for both cases...
> > [...]
> > Call ValueS(Str, StrS, ItsANum)
>
> Yes, there is a bug in ValueS. In both cases, the strings are
> illegal, and ItsANum should return false.
>
> -- Frank Manning
> -- NetMedia, Inc. >
>
> **

Just curious here... is there an official errata file or is NetMedia
planning on fixing these bugs or both or ???? I understand that most are
quite unusual to stumble upon but it would sure be nice to know where
previous stumbles occured. Can the pcode interpreter even be field
upgraded? I'm sure most of these "features" can be addressed via the
compiler, hopefully.

-Mike