Loading ...
Sorry, an error occurred while loading the content.

RE: [libertybasic] MyFirst-mike

Expand Messages
  • Stefan Pendl
    ... Below find your example enhanced to allow trapping the enter key. I corrected the counting too, since wrong answers counted as correct ones. I reduced the
    Message 1 of 5 , Sep 2, 2008
    • 0 Attachment
      >
      > Anyone new to Liberty, like myself, would have learnt a lot from your
      > code, like I did. However what I had in mind was this format:
      > 5 + 2 =
      > User enters his answer and presses 'Enter' on the keyboard.
      > If correct, display next question.
      > If incorrect, print a red 'X' beside the ans, wait for a while, then
      > proceed to next question.
      > 5 + 2 = 6 X
      > I managed to produce this horizontal display format. I am stuck
      > getting it to work with the 'Enter' key, and cannot get the 'X' in
      > red. I will appreciate some help on this.
      >
      > Next, I hope to 'randomize' the operator as well (subtract, divide,
      > add, multiply). I will not need help here, but welcome.
      >

      Below find your example enhanced to allow trapping the enter key.
      I corrected the counting too, since wrong answers counted as correct ones.
      I reduced the use of goto to the bare minimum.
      There was something left over from the non GUI version, so I altered the display of the results to use a notice box.
      I added a graphicbox to allow displaying the red X.

      To randomize the operator, I would create the string of the calculation to be displayed and use EVAL() to check the result entered
      by the user.
      Something like:
      '---
      Calc$ = num1; " "; oper$; " "; num2
      #1.st3 Calc$; " ="
      '...
      if eval(Calc$) <> ans then
      '---


      '---code start (watch for line wraps)
      NOMAINWIN

      WindowWidth=300
      WindowHeight=200
      UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
      UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

      STATICTEXT #1.st3, "", 20, 20, 130, 40
      TEXTBOX #1.tb3, 150, 20, 45, 40

      'create a borderless graphicbox to get coloured text
      stylebits #1.gb, 0, _WS_BORDER, 0, 0
      graphicbox #1.gb, 210, 20, 40, 40

      'create an invisible default button to trap the ENTER key
      'works with dialog windows only
      button #1.default "", [check], ul, 1, 1, 1, 1

      OPEN "Practice" FOR dialog AS #1
      PRINT #1, "trapclose [quit]"
      PRINT #1, "FONT courier_new 20 bold"

      'set up graphicbox
      #1.gb "font arial 25 bold"
      #1.gb "down"
      #1.gb "color red"
      #1.gb "backcolor buttonface"
      #1.gb "fill buttonface"
      #1.gb "flush wrong"

      [again]
      qnr=qnr+1
      num1=INT(RND(0)*10)+1
      num2=INT(RND(0)*10)+1
      PRINT #1.tb3, ""
      PRINT #1.st3, num1;" + ";num2;" = "
      PRINT #1.tb3, "!setfocus"
      WAIT

      [check]
      PRINT #1.tb3, "!contents? ans"
      'after typing the ans, to press Enter on the keyboard
      IF ans<>num1+num2 THEN
      gosub [incorrect]
      else
      corr=corr+1
      end if
      if qnr<10 then [again]

      [quit]
      notice "Your score is ";corr;" out of ";qnr
      CLOSE #1
      END

      [incorrect]
      #1.gb "delsegment wrong"
      #1.gb "place 1 30"
      PRINT #1.gb, "\X"

      'pause that will be equal length on all computers
      'wait one second
      timer 1000, [PauseEnd]
      wait
      [PauseEnd]
      timer 0
      'end pause code

      PRINT #1.gb, "fill buttonface"
      #1.gb "flush wrong"
      return
      '---code end

      ---
      Stefan Pendl
    • Stefan Pendl
      ... There is still one GOTO included, that is the only one needed. Blow find some hints in the example. To create a standalone application, use the Create
      Message 2 of 5 , Sep 2, 2008
      • 0 Attachment
        >
        > Hi SL,Thanks for the correction to the counting, eliminating
        > GOTOs completely, and the tip on 'Eval'. Most of all, on how
        > to display colored text.BL had already taught me on using the
        > 'Enter' key. Thanks, anyway.I prefer showing the results on
        > the window itself, rather than on (yet) another window, in
        > this case, the notice box.1) Can we completely clear the main
        > window, and show the results thereon?   
        > 2) So that, probably using smaller fonts, I can add in some
        > comments/message?3) Once the test is completed, how to exit
        > completely out of LB? (ie: without the need to manually close
        > the console window and code window)Thank you.

        There is still one GOTO included, that is the only one needed.
        Blow find some hints in the example.
        To create a standalone application, use the "Create Application" menu entry in the Run menu.
        You should still read the help file topic on this menu entry to get the whole concept.

        '---code start (watch for line wraps)
        oper$(1) = " + "
        oper$(2) = " - "
        oper$(3) = " * "
        oper$(4) = " / "

        'preset the value to keep EVAL() from failing on the first run
        calc$= "0"

        NOMAINWIN

        WindowWidth=300
        WindowHeight=200
        UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
        UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

        stylebits #1.st3, _SS_RIGHT, 0, 0, 0
        STATICTEXT #1.st3, "Begin...", 20, 20, 180, 40

        'create a right justified textbox
        stylebits #1.tb3, _ES_RIGHT, 0, 0, 0
        TEXTBOX #1.tb3, 200, 20, 50, 40

        'create a borderless graphicbox to get colored text
        stylebits #1.gb, 0, _WS_BORDER, 0, 0
        graphicbox #1.gb, 250, 20, 40, 40

        'create an invisible default button to trap the ENTER key
        'works with dialog windows only
        button #1.default "", [check], ul, 1, 1, 1, 1

        statictext #1.tx1, "Your Score is", 20, 80, 210, 30
        statictext #1.tx2, "out of", 20, 110, 210, 30

        'create right justified statictext
        stylebits #1.corr, _SS_RIGHT, 0, 0, 0
        statictext #1.corr, "", 230, 80, 50, 30
        stylebits #1.qnr, _SS_RIGHT, 0, 0, 0
        statictext #1.qnr, "", 230, 110, 50, 30

        OPEN "Practice" FOR dialog AS #1
        PRINT #1, "trapclose [quit]"
        PRINT #1, "FONT courier_new 20 bold"

        'set up graphicbox
        #1.gb "font arial 25 bold"
        #1.gb "down"
        #1.gb "color red"
        #1.gb "backcolor buttonface"
        #1.gb "fill buttonface"
        #1.gb "flush wrong"

        [again]
        qnr=qnr+1

        'loop until the result is an integer
        do
        num1=INT(RND(0)*10)+1
        num2=INT(RND(0)*10)+1
        oper=INT(RND(0)*4)+1
        calc$=num1; oper$(oper) ;num2
        loop until eval(calc$) = int(eval(calc$))

        PRINT #1.tb3, ""
        PRINT #1.st3, calc$;" = "
        PRINT #1.tb3, "!setfocus"
        WAIT

        [check]
        PRINT #1.tb3, "!contents? ans"
        'after typing the ans, to press Enter on the keyboard
        IF ans <> eval(calc$) THEN
        gosub [incorrect]
        else
        corr=corr+1
        end if

        'display the current score
        #1.corr corr
        #1.qnr qnr
        if qnr<10 then [again]

        'finaly notify the user of the end
        #1.tb3 "!hide"
        #1.default "!disable"
        #1.st3 "Finished..."
        wait

        [quit]
        CLOSE #1
        END

        [incorrect]
        #1.gb "delsegment wrong"
        #1.gb "place 1 30"
        PRINT #1.gb, "\X"

        'pause that will be equal length on all computers
        'wait one second
        timer 1000, [PauseEnd]
        wait
        [PauseEnd]
        timer 0
        'end pause code

        PRINT #1.gb, "fill buttonface"
        #1.gb "flush wrong"
        return
        '---code end

        ---
        Stefan Pendl
      • Michael Gallup
        wow! I was away for months and was blown away by the input from all these people 833 of them. I now will work on a program generator for liberty basic.. ...
        Message 3 of 5 , Sep 19, 2008
        • 0 Attachment
          wow! I was away for months and was blown away by the input from all these people 833 of them. I now will work on a program generator for liberty basic..

          --- On Wed, 9/3/08, Stefan Pendl <pendl2megabit@...> wrote:

          From: Stefan Pendl <pendl2megabit@...>
          Subject: RE: [libertybasic] MyFirst-mike
          To: libertybasic@yahoogroups.com
          Received: Wednesday, September 3, 2008, 6:55 AM






          >
          > Hi SL,Thanks for the correction to the counting, eliminating
          > GOTOs completely, and the tip on 'Eval'. Most of all, on how
          > to display colored text.BL had already taught me on using the
          > 'Enter' key. Thanks, anyway.I prefer showing the results on
          > the window itself, rather than on (yet) another window, in
          > this case, the notice box.1) Can we completely clear the main
          > window, and show the results thereon?   
          > 2) So that, probably using smaller fonts, I can add in some
          > comments/message? 3) Once the test is completed, how to exit
          > completely out of LB? (ie: without the need to manually close
          > the console window and code window)Thank you.

          There is still one GOTO included, that is the only one needed.
          Blow find some hints in the example.
          To create a standalone application, use the "Create Application" menu entry in the Run menu.
          You should still read the help file topic on this menu entry to get the whole concept.

          '---code start (watch for line wraps)
          oper$(1) = " + "
          oper$(2) = " - "
          oper$(3) = " * "
          oper$(4) = " / "

          'preset the value to keep EVAL() from failing on the first run
          calc$= "0"

          NOMAINWIN

          WindowWidth= 300
          WindowHeight= 200
          UpperLeftX=INT( (DisplayWidth- WindowWidth) /2)
          UpperLeftY=INT( (DisplayHeight- WindowHeight) /2)

          stylebits #1.st3, _SS_RIGHT, 0, 0, 0
          STATICTEXT #1.st3, "Begin...", 20, 20, 180, 40

          'create a right justified textbox
          stylebits #1.tb3, _ES_RIGHT, 0, 0, 0
          TEXTBOX #1.tb3, 200, 20, 50, 40

          'create a borderless graphicbox to get colored text
          stylebits #1.gb, 0, _WS_BORDER, 0, 0
          graphicbox #1.gb, 250, 20, 40, 40

          'create an invisible default button to trap the ENTER key
          'works with dialog windows only
          button #1.default "", [check], ul, 1, 1, 1, 1

          statictext #1.tx1, "Your Score is", 20, 80, 210, 30
          statictext #1.tx2, "out of", 20, 110, 210, 30

          'create right justified statictext
          stylebits #1.corr, _SS_RIGHT, 0, 0, 0
          statictext #1.corr, "", 230, 80, 50, 30
          stylebits #1.qnr, _SS_RIGHT, 0, 0, 0
          statictext #1.qnr, "", 230, 110, 50, 30

          OPEN "Practice" FOR dialog AS #1
          PRINT #1, "trapclose [quit]"
          PRINT #1, "FONT courier_new 20 bold"

          'set up graphicbox
          #1.gb "font arial 25 bold"
          #1.gb "down"
          #1.gb "color red"
          #1.gb "backcolor buttonface"
          #1.gb "fill buttonface"
          #1.gb "flush wrong"

          [again]
          qnr=qnr+1

          'loop until the result is an integer
          do
          num1=INT(RND( 0)*10)+1
          num2=INT(RND( 0)*10)+1
          oper=INT(RND( 0)*4)+1
          calc$=num1; oper$(oper) ;num2
          loop until eval(calc$) = int(eval(calc$ ))

          PRINT #1.tb3, ""
          PRINT #1.st3, calc$;" = "
          PRINT #1.tb3, "!setfocus"
          WAIT

          [check]
          PRINT #1.tb3, "!contents? ans"
          'after typing the ans, to press Enter on the keyboard
          IF ans <> eval(calc$) THEN
          gosub [incorrect]
          else
          corr=corr+1
          end if

          'display the current score
          #1.corr corr
          #1.qnr qnr
          if qnr<10 then [again]

          'finaly notify the user of the end
          #1.tb3 "!hide"
          #1.default "!disable"
          #1.st3 "Finished... "
          wait

          [quit]
          CLOSE #1
          END

          [incorrect]
          #1.gb "delsegment wrong"
          #1.gb "place 1 30"
          PRINT #1.gb, "\X"

          'pause that will be equal length on all computers
          'wait one second
          timer 1000, [PauseEnd]
          wait
          [PauseEnd]
          timer 0
          'end pause code

          PRINT #1.gb, "fill buttonface"
          #1.gb "flush wrong"
          return
          '---code end

          ---
          Stefan Pendl
















          __________________________________________________________________
          Connect with friends from any web browser - no download required. Try the new Yahoo! Canada Messenger for the Web BETA at http://ca.messenger..yahoo.com/webmessengerpromo.php

          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.