Shop OBEX P1 Docs P2 Docs Learn Events
if..else — Parallax Forums

if..else

ice-egozice-egoz Posts: 55
edited 2004-09-16 15:01 in BASIC Stamp
this is my statement: area18: IF latitudeMin=17 AND longitudeMin=37 THEN DEBUG "Tuas South"
can i do this:
area18: IF latitudeMin=17 AND longitudeMin=37 THEN serData=·"Tuas South"

I know that the above statement will give me an error.. but what other ways can i use to do this?




▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I need all ya guidance Masters. [noparse]:)[/noparse]

Comments

  • Fe2o3FishFe2o3Fish Posts: 170
    edited 2004-09-16 04:00
    The syntax you're using would be OK if you add this line

    ' {$PBASIC 2.5}
    
    



    to the beginning of your program. This is presuming that you're
    using the newer Basic Stamp Editor/Development System. Your
    statement would fall under the the single line syntax of IF...THEN...ELSE

    If you're not using the new PBASIC 2.5 syntax then the part
    after the THEN should be a statement label. If this is the case
    then you could try something like this:

       IF not (latMin=17 AND lonMin=37) then keep_testing
       DEBUG "Tuas South"
    
       keep_testing:
       ' more code here...
    
    



    Well, it works for me. smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rusty-
    --
    Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
    **Out yonder in the Van Alstyne (TX) Metropolitan Area**
    Microsoft is to software what McDonalds is to gourmet cooking
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-16 04:44
    PBASIC does not support string types. What you can do is use string pointers -- change your pointer and then use a subroutine to print it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ice-egozice-egoz Posts: 55
    edited 2004-09-16 05:01
    I have many lines of similar codes:

    serData······ VAR········· Byte(4)

    area33: IF latitudeMin=18 AND longitudeMin=38 THEN DEBUG "Tuas" ' over here can i make it serData? rather tham DEBUG
    area34: IF latitudeMin=19 AND longitudeMin=38 THEN DEBUG "Tuas"
    area35: IF latitudeMin=20 AND longitudeMin=38 THEN DEBUG "Tuas/AYE"

    instead of wasting memory, I decided to use a VAR Byte(4) to store the String rather than DEBUG. I am using version 2.5..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-16 05:13
    You could change DEBUG to SEROUT with the correct parameters -- this would consume a lot of code space though. Better to change the THEN portion of each line to changing the pointer to the string, then calling a subroutine that prints it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ice-egozice-egoz Posts: 55
    edited 2004-09-16 05:59
    whats a pointer to a string?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-16 15:01
    To reduce the number of SEROUTs in a program one can store their strings in DATA statements; this is quite common and some of the demo programs from Parallax that you're using do this.· Each string has a location in memory -- a variable can be set to the location of the first character of the string before calling the printing (SEROUT) routine; this is what is meant by pointing.· When the varialbe is set to the first location of the string, it is "pointing" to it for the printing loop that might look something like this:

    Print_String: 
      DO 
        READ eeAddr, char 
        eeAddr = eeAddr + 1 
        IF (char = 0) THEN EXIT 
        SEROUT TxPin, Baud, [noparse][[/noparse]char] 
      LOOP 
      RETURN
    


    For this code, "eeAddr" is the pointer to the string.· It is set to the first location of the (zero-terminated) string before calling the routine.

    Our WAM and StampWorks books have examples that will help you -- you might want to take a week or so to work through them before continuing with your sophisticated experiments.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.