Announcement

Collapse
No announcement yet.

Can't Make It Work -- Please Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dale Yarker
    replied
    '
    Code:
    #compile exe
    #dim all
    
    function pbmain () as long
      local myptr as dword
      MyPtr = codeptr(MyLabel)
      on 1 goto Myptr
      ? "did not work"
      waitkey$
      exit function
      MyLabel:
        ? "worked"
        waitkey$
    end function '
    Won't compile here. Using GOTO DWORD MyPtr compiles and runs. GOSUB the same.
    ON n GOTO , GOTO , ON n GOSUB and GOSUB do not take pointers.

    If you can't test, then read Help. If you can't do either, then say nothing. (One (initials deleted) around here is already one too many!)

    Leave a comment:


  • Walt Decker
    replied
    FWIW ON .... GOTO and ON ... GOSUB will also take CODE POINTERS as will GOTO and GOSUB

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Michael Mattias View Post

    Or you may use
    ON n GOSUB {label | line_number} [, {label | line_number}] ...
    OR
    ON n GOTO {label | line_number} [, {label | line_number}] ...
    FWIW, "preferable" is subjective.


    MCM
    FWIW, I repeat from Post #3:..
    (or, but very inferior, On x GOSUB or ON x GOTO)

    Not just my subjective judgement. To quote Bob Zale:
    The SELECT and IF blocks also perform multiple branching, and are more flexible than ON GOTO
    (he wrote the same about ON GOSUB)

    Note also my comment:

    or IF...ELSE(IF)...END IF (a bit more difficult to debug for complex cases)
    Do you dispute that observation as well?
    Last edited by Stuart McLachlan; 18 Oct 2020, 12:03 AM.

    Leave a comment:


  • Michael Mattias
    replied
    If you want to branch depending on a value, use SELECT CASE, (preferable)
    Or you may use
    ON n GOSUB {label | line_number} [, {label | line_number}] ...
    OR
    ON n GOTO {label | line_number} [, {label | line_number}] ...

    FWIW, "preferable" is subjective.


    MCM

    Leave a comment:


  • Dale Yarker
    replied

    Leave a comment:


  • David Jeppesen
    replied
    Dale and Stuart,

    Bback on 17 Sept I solicited your help and you more than graciously responded. Thank you so much ! I n the interim I have not been well , and have only now escaped the clutches of the hospital. But a quick read looks like you have solved my problem. !! Thanks again !!

    Leave a comment:


  • David Jeppesen
    replied
    Oh.Wow! You guys ARE the old troopers! I am getting so old and blind I didn't even see your respohses!!! Now you've given me some homework Thank you so micu!! I'll be back!

    Leave a comment:


  • David Jeppesen
    replied
    1..1 Well. I was trying to recruite a new member to PBCC....I didn't do so well on that one did ??g Something is really broken somewhere. All of my back up files are mixed up with the wrong originals. 1. 2 I overheard someone say that it acts like some burffres are being overrun. I agree. 1 . 3 Too bad you were unable to bring the old troops along to the new system. You had some real characters in there!

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Dale Yarker View Post
    But especially note
    'the overlap in our suggestions
    ' Cheers,
    Especially the #DIM ALL, which we also pointed out in a couple of 2013 threads started by David, combined with suggestions about single character variable names versus descriptive ones

    Leave a comment:


  • Dale Yarker
    replied
    '
    Code:
     I am sure I missed the logic you wanted, but this compiles and runs.
    #compile exe
    #dim all
    #debug display on  'D3BUG to DEBUG
    #break on 'enables "X" upper right for alternate close method. you
              'still need WAITKEY$ below to hold window
    
    '#### Line numbers and GOTO now considered "bad form" #########
    
    function pbmain () as long
      local A, B, D, X, Y as single
      print "INPUT A, B, D"
      A = 100.
      B = -100.
      D = 1
      print A; B; D
    
    
      print "INPUT A, B, D"
      2 X=(A+B)/2
      Y=X 'Driver Equation' Y=f(X)'
      if (abs(B-X)-D) = 3 or (abs(B-X)-D) = 4 then
      3 print A; B; X
      end if
      4 if (Y) = 5 or (Y) = 3 or (Y) = 6 then
          5 A=X
          goto 2
          6 B=X
          goto 2
        end if 'inserted END IF
    
    
      print : print "Any key to close."
      waitkey$ 'keep console window open so results can be read
    end function '
    Stuart posted while I was away. But especially note
    'the overlap in our suggestions
    ' Cheers,

    Leave a comment:


  • Stuart McLachlan
    replied
    #D3BUG DISPLAY ON replace the 3 with an E
    Always use #DIM ALL
    Forget about the old BASIC style line numbers and GOTOs.
    Look in Help for the correct way to use IF.
    If you want to branch depending on a value, use
    SELECT CASE, (preferable)
    or IF...ELSE(IF)...END IF (a bit more difficult to debug for complex cases)
    (or, but very inferior, On x GOSUB or ON x GOTO)

    I'm not sure of exactly what you are trying to achieve, but I think it's something like:

    Code:
    #COMPILE EXE
    #DEBUG DISPLAY ON
    #DIM ALL
    #BREAK ON
    
    FUNCTION PBMAIN () AS LONG
    LOCAL a,b,c,d,x,y AS SINGLE
    
      INPUT "Input A,B,D",A, B, D
      PRINT A; B; D
    DO
      X=(A+B)/2
      Y=X 'Driver Equation' Y=f(X)'
      SELECT CASE   ABS(B-X)-D
           CASE 1,2
               PRINT A; B; X
           CASE ELSE
               PRINT "ABS(B-X)-D = ",ABS(B-X)-D
      END SELECT
    
      SELECT CASE y
          CASE 1
              A=X
          CASE 2
             PRINT A; B; X
          CASE 3
              PRINT "ABS(B-X)-D = ",ABS(B-X)-D
      END SELECT
    LOOP
    END FUNCTION
    But there's a major problem with the second Case for y. It's a perpetual loop

    Leave a comment:


  • Dale Yarker
    replied
    Still working on it. My first pass changes are -
    '
    Code:
    #compile exe
    #debug display on  'D3BUG to DEBUG
    #dim all 'vs NONE (see DEFSNG comment)
    #break on
    'DEFSNG A-Z 'do not use DEFxxx anymore, use LOCAL, GLOBAL, etc. instead
    function pbmain () as long
      local A, B, D, X, Y as single
      print "INPUT A, B, D"
      A = 100.
      B = -100.
      D = 1
      print A; B; D
    #if 0     'while I figure out if wanted separate IFs or nested
      print "INPUT A, B, D"
      2 X=(A+B)/2
      Y=X 'Driver Equation' Y=f(X)'
      if(abs(B-X)-D)3,3,4 then  '(added THEN)
        3 print A; B; X
        4 if(Y)5,3,6 then '(added THEN)
          5 A=X
          goto 2
          6 B=X
          goto 2
        end if 'inserted END IF
      end if 'change EXIT FUNCTION to END IF
    #endif
      print : print "Any key to close."
      waitkey$ 'keep console open so results can be read
    end function '
    Cheers,

    Leave a comment:


  • David Jeppesen
    started a topic Can't Make It Work -- Please Help

    Can't Make It Work -- Please Help

    #COMPILE EXE
    #D3BUG DISPLAY ON
    #DIM NONE
    #BREAK ON
    DEFSNG A-Z
    FUNCTION PBMAIN () AS LONG

    PRINT "INPUT A, B, D"
    A=100.
    B=-100.
    D=1
    PRINT A; B; D

    PRINT "INPUT A, B, D"
    2 X=(A+B)/2
    Y=X 'Driver Equation' Y=f(X)'
    IF(ABS(B-X)-D)3,3,4
    3 PRINT A; B; X
    4 IF(Y)5,3,6
    5 A=X
    GOTO 2
    6 B=X
    GOTO 2
    EXIT FUNCTION

    END FUNCTION
    888888888888888888 My first attempt here -- please bear with me. Have spent the better parF Furthermore the code you see (upper left ) of 4 days trying to get this ittle thing to work. It won't. Something is broken (my code upper left has been scrambled. Somebody please see if you can make sense of this. Thank you!!!
Working...
X