Shop OBEX P1 Docs P2 Docs Learn Events
Assign a NULL value to a variable? — Parallax Forums

Assign a NULL value to a variable?

MorrolanMorrolan Posts: 98
edited 2008-05-31 11:40 in BASIC Stamp
Hi all,

I've suddenly developed a need to assign a NULL value to a variable.

IF dir = 1 THEN                      ' dir is a byte, 0 = N, 1 = S from Parallax GPS Receiver)
   negDisp = negSym                      ' negDisp is a byte, negSym is a Constant (45) for hyphen/minus symbol on Parallax serial LCD)
 ELSEIF dir = 0 THEN                
   neg = NULL
 ENDIF

  SEROUT TX, LcdBaud, [noparse][[/noparse]$85, negDisp, DEC degrees, ".", DEC4 workVal]            ' adapted from the GPS Demo code to output to a serialLCD instead of Debug



Obviously the NULL isn't liked by the syntax checker but that is where I need to assign a null value.

My problem is as I am only using the decimal GPS format, I need to determine a way to display the negative symbol if the direction (dir) returned from the GPS receiver for Lat and Long coordinates is W or S.

Is there an easier way to do this or have I just missed how to empty a variable somewhere along the line?

Many Thanks in Advance,
Morrolan
.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.

"I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
Stephen Hawking

Post Edited (Morrolan) : 5/30/2008 4:24:50 PM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-05-30 17:45
    How about neg = ""

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-30 17:58
    There's no such thing as a null string or empty string in PBasic. You would have to do something like
    IF dir = 1 THEN                      ' dir is a byte, 0 = N, 1 = S from Parallax GPS Receiver)
       SEROUT TX, LcdBaud, [noparse][[/noparse]$85, "-", DEC degrees, ".", DEC4 workVal]
    ELSEIF dir = 0 THEN                
       SEROUT TX, LcdBaud, [noparse][[/noparse]$85, DEC degrees, ".", DEC4 workVal]
     ENDIF
    
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2008-05-30 18:10
    I would do this as follows, using the REP modifier:

    sign VAR bit
    SEROUT TX, LcdBaud, [noparse][[/noparse]$85, REP "-"\sign, DEC degrees, ".", DEC4 workVal]            ' adapted from the GPS Demo code to output to a serialLCD instead of Debug
    
    


    If sign=1 or sign=0, the "-" is either included or not.

    Another way to do this is,

    sign VAR bit
    SEROUT TX, LcdBaud, [noparse][[/noparse]$85, 13*sign+32, DEC degrees, ".", DEC4 workVal]            ' adapted from the GPS Demo code to output to a serialLCD instead of Debug
    
    



    That version sends out either a space (sign=0) or "-" (sign=1).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • MorrolanMorrolan Posts: 98
    edited 2008-05-31 11:40
    Thanks for the replies!

    Of course I should have realised that I should just do it Mike Green's way but I was tired at that point.

    I will also investigate the REP modifier as that looks to be the neatest and smallest solution so far.


    Many Thanks,
    Morrolan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking
Sign In or Register to comment.