Shop OBEX P1 Docs P2 Docs Learn Events
Defining String (problem) — Parallax Forums

Defining String (problem)

BorisBoris Posts: 81
edited 2005-01-28 18:26 in BASIC Stamp
A simple problem, its gota be something obvious.

How come I get an error when i do this:

Faults VAR Byte(23)
Faults="test"·

Basic Stamp Editor 2.1 stops on letter "e" in "test" and says "Expected ':' or end of line"

do i have to write characters into "Faults" variable one by one?
·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-28 18:01
    Maybe:

    Faults = STR "test" ?
  • Erik ArendallErik Arendall Posts: 21
    edited 2005-01-28 18:14
    If you look under the help file you will find a section under hte DEBUG command that has example code on how to display strings. Here is the section. Hopefuly this will help.

    Displaying Strings (Byte Arrays)

    If you have a string of characters to display (a byte array), you can use the STR formatter to do so. The STR formatter has two forms (as shown in the table above) for variable-width and fixed-width data. The example below is the variable-width form.

    alpha VAR Byte(5)

    Init:
    alpha(0) = "A"
    alpha(1) = "B"
    alpha(2) = "C"
    alpha(3) = "D"
    alpha(4) = 0

    Main:
    DEBUG STR alpha, CR ' display "ABCD"
    END

    This code displays "ABCD" on the screen. In this form, the STR formatter displays each character contained in the byte array until it finds a character that is equal to 0 (value 0, not "0"). This is convenient for use with the SERIN command's STR formatter, which appends 0's to the end of variable-width character string inputs. NOTE: If your byte array doesn't end with 0, the BASIC Stamp will read and output all RAM register contents until it finds a 0 or until it cycles through all RAM locations.

    To specify a fixed-width format for the STR formatter, use the form STR alpha\n; where alpha is the byte array and n is the number of characters to print. Changing the DEBUG line in the example above to: DEBUG STR alpha\2 would display "AB" on the screen.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-28 18:26
    There is no string type in PBASIC -- you can use an array of characters, but as Erik indicates above you must fill the array char-by-char. For messages, the DATA statement is convenient place to store strings (arrays of characters) that are "printed" with a subroutine.

    Msg DATA "BASIC Stamp by Parallax", 0

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.