Announcement

Collapse
No announcement yet.

Can't Make It Work -- Please Help

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

  • 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!!!

  • #2
    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,
    Dale

    Comment


    • #3
      #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

      Comment


      • #4
        '
        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,
        Dale

        Comment


        • #5
          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

          Comment


          • #6
            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!

            Comment


            • #7
              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!

              Comment

              Working...
              X