none
Problem with curriculum 3.4! RRS feed

  • Question

  •  Hello all,

    I finished the whole lesson, then got to the final part, where it gives you a "test". I tried to make it not using the solution, but I couldn't, and copied it anyway. But, once I finished, and looked over my code, when I ran it it didn't do too much! only two buttons worked. I am going to go over it again later (and try something completely different) but I could use some help to get started off in the right direction.

    If you need the code and program, I uploaded it here.

    In advance, i thank anyone who can help, or tries to help. :) thanks!


    I am a 12 year old learning how to code using small basic.

    Thursday, May 23, 2013 3:36 AM

Answers

  • Hi 8bit

    This is the exact same program I had trouble with. I found the code hard to follow. It's listed in this months monthly challenge:

    Community Suggestion 3

    (1) Curriculum Challenge 3.4 Events and Interactivity.

    I ended up abandoning the sample code and just doing it myself. But I still would like to get my head around the way it was done in the curriculum.


    You have to have a dream so you can get up in the morning. - Billy Wilder


    Thursday, May 23, 2013 8:40 AM
    Moderator
  • 8bit, i'm going to start doing this program now, it might take me a day or 2 because I've got other things I need to do. But i'll post my progress here, it may be helpful. If not pls ignore.

    My approach at this point, break it up into clear steps:

    1. using the GraphicsWindow object create the window and rectangular borders, but not the buttons or shapes.
    2. add the buttons and set their size and location.
    3. add 1 button click event and assign a subroutine to it. e.g. Controls.ButtonClicked = ButtonClicked. Nothing else at this point.
    4. then create the shapes, triangle, square and circle. And hide them.
    5. when you click on the buttons show the related shape inside the viewing pane.

    6 & 7 Show, rotate & move. Also clear and Exit.

       8. then create a separate program using the same GraphicsWindow settings to code and test the Draw Button routine. This will use the MouseDown and MouseMove events to draw a freestyle line within the display border (this is a bit tricky, try or check out the code in the curriculum). Use IF condition to prevent the line being drawn outside the viewing pane. Then copy this into the main program and wire these events to its lastbutton clicked "Draw" routine.

    Hope that gets you started in the right direction.

    Then Step 9 is my solution. Easier to follow I reckon. Here's the sample NZN745


    You have to have a dream so you can get up in the morning. - Billy Wilder






    Friday, May 24, 2013 1:00 AM
    Moderator
  • Yes...:))  HAPPY DAYS

    Step 9 for me was to have dinner and chill out. Come back to it the next morning and solved.

    I put the settings for drawing the GUI in a sub, then was able to use GraphicsWindow.Clear in the ButtonClicked routine followed by calling the GUI() routine.

    Here's the code, it MUCH EASIER to follow then the curriculum sample I reckon. Have look 8Bit, it's not too hard to follow. It took me 3 goes after 4 months of Small Basic to say to myself "that I could nail that one." 

    NZN745

    There's less code in this sample as well. You could even get rid of HideShapes() routine and replace it with GW.Clear followed by calling the GUI() sub.

    There's always some logical reason why something doesn't work the way we want it to. Just takes a bit of time and a few re attempts. I did this one 2 months ago and abandoned it, but I came back and chipped away step by step and got it solved.


    You have to have a dream so you can get up in the morning. - Billy Wilder



    Friday, May 24, 2013 9:07 PM
    Moderator

