Melfa Basic VI - If...Then...Elseif...Endif Syntax Help / Examples

  • I have a simple syntax question concerning Melfa Basic VI If...Then...Elsif...Endif statements.

    What I want this routine to do is this - Based on the exteranl inputs run specific subroutine and if none are true goto a holding Position (posXXX).

    The way I currently have it programmed is working except for when none of the Inputs are true, The program goes to the next subroutine.


    *Box1, *Box2, *Box3 are subroutines. posXXX is the default/ holding position.

    If M_In(11) = 1 Then *Box1

    If M_In(12) = 1 Then *Box2

    If M_In(13) = 1 Then *Box3


    I have read all the Mitsubishi documentation on thes If/Then/Elseif statements and every time I try to include the last "Else" condition I get syntax errors.


    Any help is appreciated, program examples welcome.

    Thanks in advance.

  • AD
  • Without knowing Melfa Basic, somethink like this should work:

    it would be better:

    1. posting one of your faulty trials

    2. posting a bit more of your code, at least some lines following the If/Then/Else . ;)

    • Helpful

    Goto is suboptimal. Make a local subroutine and use GoSub.

    When the subroutine is finished, the program pointer jumps back to the place where it was called.

  • Thank you all for your responses.


    BO,

    The script you have is exactly how I have been keeping this process moving fwd.

    But I know there is a more standard way to write this routine. I just kept hitting syntax errors.


    HE,

    I had tried your idea and still received syntax errors.


    Roland,

    Your idea worked great! Below is the working program.


    *BoxEval

    Mvs posPostScan

    If M_In(10) = 1 Then

    GoSub *Box6

    Break

    ElseIf M_In(11) = 1 Then

    GoSub *Box1

    Break

    ElseIf M_In(12) = 1 Then

    GoSub *Box2

    Break

    ElseIf M_In(13) = 1 Then

    GoSub *Box3

    Break

    ElseIf M_In(14) = 1 Then

    GoSub *Box4

    Break

    ElseIf M_In(15) = 1 Then

    GoSub *Box5

    Break

    Else

    GoSub *BoxEval

    EndIf


    Roland - "Goto is suboptimal. Make a local subroutine and use GoSub.

    When the subroutine is finished, the program pointer jumps back to the place where it was called."


    I'm a rookie with Melfa Basic and have always used "Go To" instead of "GoSub".

    What are the practical differences between GoTo and GoSub?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now