Shop OBEX P1 Docs P2 Docs Learn Events
Is there a way to assign a $tring to a variable? (P$ = "test") — Parallax Forums

Is there a way to assign a $tring to a variable? (P$ = "test")

IceFireProIceFirePro Posts: 86
edited 2010-06-08 21:49 in BASIC Stamp
Can I assign string value to a variable in BS2?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-08 15:00
    No. There are no string variables in Stamp Basic.
  • IceFireProIceFirePro Posts: 86
    edited 2010-06-08 16:20
    So, i can just go to a subroutine that prints certain text based on the numerical value of a numeric variable, or use VB6 interfacing again.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-06-08 20:28
    You can create an array and store each character in that array. Remember, the BASIC Stamp has only 26 bytes of RAM / Variable space so dealing with strings can quickly consume that. It's often better to deal with strings on a byte-by-byte basis unless you have a BS2p or higher with SPRAM to store the string data. If the strings are constants they can be stored in EEPROM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-06-08 21:49
    Like:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    Str1 DATA "Hello",0

    MyStr VAR Word

    Main:
    · MyStr = Str1
    · SEROUT 16, 16864, [noparse][[/noparse]STR MyStr, CR]
    · PAUSE 500
    · GOTO Main

    This takes advantage that the 'label' for a DATA statement is really an 'address' into the eeprom.·
    And that the 'STR' modifier will accept a string address, expecting that string to end with a
    'zero' byte.


    ·
Sign In or Register to comment.