All replies

  • Hi 8bit

    This is the exact same program I had trouble with. I found the code hard to follow. It's listed in this months monthly challenge:

    Community Suggestion 3

    (1) Curriculum Challenge 3.4 Events and Interactivity.

    I ended up abandoning the sample code and just doing it myself. But I still would like to get my head around the way it was done in the curriculum.


    You have to have a dream so you can get up in the morning. - Billy Wilder


    Thursday, May 23, 2013 8:40 AM
    Moderator
  • 8bit, i'm going to start doing this program now, it might take me a day or 2 because I've got other things I need to do. But i'll post my progress here, it may be helpful. If not pls ignore.

    My approach at this point, break it up into clear steps:

    1. using the GraphicsWindow object create the window and rectangular borders, but not the buttons or shapes.
    2. add the buttons and set their size and location.
    3. add 1 button click event and assign a subroutine to it. e.g. Controls.ButtonClicked = ButtonClicked. Nothing else at this point.
    4. then create the shapes, triangle, square and circle. And hide them.
    5. when you click on the buttons show the related shape inside the viewing pane.

    6 & 7 Show, rotate & move. Also clear and Exit.

       8. then create a separate program using the same GraphicsWindow settings to code and test the Draw Button routine. This will use the MouseDown and MouseMove events to draw a freestyle line within the display border (this is a bit tricky, try or check out the code in the curriculum). Use IF condition to prevent the line being drawn outside the viewing pane. Then copy this into the main program and wire these events to its lastbutton clicked "Draw" routine.

    Hope that gets you started in the right direction.

    Then Step 9 is my solution. Easier to follow I reckon. Here's the sample NZN745


    You have to have a dream so you can get up in the morning. - Billy Wilder






    Friday, May 24, 2013 1:00 AM
    Moderator
  • Hi 8bit

    Your program(RBV666) is almost OK.  Only X,Y values are  wrong.

    For example;

       rectangle = Controls.AddButton("Rectangle",25,385)
       Controls.SetSize(rectangle,100,28)

     Line 31...If x > 40 And x < 160 Then  are  wrong values.

     If X>25 and X<125 then     are right.

       ' 25(Left)+100(width)=125

    PLZ see RBV666-0

    *Note: This  curriculum 3.4 is confusing for beginners.(I think)

    Because , Controlbuttons are used to add shapes or actions.

    But controls.clicked actions are graphicswindow mouse actions.

    Why not use Controls.LastClickedButton or controls.GetButtonCaption?

    Friday, May 24, 2013 2:07 AM
    Answerer
  •  I have successfully completed 1-3. i will work on the other ones now. thanks! and i don't mind you putting your progress here. :3 it will probably help me out.
    If the username of who worte this isn't "8BiT", i have no idea why. i wrote that. :/ could be some random bug...

    I am a 12 year old learning how to code using small basic.

    Friday, May 24, 2013 2:21 AM
  • Step 1: ZQT230

    Step 2: BQD248


    You have to have a dream so you can get up in the morning. - Billy Wilder


    Friday, May 24, 2013 3:14 AM
    Moderator
  • Steps 5, 6 & 7. TCX597

    Now all I have to do is Step 8. Which I'll code and test in a separate program first. So the only part left to do is the Draw routine.


    You have to have a dream so you can get up in the morning. - Billy Wilder


    Friday, May 24, 2013 10:23 AM
    Moderator
  • Tried to do this way but get totally stuck at clearing the line draw with GraphicsWindows.Clear

    I can't loop back to the start or even a Goto. Any ideas?

    Now Solved in this thread. new sample given.


    You have to have a dream so you can get up in the morning. - Billy Wilder


    Friday, May 24, 2013 1:36 PM
    Moderator
  • LFC592

    Tried to do this way but get totally stuck at clearing the line draw with GraphicsWindows.Clear

        Use graphicswindow.fillrectangle with brushcolor="white"
    Friday, May 24, 2013 1:56 PM
    Answerer
  • LFC592

    I can't loop back to the start or even a Goto. Any ideas?



    When do you want to loop back to the start? After pressing "Clear" ?

    Jan [ WhTurner ] The Netherlands


    Friday, May 24, 2013 2:31 PM
    Answerer
  •   Hello 8BiT

     I´ve made copy/ paste frommy Curriculum (Spanish) and it works very well

    The program RBV666 don´t work so

     Regards


    carlosfmur - Buenos Aires

    Friday, May 24, 2013 7:25 PM
  • Yes...:))  HAPPY DAYS

    Step 9 for me was to have dinner and chill out. Come back to it the next morning and solved.

    I put the settings for drawing the GUI in a sub, then was able to use GraphicsWindow.Clear in the ButtonClicked routine followed by calling the GUI() routine.

    Here's the code, it MUCH EASIER to follow then the curriculum sample I reckon. Have look 8Bit, it's not too hard to follow. It took me 3 goes after 4 months of Small Basic to say to myself "that I could nail that one." 

    NZN745

    There's less code in this sample as well. You could even get rid of HideShapes() routine and replace it with GW.Clear followed by calling the GUI() sub.

    There's always some logical reason why something doesn't work the way we want it to. Just takes a bit of time and a few re attempts. I did this one 2 months ago and abandoned it, but I came back and chipped away step by step and got it solved.


    You have to have a dream so you can get up in the morning. - Billy Wilder



    Friday, May 24, 2013 9:07 PM
    Moderator
  • Thanks NaochanON

    I remember that trick, you helped me out before with that. Very handy. Anyway I ended clearing the GW, the solution was obvious to me when I woke up this morning.


    You have to have a dream so you can get up in the morning. - Billy Wilder

    Friday, May 24, 2013 9:45 PM
    Moderator
  • Hi Jan

    Try with this, if you please

    Regards

    ..........................................................................................................................................................

    GraphicsWindow.Hide()
    ancho = 620
    alto = 450
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.Width = ancho
    GraphicsWindow.Height = alto
    GraphicsWindow.Top = (Desktop.Height-alto) / 2
    GraphicsWindow.Left = (Desktop.Width-ancho) / 2
    GraphicsWindow.Show()
    GraphicsWindow.Title = "Eventos e interactividad"
    InterfazUsuario()
    Controls.ButtonClicked = AcciónMouse
    Sub InterfazUsuario 
      GraphicsWindow.DrawRectangle(10, 10, 600, 320)
      GraphicsWindow.DrawRectangle(10, 340, 200, 100)
      GraphicsWindow.DrawRectangle(10, 340, 600, 100)
      GraphicsWindow.DrawRectangle(370, 340, 150, 100)  
      Triángulo = Controls.AddButton("Triángulo", 40, 345)
      Controls.SetSize(Triángulo, 120, 30)
      Rectángulo = Controls.AddButton("Rectángulo",40,375)
      Controls.SetSize(Rectángulo, 120, 30)
      Círculo = Controls.AddButton("Círculo", 40, 405)
      Controls.SetSize(Círculo, 120, 30)
      Rotar = Controls.AddButton("Rotar", 230, 360)
      Controls.SetSize(Rotar, 60, 60)
      Zoom = Controls.AddButton("Zoom", 290, 360)
      Controls.SetSize(Zoom, 60, 60)
      FreeHand = Controls.AddButton("Dibujar", 390, 360)
      Controls.SetSize(FreeHand, 60, 60)  
      Borrar = Controls.AddButton("Borrar", 450, 360)
      Controls.SetSize(Borrar, 60, 60)
      Salir = Controls.AddButton("Salir", 530, 360)
      Controls.SetSize(Salir, 60, 60)    
    EndSub
    Sub AcciónMouse
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY  
      GraphicsWindow.PenWidth = 1 
      If x > 40 And x < 160 Then    
        GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor() 
        If y > 345 And y < 375 Then       
          dibujar = 0
          j = 0
          z = 1
          tri = Shapes.AddTriangle(20, 20, 100, 100, 150, 20)
          Shapes.Move(tri, 80, 100)
        EndIf  
        If y > 375 And y < 405 Then
          dibujar = 0     
          j = 0 
          z = 2  
          rect = Shapes.AddRectangle(100, 100)
          Shapes.Move(rect, 250, 150)
        EndIf    
        If y > 405 And y < 435 Then
          dibujar = 0
          j = 0      
          z = 3      
          circ = Shapes.AddEllipse(100, 100)
          Shapes.Move(circ, 400, 150)
        EndIf      
      EndIf    
      If y > 360 And y < 420 Then       
        If x > 230 And x < 290 Then          
          dibujar = 0   
          If z = 1 Then        
            Shapes.Rotate(tri, 30 + m)
          Else
            If z = 2 Then     
              Shapes.Rotate(rect,30 + m)  
            Else
              If z = 3 Then     
                Shapes.Rotate(circ, 30 + m)    
              Endif           
            Endif 
          Endif
          m = m + 30             
        EndIf      
        If x > 290 And x < 390 Then
          dibujar = 0         
          i = 0.1 + j
          If i < 0.4 Then  
            If z = 1 Then        
              Shapes.Zoom(tri, 1 + i, 1 + i)
            Else
              If z = 2 Then     
                Shapes.Zoom(rect, 1 + i, 1 + i)
              Else
                If z = 3 Then     
                  Shapes.Zoom(circ, 1 + i, 1 + i)      
                EndIf    
              EndIf 
            EndIf     
            j = j + 0.1
          EndIf
        EndIf         
        If x > 390 And x < 450 Then
          dibujar = 1
          Paint()
        EndIf     
        If x > 450 And x < 510 Then
          dibujar = 0
          j = 0
          GraphicsWindow.Clear()   
          GraphicsWindow.BrushColor = "Blue"
          InterfazUsuario()
          dibujar = 0
        EndIf     
        If x > 530 And x < 590 Then
          dibujar = 0
          Program.End()
        EndIf     
      EndIf     
    EndSub
    Sub Paint
      If dibujar = 1 Then    
        GraphicsWindow.MouseMove = ArrastrarMouse         
      Else
        If Mouse.IsLeftButtonDown Then    
          AcciónMouse()   
        EndIf
      EndIf    
    EndSub

    Sub ArrastrarMouse
      If dibujar = 1 then 
        x = GraphicsWindow.MouseX
        y = GraphicsWindow.MouseY   
        If x > 10 And x < 600 And y > 10 And y < 320 Then   
          If Mouse.IsLeftButtonDown Then
            GraphicsWindow.DrawLine(OrgX, OrgY, x, y)
          EndIf    
        EndIf 
        OrgX = x
        OrgY = y
      EndIf
    EndSub


    carlosfmur - Buenos Aires

    Friday, May 24, 2013 9:58 PM
  • That works very well! Thank you all for the help. I'll use your code and study it, so i can make my own version. Thanks again everyone!

    I am a 12 year old learning how to code using small basic.

    Friday, May 24, 2013 11:33 PM
  • No worries. I had to do it anyway. Good practice = better coding

    You have to have a dream so you can get up in the morning. - Billy Wilder


    Tuesday, May 28, 2013 9:27 AM
    Moderator
  • Hello all,  I made all shapes version for curriculum 3.4.

    PLZ refer.

    http://smallbasic.com/smallbasic.com/program/?FBH659


    Wednesday, May 29, 2013 8:13 AM
    Answerer
  • Hey NaochanON

    Thanks. Like the no buttons and love how you clear the draw line.

    Btw, i'm still experimenting with the POS challenge. Your approach was very practical. I'm looking at using txt files to store menu items and bill calculations. I figure this way I could then create a user input interface that allows the user to change and add menu items, and also remove items off the bill if the console operator made a mistake. Also record bill and cash receipts to file thereby setting up a cash journal.

    I'm going to work on the POS for a couple of months and try out different methods, i'll start a discussion next month.

    Sorry 8bit for cloud-bombing your thread, but you might be interested as well.


    You have to have a dream so you can get up in the morning. - Billy Wilder


    Thursday, May 30, 2013 9:40 PM
    Moderator
  • It's alright. ^^

    I am a 12 year old learning how to code using small basic.

    Friday, May 31, 2013 5:02 PM