locked
I need HelpGraphicsWindow.Height = 500GraphicsWindow.Height = 500GraphicsWindow.Height = 500 RRS feed

  • Question

  • GraphicsWindow.Height = 500
    GraphicsWindow.Width = 500
    GraphicsWindow.BackgroundColor = "Green"
    Menu:
    GraphicsWindow.BrushColor = "Red"
    Exit = Controls.AddButton("Exit" , 220, 40)
    GraphicsWindow.BrushColor = "Blue"
    Note = Controls.AddButton("Notepad" , 250, 10)
    GraphicsWindow.BrushColor = "Purple"
    Def = Controls.AddButton("Dictionary" , 150, 10)
    i = Controls.LastClickedButton 
      Controls.ButtonClicked = OnButtonClicked
    Sub OnButtonClicked
       IF Controls.LastClickedButton = Getdef Then
         i = Controls.GetTextBoxText(Defword)
          x = Dictionary.GetDefinition(i)
          Controls.SetTextBoxText(Definition,x)
           Endif
           
           If Controls.LastClickedButton = Def Then 
             GraphicsWindow.Clear()
             GraphicsWindow.BrushColor = "green"
             options = Controls.AddButton("Options",500,10)
             GraphicsWindow.Width = 1100
             GraphicsWindow.Height = 700
             Getdef = Controls.AddButton("Find Definition",270,100)
             Defword = Controls.AddTextBox(100,100)
             Definition = Controls.AddMultiLineTextBox(100,200)
             Controls.SetSize(Definition, 400, 400)
           EndIf
         EndSub
         If Controls.LastClickedButton = options Then 
           GraphicsWindow.Clear()
           GraphicsWindow.Show()
           GraphicsWindow.Height = 500
    GraphicsWindow.Width = 500
    GraphicsWindow.BackgroundColor = "Green"
    GraphicsWindow.BrushColor = "Red"
    Exit = Controls.AddButton("Exit" , 220, 40)
    GraphicsWindow.BrushColor = "Blue"
    Note = Controls.AddButton("Notepad" , 250, 10)
    GraphicsWindow.BrushColor = "Purple"
    Def = Controls.AddButton("Dictionary" , 150, 10)
    EndIf
    Sub Exit
    If Controls.LastClickedButton = Exit Then
      Program.End()
    EndIf
      EndSub

    Whats wrong with the end Button it won't Close and why is this
    Tuesday, March 20, 2012 1:19 AM

Answers

  • Hello again, CodingCrazy!

    I guess you need a bit more explanation about what happens when a triggered event is raised.
    When a program is executed on MS Small Basic, an instance is created for it.
    And every time a triggered event occurs, an extra instance is created as well, and they run alongside the main one!
    And this situation can create many sorts of anomalies, like more than one instance tries to manipulate the same variable at the same time for example.
    So it is very advisable to leave triggered event subs to just a minimal of code; mostly capture and register the last button, mouse or key pressed.
    Of course you can make triggered subs do more things, but make them be quick ones as not to cause any crazy bugs :D

    Wednesday, March 21, 2012 12:41 AM
    Answerer
  • So what would be a better course of action? Besides assigning a variable to store the event triggered inside the triggered event sub, is creating a "wait-loop" every time you need an input from the user, but this one inside the main instance!
    Let's call our triggered sub as OnButtonClicked like this:

    Sub OnButtonClicked
      Button= Controls.LastClickedButton
    EndSub

    Let's say you need to know if the Def button was clicked in a particular place inside your code:

    Controls.ButtonClicked= OnButtonClicked
    
    WaitLoop:
    
    If Button = Def Then
      Button= ""
      WordDefinition()
    EndIf
    
    Program.Delay(100)
    
    Goto WaitLoop

    It means the program's gonna wait inside that loop until the user clicks on the button "Def" at the screen!
    Loop keeps on checking the variable 'Button' indefinitely, but the Sub responsible to change the 'Button' variable is OnButtonClicked, which happens everytime a user clicks on any button which happens to be at the GraphicsWindow.
    In our example, the only button which would kick in is the "Def" one. Once it does, we erase 'Button' w/ = "", and we finally call upon a specific Subroutine to deal w/ that: WordDefinition().

    Wednesday, March 21, 2012 12:48 AM
    Answerer
  • As you can see, the whole process is not that difficult to grasp.
    Below is the code I've adapted from yours applying the things I've just taught you. I wish you try to fully understand it. Be happy:

    '================================================'
    ' Notepad & Dictionary '
    '================================================'
    
    InitScreen()
    CreateButtons()
    Controls.ButtonClicked= OnButtonClicked
    
    '================================================'
    ' Sitting-Duck Waiting-Loop: '
    '================================================'
    WaitLoop:
    
    If Button = Exit Then
      Sound.PlayChimeAndWait()
      Program.End()
    EndIf
    
    If Button = Note Then
      Button= ""
      Sound.PlayChimesAndWait()
    EndIf
    
    If Button = Def Then
      Button= ""
      WordDefinition()
    EndIf
    
    Program.Delay(100)
    
    Goto WaitLoop
    '================================================'
    
    '----------------------------------------------------------------------------------'
    Sub OnButtonClicked
      
      Button= Controls.LastClickedButton
      Sound.PlayClick()
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub InitScreen
      
      GraphicsWindow.Clear()
      GraphicsWindow.Width=  500
      GraphicsWindow.Height= 500
      GraphicsWindow.BackgroundColor= "Green"
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub CreateButtons
      
      GraphicsWindow.BrushColor= "Red"
      Exit= Controls.AddButton("Exit"       220,40)
      GraphicsWindow.BrushColor= "Blue"
      Note= Controls.AddButton("Notepad"    250,10)
      GraphicsWindow.BrushColor= "Purple"
      Def=  Controls.AddButton("Dictionary" 150,10)
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub CreateDicButtons
      
      GraphicsWindow.BrushColor= "Green"
      Options= Controls.AddButton("Options"          500, 10)
      GetDef=  Controls.AddButton("Find Definition"  270,100)
      GraphicsWindow.BrushColor= "Red"
      Back=    Controls.AddButton("Back"              10, 10)
      GraphicsWindow.BrushColor= "Blue"
      Defword= Controls.AddTextBox(100,100)
      Definition= Controls.AddMultiLineTextBox(100,200)
      Controls.SetSize(Definition  400,400)
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub WordDefinition
      
      GraphicsWindow.Clear()
      GraphicsWindow.Width=  1100
      GraphicsWindow.Height= 700
      
      CreateDicButtons()
      
      '=============================================='
      ' Dicitonary Sitting-Duck Waiting-Loop: '
      '=============================================='
      
      While Button <> Back    
        If Button = GetDef Then
          Button= ""
          Typed= Controls.GetTextBoxText (Defword)
          Word=  Dictionary.GetDefinition(Typed)
          Controls.SetTextBoxText(Definition Word)
        EndIf
        Program.Delay(100)    
      EndWhile
      '=============================================='
      
      InitScreen()
      CreateButtons()
      
    EndSub
    '----------------------------------------------------------------------------------'

    Wednesday, March 21, 2012 12:52 AM
    Answerer

All replies

  • What you want to do is this? FZV557-0

    Post your sample source code here and get featured on our blogs! (Part IV)*Function......
    Flickr(gets a photo ) ,  Dictionary(meaning), Graphics drawing(mouse, polygon), Sound (playMML, file,chime....), Show Files (Text, photo), File explorer(Makedirectory,Deldirectory,Save as,delfile,Readline,insertline...)

      An easy dictionary..... PDS316    
    Tuesday, March 20, 2012 2:22 AM
    Answerer
  • I don't understand and btw I can't test your code on the website because the
    Tuesday, March 20, 2012 2:57 AM
  • Hello again, CodingCrazy!

    I guess you need a bit more explanation about what happens when a triggered event is raised.
    When a program is executed on MS Small Basic, an instance is created for it.
    And every time a triggered event occurs, an extra instance is created as well, and they run alongside the main one!
    And this situation can create many sorts of anomalies, like more than one instance tries to manipulate the same variable at the same time for example.
    So it is very advisable to leave triggered event subs to just a minimal of code; mostly capture and register the last button, mouse or key pressed.
    Of course you can make triggered subs do more things, but make them be quick ones as not to cause any crazy bugs :D

    Wednesday, March 21, 2012 12:41 AM
    Answerer
  • So what would be a better course of action? Besides assigning a variable to store the event triggered inside the triggered event sub, is creating a "wait-loop" every time you need an input from the user, but this one inside the main instance!
    Let's call our triggered sub as OnButtonClicked like this:

    Sub OnButtonClicked
      Button= Controls.LastClickedButton
    EndSub

    Let's say you need to know if the Def button was clicked in a particular place inside your code:

    Controls.ButtonClicked= OnButtonClicked
    
    WaitLoop:
    
    If Button = Def Then
      Button= ""
      WordDefinition()
    EndIf
    
    Program.Delay(100)
    
    Goto WaitLoop

    It means the program's gonna wait inside that loop until the user clicks on the button "Def" at the screen!
    Loop keeps on checking the variable 'Button' indefinitely, but the Sub responsible to change the 'Button' variable is OnButtonClicked, which happens everytime a user clicks on any button which happens to be at the GraphicsWindow.
    In our example, the only button which would kick in is the "Def" one. Once it does, we erase 'Button' w/ = "", and we finally call upon a specific Subroutine to deal w/ that: WordDefinition().

    Wednesday, March 21, 2012 12:48 AM
    Answerer
  • As you can see, the whole process is not that difficult to grasp.
    Below is the code I've adapted from yours applying the things I've just taught you. I wish you try to fully understand it. Be happy:

    '================================================'
    ' Notepad & Dictionary '
    '================================================'
    
    InitScreen()
    CreateButtons()
    Controls.ButtonClicked= OnButtonClicked
    
    '================================================'
    ' Sitting-Duck Waiting-Loop: '
    '================================================'
    WaitLoop:
    
    If Button = Exit Then
      Sound.PlayChimeAndWait()
      Program.End()
    EndIf
    
    If Button = Note Then
      Button= ""
      Sound.PlayChimesAndWait()
    EndIf
    
    If Button = Def Then
      Button= ""
      WordDefinition()
    EndIf
    
    Program.Delay(100)
    
    Goto WaitLoop
    '================================================'
    
    '----------------------------------------------------------------------------------'
    Sub OnButtonClicked
      
      Button= Controls.LastClickedButton
      Sound.PlayClick()
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub InitScreen
      
      GraphicsWindow.Clear()
      GraphicsWindow.Width=  500
      GraphicsWindow.Height= 500
      GraphicsWindow.BackgroundColor= "Green"
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub CreateButtons
      
      GraphicsWindow.BrushColor= "Red"
      Exit= Controls.AddButton("Exit"       220,40)
      GraphicsWindow.BrushColor= "Blue"
      Note= Controls.AddButton("Notepad"    250,10)
      GraphicsWindow.BrushColor= "Purple"
      Def=  Controls.AddButton("Dictionary" 150,10)
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub CreateDicButtons
      
      GraphicsWindow.BrushColor= "Green"
      Options= Controls.AddButton("Options"          500, 10)
      GetDef=  Controls.AddButton("Find Definition"  270,100)
      GraphicsWindow.BrushColor= "Red"
      Back=    Controls.AddButton("Back"              10, 10)
      GraphicsWindow.BrushColor= "Blue"
      Defword= Controls.AddTextBox(100,100)
      Definition= Controls.AddMultiLineTextBox(100,200)
      Controls.SetSize(Definition  400,400)
      
    EndSub
    '----------------------------------------------------------------------------------'
    Sub WordDefinition
      
      GraphicsWindow.Clear()
      GraphicsWindow.Width=  1100
      GraphicsWindow.Height= 700
      
      CreateDicButtons()
      
      '=============================================='
      ' Dicitonary Sitting-Duck Waiting-Loop: '
      '=============================================='
      
      While Button <> Back    
        If Button = GetDef Then
          Button= ""
          Typed= Controls.GetTextBoxText (Defword)
          Word=  Dictionary.GetDefinition(Typed)
          Controls.SetTextBoxText(Definition Word)
        EndIf
        Program.Delay(100)    
      EndWhile
      '=============================================='
      
      InitScreen()
      CreateButtons()
      
    EndSub
    '----------------------------------------------------------------------------------'

    Wednesday, March 21, 2012 12:52 AM
    Answerer