none
dumb question? RRS feed

  • Question

  • I clicked the "Graduate" button @ the top of Small Basic just to see what would happen.  Now I have VB2010 express. Does this mean that I can't use Small Basic anymore? The reason I'm asking is that I'm trying new things in SB. I have a "GraphicsWindow.MouseDown = OnMouseDown" line of code and the program doesn't seem to do anything when I click the mouse??!? Any ideas what's going on?  Any help would be much appreciated! Thanks

    Well, I feel a whole heck of a lot more like I do now than I did a little while ago!!?!

    Wednesday, June 6, 2012 8:13 PM

Answers

  • The Graduate converts SmallBasic programs to VisualBasic (VB2010) to help you move beyond SmallBasic.  All SmallBasic files do not convert perfectly, but it is a pretty good start to get you going with VB.  There may also be some setup required using VB2010 (referencing .Net 3.5 rather than .Net 4.0) but these need not concern you unless you actually want the VisualBasic graduated conversion and start learning VB.

    Anyhow, it absolutely should not stop you using SmallBasic in any way.

    Try loading a SmallBasic program that you know works, I suspect the problem is actually with the code you have written not behaving as expected.

    Therefore post the code that isn't working to get some help with it.

    • Marked as answer by Namyegob Thursday, June 7, 2012 5:13 PM
    Wednesday, June 6, 2012 8:33 PM
    Moderator

All replies

  • The Graduate converts SmallBasic programs to VisualBasic (VB2010) to help you move beyond SmallBasic.  All SmallBasic files do not convert perfectly, but it is a pretty good start to get you going with VB.  There may also be some setup required using VB2010 (referencing .Net 3.5 rather than .Net 4.0) but these need not concern you unless you actually want the VisualBasic graduated conversion and start learning VB.

    Anyhow, it absolutely should not stop you using SmallBasic in any way.

    Try loading a SmallBasic program that you know works, I suspect the problem is actually with the code you have written not behaving as expected.

    Therefore post the code that isn't working to get some help with it.

    • Marked as answer by Namyegob Thursday, June 7, 2012 5:13 PM
    Wednesday, June 6, 2012 8:33 PM
    Moderator
  • Thank you Lit! here it is...

    GraphicsWindow.Top = 138
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.Title = "Texas Lottery"
    GraphicsWindow.BackgroundColor = "DarkBlue"
    GraphicsWindow.BrushColor = "Yellow"
    GraphicsWindow.FontName = "Veranda"
    GraphicsWindow.FontSize = 14
    GraphicsWindow.Width = 640
    GraphicsWindow.Height = 480
    GraphicsWindow.show()
    GraphicsWindow.MouseDown = OnMouseClick
    
    'GraphicsWindow.DrawText(X, Y, "TEXT")
    'RanNum = Math.GetRandomNumber(maxNum) 
    'returns a number between  1 & maxNum (inclusive)
    
    x = Mouse.MouseX
    y = Mouse.MouseY
    
    tag01 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\PowerBall.png"
    tag02 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\MegaMillions.png"
    tag03 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\LottoTexas.png"
    tag04 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\Cash5.png"
    tag05 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\Daily4.png"
    tag06 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\Pick3.png"
    tag07 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\Texas2Step.png"
    tag08 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\EndProgram.png"
    tag09 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\Yes.png"
    tag10 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\No.png"
    tag11 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\No - Copy.png"
    tag12 = "C:\Users\Albert\Programming\Small Basic\Saved Projects\Small Lotto\Images\Yes - Copy.png"
    
    Sub OnMouseClick
      'PowerBall
      'MegaMillions
      'LottoTexas
      'Cash5
      'Daily4
      'Pick3
      'Texas2Step
      'EndProgram
      IF x > 64 AND x < 287 AND y > 364 AND y < 451 THEN
        Goto Start
      ELSEIF x > 351 AND x < 574 AND y > 364 AND y < 451 THEN
        EndProgram()
      ENDIF
    EndSub
    
    Start:
    GraphicsWindow.Clear()
    
    GraphicsWindow.DrawResizedImage(tag01, 64, 31, 223, 87)
    GraphicsWindow.DrawResizedImage(tag02, 351, 31, 223, 87)
    GraphicsWindow.DrawResizedImage(tag03, 64, 142, 223, 87)
    GraphicsWindow.DrawResizedImage(tag04, 351, 142, 223, 87)
    GraphicsWindow.DrawResizedImage(tag05, 64, 253, 223, 87)
    GraphicsWindow.DrawResizedImage(tag06, 351, 253, 223, 87)
    GraphicsWindow.DrawResizedImage(tag07, 64, 364, 223, 87)
    GraphicsWindow.DrawResizedImage(tag08, 351, 364, 223, 87)
    
    Sub PowerBall
      GraphicsWindow.Clear()
      
    EndSub
    
    Sub MegaMillions
      GraphicsWindow.Clear()
      
    EndSub
    
    Sub LottoTexas
      GraphicsWindow.Clear()
      
    EndSub
    
    Sub Cash5
      GraphicsWindow.Clear()
      
    EndSub
    
    Sub Daily4
      GraphicsWindow.Clear()
      
    EndSub
    
    Sub Pick3
      GraphicsWindow.Clear()
      
    EndSub
    
    Sub Texas2Step
      
    EndSub
    
    Sub EndProgram
      GraphicsWindow.Clear()
      GraphicsWindow.DrawText(10, 10, "This is the")
      GraphicsWindow.DrawResizedImage(tag08, 128, 34, 223, 87)
      GraphicsWindow.DrawText(121, 10, "routine.")
      GraphicsWindow.DrawText(340, 10, "Quit!! Really??!?")
      GraphicsWindow.DrawResizedImage(tag11, 64, 364, 223, 87)
      GraphicsWindow.DrawResizedImage(tag12, 351, 364, 223, 87)
      IF x > 64 AND x < 287 AND y > 364 AND y < 451 THEN
        Goto Start
      ELSEIF x > 351 AND x < 574 AND y > 364 AND y < 451 THEN
        Program.End()
      ENDIF
    EndSub

    I have tried moving the OnMouseDown sub around, but that doesn't seem to help.

    Well, I feel a whole heck of a lot more like I do now than I did a little while ago!!?!

    Wednesday, June 6, 2012 8:43 PM
  • Hi,

    Several problems I'm afraid:

    1] Use GraphicsWindow.MouseX rather than Mouse.MouseX (the latter is display coords) and you want the GraphicsWindows coords (the former)

    2] set x and y inside the event sub OnMouseDown since we need to know x and y just when the mouse was clicked

    3] We cannot do a GoTo into or out from a subroutine (destroys the call stack - the program would loose track of what called what)

    The solution for event driven programs is to either:

    1] Call a subroutine when an event occurs - be careful that the event cannot be fired again before it has finished doing the last thing.

    2] Better is have a game loop - an infinite loop that processes events as they occur, based on variables set when the event occurs.

    A simple example of the sort of thing I mean:

    'CREATE SOME BUTTONS
    For i = 1 To 5
      button[i] = Controls.AddButton("Button "+i,50,30*i)
    EndFor

    'START BUTTON PRESS EVENT
    clicked = ""
    Controls.ButtonClicked = OnButtonClicked

    'INFINITE GAME LOOP
    While ("True")
      If (clicked <> "") Then 'Something clicked
        'Do something depending on the button - first find which button it was
        For i = 1 To 5
          If (Controls.LastClickedButton = button[i]) Then
            GraphicsWindow.ShowMessage(i,"Button Clicked")'This button was clicked
          EndIf
        EndFor
        clicked = "" 'Reset waiting for next click
      EndIf
      Program.Delay(20) ' Don't mash cpu when nothing happening
    EndWhile

    'HANDLE BUTTON CLICK EVENT
    Sub OnButtonClicked
      clicked = Controls.LastClickedButton 'Just set a flag for the button clicked we handle in game loop
    EndSub


    Wednesday, June 6, 2012 9:26 PM
    Moderator
  • Well, alrighty then!  I used GraphicsWindow.MouseX (&Y) instead, i set x&y inside the OnMouseClickand that seemed to get the ball rolling! is there a way (instead of having buttons) add a control to the images?

    Well, I feel a whole heck of a lot more like I do now than I did a little while ago!!?!

    Wednesday, June 6, 2012 11:26 PM
  • well, i figured out that i could size the buttons to the size of the image & place the image on top of the button, i don't know if that method is correct or not also this part isn't working...  any suggestions?

    ' INFINITE GAME LOOP
    While ("True")
      If (clicked <> "") Then 'Something clicked
        'Do something depending on the button - first find which button it was
        For i = 1 To 8
          If (Controls.LastClickedButton = button[i]) Then
            Sub(button[i])
          EndIf
        EndFor
        clicked = "" 'Reset waiting for next click
      EndIf
      Program.Delay(20) ' Don't mash cpu when nothing happening
    EndWhile
    

    thanks

    Well, I feel a whole heck of a lot more like I do now than I did a little while ago!!?!

    Thursday, June 7, 2012 3:59 AM
  • Just a tip:

    Since clicked = Controls.LastClickedButton already, why not:

    If clicked = button[i] Then,    instead of  If ( Controls.LastClickedButton = button[i] ) Then???


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, June 7, 2012 8:29 AM
    Answerer
  • GoToLoop,

    Absolutely right - the last buttonclicked could actually have changed so we definitely want to use the clicked variable - my bug.

    Thursday, June 7, 2012 12:03 PM
    Moderator