Question about If Then


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    4

    Default Question about If Then

    I have always found the If Then command in PicBasic very limiting:

    5.13. IF..THEN

    IF Comp { AND/OR Comp } THEN Label

    Performs one or more comparisons. Each Comp term can relate a variable to a constant or other variable and must be in the following form:

    Var ( < | <= | = | <> | >= | > ) Value

    All comparisons are unsigned since PBC only supports unsigned types. A variable must occur on the left.

    The THEN in an IF..THEN is essentially a GOTO. If the condition is true, the program will GOTO the label after the THEN. If the condition evaluates to false, the program will continue at the next line after the IF..THEN. Another statement may not be placed after the THEN, it must be a label
    Yet I have seen posts of code written in a similar style to C:
    If B0 = 0 Then
    (code to run goes here)
    Else
    (more code)
    EndIf

    If I try this, my compiler does not like it, telling me that it expected a label after the Then (as stated in the manual).

    Can anyone tell me how I can use this style in PicBasic?

    Sorry if it's a dumb question and thanks for reading!

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    hi,

    Did you try ???

    [code]
    If B0 = 0 Then nojump
    nojump:

    (code to run goes here)
    GOTO Jump
    Else
    (more code)
    EndIf
    Jump:

    [code]

    Looks obvious ... but note I'm using PBPro ...

    or :

    [code]
    If B0 = 0 Then turnaround

    Else
    (more code)
    EndIf

    BackHome:

    .
    .
    .
    .

    Turnaround:
    (code to run goes here)
    GOTO BackHome

    [code]

    This structure works with assembler ... so it should go too !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jan 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Yes, I have tried that. PB pro does look much better! In PB, Else is seen to be a label and it gives a ": expected" error on the line with Else on it. The method that works is very similar to what you suggested:

    If B0 = 1 Then LIGHTON
    Low 7
    Goto NEXTPART
    LIGHTON:
    High 7
    NEXTPART:
    (code continues)

    But unlike this most simple example, things start to get complicated (for me) when there are more If statements referring to that variable which makes what should be a single code block get spread out across many jump labels.

    So the Else and EndIf commands are used in PB pro? - I'll have to look into it. Thanks for the help.

  4. #4
    Join Date
    Mar 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Alektric View Post
    Yes, I have tried that. PB pro does look much better! In PB, Else is seen to be a label and it gives a ": expected" error on the line with Else on it. The method that works is very similar to what you suggested:

    If B0 = 1 Then LIGHTON
    Low 7
    Goto NEXTPART
    LIGHTON:
    High 7
    NEXTPART:
    (code continues)

    But unlike this most simple example, things start to get complicated (for me) when there are more If statements referring to that variable which makes what should be a single code block get spread out across many jump labels.

    So the Else and EndIf commands are used in PB pro? - I'll have to look into it. Thanks for the help.
    I also have run into this.
    PB is not what I was expecting, or sold for that matter.
    Nothing works like the examples given.
    I even get errors compiling the examples as you state.

    I cannot define VAR, CON, INCLUDES, etc. whats up with that?
    I'm gonna have to go back to MPLab asm at least it WORKS like I expect!

    I thought buying PB was going to help but it has made things more difficult.

    All I want to do is read pins and set pins with some if---elses but all I can do is peek and poke. I might as well just do asm if I have to write code in broken assembler...

    I am not trying to stir the pot but this is not straight forward as it is shown
    in software examples.

    Back to asm I go, ugh!!!


    -M_Z-

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Did you buy PBP (PicBasic Pro) or PBC (PicBasic Compiler).

    If you got PBP, then all those things will work.

    If you took the cheeper version (PBC) ... then you have a LONG nighmare ahead of you.
    DT

Similar Threads

  1. ADCIN question
    By Greg McFadden in forum General
    Replies: 4
    Last Post: - 16th September 2008, 02:53
  2. AN Question for "word" variable read The serial port
    By redfoen in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2007, 17:39
  3. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts