none
ILGenerator: Bug or not? RRS feed

  • Question

  • Hey guys! :D

    I am back with a new problem. I added a few new codes to my program, but if I want to start it, I get "Inadmissible name in ILGenerator.". But, where is my problem?

    This is, what I added:

    TutorialAB:
    
    'If (letzterButton = Controls.LastClickedButton) Then
    GraphicsWindow.BrushColor = "White"
    GraphicsWindow.PenColor = "Gray"
    GraphicsWindow.FillRectangle(664, 60, 350, 650)
    GraphicsWindow.DrawRectangle(664, 60, 350, 650)
    GraphicsWindow.FontName = "Arial"
    GraphicsWindow.PenColor = "Black"
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawBoundText(674, 60, 340, "Hier werden die Beschreibungen der einzelnen Themen angezeigt.")
    
      'Button
    'BannerTutorial
    GraphicsWindow.BrushColor = "Black"
    'Controls.ButtonClicked = Action7
    BannerButton = Controls.AddButton("Banner",30,40)
    Controls.SetSize(BannerButton,150,30)
    letzterButton6 = Controls.LastClickedButton
    'Action7 = letzterButton7 'Sub Action6 
      If (letzterButton6 = BannerButton) Then
    Goto Bannerfenster
      EndIf
    'EndIf
    
      
      ScriptAB:
      AnleitungPAB:
      AnleitungMAB:
      OptionenAB:
      'SucheAB:
      
      
      
      
      
      
      
      Bannerfenster:
      
       GraphicsWindow.BrushColor = "White"
       GraphicsWindow.PenColor = "Gray"
       GraphicsWindow.FillRectangle(10, 60, 350, 650)
       GraphicsWindow.DrawRectangle(10, 60, 350, 650)
       GraphicsWindow.FontName = "Arial"
       GraphicsWindow.PenColor = "Blue"
       GraphicsWindow.BrushColor = "Blue"
       GraphicsWindow.PenWidth = 15
       GraphicsWindow.DrawBoundText(10, 60, 340, "Tutorial zum erstellen eines Banners:")
       GraphicsWindow.PenColor = "Black"
       GraphicsWindow.BrushColor = "Black"
       GraphicsWindow.PenWidth = 11
      
    ButtonsWiederholung:
    
    
      'Button
    'Thema
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action1111
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
    Sub Action1111
      letzterButton7 = Controls.LastClickedButton
      If letzterButton7 = TutorialButton Then
        Goto TutorialAB
      EndIf
      EndSub
      
    
      'Button
    'Script
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action111
    ScriptButton = Controls.AddButton("Scripts",130,10)
    Controls.SetSize(ScriptButton,100,30)
    Sub Action111
      letzterButton8 = Controls.LastClickedButton
      If letzterButton8 = ScriptButton Then
        Goto ScriptAB
      EndIf
      EndSub
    
    
      'Button
    'Anleitung für andere  Modding Programme
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action222
    AnleitungProgrammButton = Controls.AddButton("Anleitung Modding Programme",250,10)
    Controls.SetSize(AnleitungProgrammButton,100,30)
    Sub Action222
      letzterButton9 = Controls.LastClickedButton
      If letzterButton9 = AnleitungProgrammButton Then
        Goto AnleitungPAB
      EndIf
      EndSub
    
    
      'Button
    'Anleitung Mods
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action333
    AnleitungModsButton = Controls.AddButton("Anleitung Mods",370,10)
    Controls.SetSize(AnleitungModsButton,100,30)
    Sub Action333
      letzterButton11 = Controls.LastClickedButton
      If letzterButton11 = AnleitungModsButton Then
        Goto AnleitungMAB
      EndIf
      EndSub
    
    
      'Button
    'Optionen
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action444
    OptionenButton = Controls.AddButton("Optionen",490,10)
    Controls.SetSize(OptionenButton,100,30)
    Sub Action444
      letzterButton12 = Controls.LastClickedButton
      If letzterButton12 = OptionenButton Then
        Goto OptionenAB
      EndIf
      EndSub
    

    I had this problem a long time ago too, but I can't remember what I did to fix it...

    Greetings

    Timo


    Ich bin Neu

    Sunday, September 9, 2012 4:00 PM

Answers

  • Hello Timo,

    You jump out of a subroutine with a goto. A subroutine should always to run to the end. You can set a variable in the subroutine and after the return, check this variable.


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Sunday, September 9, 2012 4:48 PM
    Answerer
  • If possible try to structure your program with no GoTo's at all.  They are allowed in SmallBasic, but almost all programers never use them (or at least extremely rarely) in any language -  used as the main flow control method they result in code that is hard to read and hard to extend (spaghetti code).

    There is stacks of stuff about GoTo, but here or here is a start as to what the issues are.

    • Edited by litdevModerator Sunday, September 9, 2012 8:37 PM
    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Sunday, September 9, 2012 7:02 PM
    Moderator
  • Here is a code snippet that will generate the error:  Bad label in IL generator.  This makes the error easier to look at and analyze.  Run it this way and you will get the error.  Then move the goto to just past the endsub.  You will see that the program will then run.  So, the general rule is to never jump out of a subroutine with a goto.  What is interesting is when you look at Timo's code it does look like it really should work.

    MySub()
    Sub MySub

        Goto First

      EndSub

    First:

    JR


    JR

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Sunday, September 9, 2012 9:49 PM
    Answerer
  • You need a single button click event subroutine that you check which button is clicked and then call appropriate subroutine for that button.

    Here is how I would start based on your previous code, import WCF463.  Using comments and subroutine to separate functionality, a single button event subroutine that calls different subroutines depending on which was clicked.

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Monday, September 10, 2012 5:22 PM
    Moderator
  • not exactly, you don't call the event subroutine Action111(), it is called for you by the program when a button is clicked (this is what an event subroutine is for).

    The WCF463, is a code to import a SmallBasic source code - from the SmallBAsic interface, hit the import button on the top of the window and enter this or any other code you see given on this forum to import the source code.

    You can also publish your source code and provide the resulting 6 digit code for anyone else to import your source without copying the source (especially long code) into a post.

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Tuesday, September 11, 2012 1:37 PM
    Moderator
  • ok thanks.....

    (So I have to delete this  ()  after  Action111  in my code? My English isn't the best so it is hard for me to understand this.....)

    But there is no German Small Basic forum.....

    I got it! I have program a new button which uses only one Subroutine. Here is it:

    GraphicsWindow.Height = 500
    GraphicsWindow.Width = 500
    GraphicsWindow.Title = "Buttontest"
    
    
    
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
    
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    BannerButton = Controls.AddButton("Tutorials",10,50)
    Controls.SetSize(BannerButton,100,30)
      
      Sub MySub
        
        letzterButton = Controls.LastClickedButton
        
      If letzterButton = TutorialButton Then
        TextWindow.WriteLine("Erfolg!")
        
      ElseIf letzterButton = BannerButton Then
        TextWindow.WriteLine("Erfolg2!")
      EndIf
    EndSub

    Please tell me what you think about it! :D

    And if you find it is ok, would I like to make a kind of OSP out of it. Like you (litdev) wrote it about the WCF463.


    Ich bin Neu


    • Edited by Timo Sö Tuesday, September 11, 2012 2:29 PM More information
    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Tuesday, September 11, 2012 1:51 PM

All replies

  • Hello Timo,

    You jump out of a subroutine with a goto. A subroutine should always to run to the end. You can set a variable in the subroutine and after the return, check this variable.


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Sunday, September 9, 2012 4:48 PM
    Answerer
  • Ah ok thanks. But how can I check a variable after the return?

    I only know, that I can't define a variable with a Goto X .


    Ich bin Neu

    Sunday, September 9, 2012 6:15 PM
  • If possible try to structure your program with no GoTo's at all.  They are allowed in SmallBasic, but almost all programers never use them (or at least extremely rarely) in any language -  used as the main flow control method they result in code that is hard to read and hard to extend (spaghetti code).

    There is stacks of stuff about GoTo, but here or here is a start as to what the issues are.

    • Edited by litdevModerator Sunday, September 9, 2012 8:37 PM
    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Sunday, September 9, 2012 7:02 PM
    Moderator
  • Here is a code snippet that will generate the error:  Bad label in IL generator.  This makes the error easier to look at and analyze.  Run it this way and you will get the error.  Then move the goto to just past the endsub.  You will see that the program will then run.  So, the general rule is to never jump out of a subroutine with a goto.  What is interesting is when you look at Timo's code it does look like it really should work.

    MySub()
    Sub MySub

        Goto First

      EndSub

    First:

    JR


    JR

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Sunday, September 9, 2012 9:49 PM
    Answerer
  • Thanks for this nice answers. :D

    I will look at your links litdev. I hope that they will help me.

    @jricestk

    Iwill try your code. :)


    Ich bin Neu

    Monday, September 10, 2012 10:00 AM
  • Ok.... I tried it. I use now Sub commands instead of Gotos. But how can I use a kind of Sub inside of another Sub?

    This is because my buttons. I need a Sub command for them.....

    This is one of my buttons:

      'Button
    'Thema
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action111
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
    Sub Action111
      letzterButton6 = Controls.LastClickedButton
      If letzterButton6 = TutorialButton Then
        MySub3()
        EndIf
      EndSub
      


    Ich bin Neu

    Monday, September 10, 2012 3:20 PM
  • You need a single button click event subroutine that you check which button is clicked and then call appropriate subroutine for that button.

    Here is how I would start based on your previous code, import WCF463.  Using comments and subroutine to separate functionality, a single button event subroutine that calls different subroutines depending on which was clicked.

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Monday, September 10, 2012 5:22 PM
    Moderator
  • Ah I understand. So it has to look like this (for example):

      'Button
    'Thema
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = Action111
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
    Action111()
      If letzterButton = TutorialButton Then
        MySub3()
        EndIf
      EndSub
    
    Sub Action111
      letzterButton = Controls.LastClickedButton
    EndSub

    right? And what do you mean with "WCF463"?


    Ich bin Neu

    Tuesday, September 11, 2012 1:14 PM
  • not exactly, you don't call the event subroutine Action111(), it is called for you by the program when a button is clicked (this is what an event subroutine is for).

    The WCF463, is a code to import a SmallBasic source code - from the SmallBAsic interface, hit the import button on the top of the window and enter this or any other code you see given on this forum to import the source code.

    You can also publish your source code and provide the resulting 6 digit code for anyone else to import your source without copying the source (especially long code) into a post.

    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Tuesday, September 11, 2012 1:37 PM
    Moderator
  • ok thanks.....

    (So I have to delete this  ()  after  Action111  in my code? My English isn't the best so it is hard for me to understand this.....)

    But there is no German Small Basic forum.....

    I got it! I have program a new button which uses only one Subroutine. Here is it:

    GraphicsWindow.Height = 500
    GraphicsWindow.Width = 500
    GraphicsWindow.Title = "Buttontest"
    
    
    
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
    
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    BannerButton = Controls.AddButton("Tutorials",10,50)
    Controls.SetSize(BannerButton,100,30)
      
      Sub MySub
        
        letzterButton = Controls.LastClickedButton
        
      If letzterButton = TutorialButton Then
        TextWindow.WriteLine("Erfolg!")
        
      ElseIf letzterButton = BannerButton Then
        TextWindow.WriteLine("Erfolg2!")
      EndIf
    EndSub

    Please tell me what you think about it! :D

    And if you find it is ok, would I like to make a kind of OSP out of it. Like you (litdev) wrote it about the WCF463.


    Ich bin Neu


    • Edited by Timo Sö Tuesday, September 11, 2012 2:29 PM More information
    • Marked as answer by Timo Sö Tuesday, September 11, 2012 2:32 PM
    Tuesday, September 11, 2012 1:51 PM
  • Yes, this is right except you only need to do these lines ONCE - no need to repeat them.

    GraphicsWindow.BrushColor = "Black"
    Controls
    .ButtonClicked = MySub

    You can then call any subroutine inside MySub for each button click type.


    Tuesday, September 11, 2012 3:35 PM
    Moderator
  • Ok :D Thanks.

    But here is a new problem again..... But it is little I think.

    I want to clear the window if I press on the button. That's no problem. But then I want, that it jump back to the background part and after this is finished back to the main menu. So I added this to the end of the Sub of this Button:

    y = 0 y2 = y + 1

    EndSub

     If (y = 0) Then
     Goto Hintergruende
     EndIf

    And at the end of the background part have I added this:

    If (y2 = 1) Then
    y2 = y2 - 1
    Goto Buttons2
    EndIf
    Now, I can start the program (with SB) without a problem. But the background will not define.....


    Ich bin Neu

    Tuesday, September 11, 2012 3:41 PM
  • See the program I sent the import code for - I put all of the initial buttons inside a subroutine called initialise - just have a simi;lar subroutine that you call afer a GraphicsWindow.Clear() or even pu the clear as the first statement in this subroutine and call whenever you want to revert to the start.

    Or just remove all the stuff you have added for a particular button when you are done with it.

    Tuesday, September 11, 2012 4:17 PM
    Moderator
  • Ok thanks.

    I copyed the files, but now get I an Error. The variable of the button is not defined. But it is he same like before. And there is all fine.


    Ich bin Neu

    Tuesday, September 11, 2012 6:25 PM
  • Publish the code with the problem and post the 6 digit import code so we can check for a problem - or perhaps search a bit yourself for what you may have changed that would give the error you see.
    Tuesday, September 11, 2012 6:35 PM
    Moderator
  • This is my code:

    Anfang:
    
    'Grundeinstellungen
    GraphicsWindow.Title = "NoobHelper 0.2"
    GraphicsWindow.Height = 769
    GraphicsWindow.Width = 1025
    GraphicsWindow.BackgroundColor = "White"
    
    
    
    GraphicsWindow.ShowMessage("Dies ist momentan noch eine Probeversion von NoobHelper. Daher sind erst wenige Themen enthalten. Bei technischen Mängeln, sendet bitte eine Nachricht an den Taleworlds Forum Nutzer  Roemerboy  . Oder sendet eine E-mail an timo12939@googlemail.com .", "NoobHelper 0.2")
    
    
    
    Hintergruende:
    
    
    'Hintergruende (Tagesabhaengig)
    If (Clock.WeekDay = "Mittwoch") Then
    hintergrund1 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 1.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund1)
    breite = ImageList.GetWidthOfImage(hintergrund1)
    GraphicsWindow.DrawImage(hintergrund1, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Dienstag") Then
    hintergrund2 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 2.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund2)
    breite = ImageList.GetWidthOfImage(hintergrund2)
    GraphicsWindow.DrawImage(hintergrund2, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Donnerstag") Then
    hintergrund3 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 3.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund3)
    breite = ImageList.GetWidthOfImage(hintergrund3)
    GraphicsWindow.DrawImage(hintergrund3, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Montag") Then
    hintergrund4 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 4.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund4)
    breite = ImageList.GetWidthOfImage(hintergrund4)
    GraphicsWindow.DrawImage(hintergrund4, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Samstag") Then
    hintergrund5 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 5.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund5)
    breite = ImageList.GetWidthOfImage(hintergrund5)
    GraphicsWindow.DrawImage(hintergrund5, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Freitag") Then
    hintergrund6 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 6.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund6)
    breite = ImageList.GetWidthOfImage(hintergrund6)
    GraphicsWindow.DrawImage(hintergrund6, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Sonntag") Then
    hintergrund7 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 7.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund7)
    breite = ImageList.GetWidthOfImage(hintergrund7)
    GraphicsWindow.DrawImage(hintergrund7, 0, 0) ' the coords are the top left of the image
    EndIf
    
    
    
    
    
    Buttons2:
    
      'Button
    'Tutorial
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
      
    
      'Button
    'Script
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    ScriptButton = Controls.AddButton("Scripts",130,10)
    Controls.SetSize(ScriptButton,100,30)
    
    
      'Button
    'Anleitung für andere  Modding Programme
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    ProgrammButton = Controls.AddButton("Programme",250,10)
    Controls.SetSize(ProgrammButton,100,30)
    
    
      'Button
    'Anleitung Mods
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    ModButton = Controls.AddButton("Mods",370,10)
    Controls.SetSize(ModButton,100,30)
    
    
      'Button
    'Optionen
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    OptionenButton = Controls.AddButton("Optionen",490,10)
    Controls.SetSize(OptionenButton,100,30)
    
    
    
      'Button
    'Suche
    'GraphicsWindow.BrushColor = "Black"
    'Controls.ButtonClicked = MySub
    'SucheButton = Controls.AddButton("Suche",610,10)
    'Controls.SetSize(SucheButton,100,30)
    
    
    
    
    
    Sub MySub
    
    letzerButton = Controls.LastClickedButton
    
    If (letzerButton = TutorialButton) Then
    
        ButtonsWiederholung:
        
        
    
      'Button
    'Zurueck
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MainMenu
    ZurueckButton = Controls.AddButton("Zurück",10,10)
    Controls.SetSize(ZurueckButton,100,30)
    
    
    
    
    
    TutorialButtons:
    'Hier kommen die einzelnen Tutorial Buttons hin.
    
    
      'Button
    'BannerTutorial
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub1
    BannerButton = Controls.AddButton("Banner",30,40)
    Controls.SetSize(BannerButton,150,30)
    
    GraphicsWindow.BrushColor = "White"
    GraphicsWindow.PenColor = "Gray"
    GraphicsWindow.FillRectangle(664, 60, 350, 650)
    GraphicsWindow.DrawRectangle(664, 60, 350, 650)
    GraphicsWindow.FontName = "Arial"
    GraphicsWindow.PenColor = "Black"
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawBoundText(674, 60, 340, "Hier werden die Beschreibungen der einzelnen Themen angezeigt.")
    
    
    EndIf
    EndSub
      
    
    
    
    Sub MySub1
    
    letzterButton = Controls.LastClickedButton
    
    If letzterButton = BannerButton Then
    
          Bannerfenster:
          
        GraphicsWindow.Clear()
        
         'Button
         'Zurueck
       GraphicsWindow.BrushColor = "Black"
       Controls.ButtonClicked = MainMenu
       Zurueck2Button = Controls.AddButton("Zurück",10,10)
       Controls.SetSize(Zurueck2Button,100,30)
          
       GraphicsWindow.BrushColor = "White"
       GraphicsWindow.PenColor = "Gray"
       GraphicsWindow.FillRectangle(10, 60, 350, 650)
       GraphicsWindow.DrawRectangle(10, 60, 350, 650)
       GraphicsWindow.FontName = "Arial"
       GraphicsWindow.PenColor = "Blue"
       GraphicsWindow.BrushColor = "Blue"
       GraphicsWindow.PenWidth = 15
       GraphicsWindow.DrawBoundText(10, 60, 340, "Tutorial zum erstellen eines Banners:")
       GraphicsWindow.PenColor = "Black"
       GraphicsWindow.BrushColor = "Black"
       GraphicsWindow.PenWidth = 11
       
       
       EndIf
     EndSub
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     Sub MainMenu
       
       Hintergruende2:
    
    
    'Hintergruende (Tagesabhaengig)
    If (Clock.WeekDay = "Mittwoch") Then
    hintergrund1 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 1.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund1)
    breite = ImageList.GetWidthOfImage(hintergrund1)
    GraphicsWindow.DrawImage(hintergrund1, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Dienstag") Then
    hintergrund2 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 2.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund2)
    breite = ImageList.GetWidthOfImage(hintergrund2)
    GraphicsWindow.DrawImage(hintergrund2, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Donnerstag") Then
    hintergrund3 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 3.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund3)
    breite = ImageList.GetWidthOfImage(hintergrund3)
    GraphicsWindow.DrawImage(hintergrund3, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Montag") Then
    hintergrund4 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 4.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund4)
    breite = ImageList.GetWidthOfImage(hintergrund4)
    GraphicsWindow.DrawImage(hintergrund4, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Samstag") Then
    hintergrund5 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 5.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund5)
    breite = ImageList.GetWidthOfImage(hintergrund5)
    GraphicsWindow.DrawImage(hintergrund5, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Freitag") Then
    hintergrund6 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 6.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund6)
    breite = ImageList.GetWidthOfImage(hintergrund6)
    GraphicsWindow.DrawImage(hintergrund6, 0, 0) ' the coords are the top left of the image
    
    ElseIf (Clock.WeekDay = "Sonntag") Then
    hintergrund7 = ImageList.LoadImage(Program.Directory + "\Bilder\Hintergrund M&B 7.jpg")
    hoehe = ImageList.GetHeightOfImage(hintergrund7)
    breite = ImageList.GetWidthOfImage(hintergrund7)
    GraphicsWindow.DrawImage(hintergrund7, 0, 0) ' the coords are the top left of the image
    EndIf
    
    
    
    
    
    Buttons20:
    
    
    letzerButton = Controls.LastClickedButton
    
    If (letzerButton = TutorialButton) Then
      
      
      'Button
    'Tutorial
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    TutorialButton = Controls.AddButton("Tutorials",10,10)
    Controls.SetSize(TutorialButton,100,30)
      
    
      'Button
    'Script
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    ScriptButton = Controls.AddButton("Scripts",130,10)
    Controls.SetSize(ScriptButton,100,30)
    
    
      'Button
    'Anleitung für andere  Modding Programme
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    ProgrammButton = Controls.AddButton("Programme",250,10)
    Controls.SetSize(ProgrammButton,100,30)
    
    
      'Button
    'Anleitung Mods
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    ModButton = Controls.AddButton("Mods",370,10)
    Controls.SetSize(ModButton,100,30)
    
    
      'Button
    'Optionen
    GraphicsWindow.BrushColor = "Black"
    Controls.ButtonClicked = MySub
    OptionenButton = Controls.AddButton("Optionen",490,10)
    Controls.SetSize(OptionenButton,100,30)
    
    
    
      'Button
    'Suche
    'GraphicsWindow.BrushColor = "Black"
    'Controls.ButtonClicked = MySub
    'SucheButton = Controls.AddButton("Suche",610,10)
    'Controls.SetSize(SucheButton,100,30)
    
    EndIf
    EndSub


    Ich bin Neu

    Wednesday, September 12, 2012 6:21 PM
  • Use the publish method for longish code if you can.

    The issue is the repeated setting of Controls.ButtonClicked.

    The rule is set this ONCE, at the start of the program and not inside a subroutine.

    Do not set it to more than subroutine e.g. MySub and MySub1 and MainMenu. Just handle different buttons inside one sub using the Controls.LastClickedButton.

    This your code hacked to work, import JGC473, but the structure is hard to follow and will make life hard.  I really recommend something like the code I gave before, this one WCF463, for a good starting structure.

    EDIT

    One approach if you have lots of buttons that change is to use Shapes.ShowShape and Shapes.HideShape to just display the ones you want at any point.  Just create them all at the start, and never create or remove any during the program, just show and hide them.

    Perhaps also have a variable that stores which 'page' you are on and use this to hide/show all the required buttons for the current 'page'.  Still using just the ONE Button event subroutine.

    This will help to not use GraphicsWindow.Clear() which gets rid of everything and means anything you need has to keep being created.

    Also for the graphics you don't need to get the hoehe and breite of the images unless you want to use these for something.


    Wednesday, September 12, 2012 7:10 PM
    Moderator
  • Thanks. I will try the shapes.

    1. How can I do, that I only have to use the ButtonClicked event only one time? Perhaps I have a blackout, but I don't know how....

    2. I searched in the forums, but I can't find  WCF463  or  JGC473 .


    Ich bin Neu

    Thursday, September 13, 2012 2:53 PM
  • 2] These are import IDs, Press the Import button on the SmallBasic interface and enter the 6 digit code.
    Thursday, September 13, 2012 3:11 PM
    Moderator
  • Ahhhh

    This explain it. :)

    Thanks for this. My problem is now fixed.

    But how can I hide the rectangles and the text in it?

    Ich bin Neu

    Thursday, September 13, 2012 5:02 PM
  • Harder,

    you could create a multi-line Textbox and just hide this, example below:

    mlTextBox = Controls.AddMultiLineTextBox(50,50)
    Controls.SetSize(mlTextBox,400,500)
    EOL = Text.GetCharacter(13)
    Controls.SetTextBoxText(mlTextBox,"This is a multiLine textbox"+EOL+"for you to text in"+EOL+EOL+"You need to end of lines in though")
    Program.Delay(2000)
    Shapes.HideShape(mlTextBox)
    Program.Delay(2000)
    Shapes.ShowShape(mlTextBox)

    Thursday, September 13, 2012 5:36 PM
    Moderator
  • Now, this is nice but I can I write in this box. I need a box I can't write in. This is my code for it:

      GraphicsWindow.BrushColor = "White"
      GraphicsWindow.PenColor = "Gray"
      GraphicsWindow.FillRectangle(10, 60, 350, 650)
      GraphicsWindow.DrawRectangle(10, 60, 350, 650)
      GraphicsWindow.FontName = "Arial"
      GraphicsWindow.PenColor = "Blue"
      GraphicsWindow.BrushColor = "Blue"
      GraphicsWindow.PenWidth = 15
      GraphicsWindow.DrawBoundText(10, 60, 340, "Tutorial zum erstellen eines Banners:")
      GraphicsWindow.PenColor = "Black"
      GraphicsWindow.BrushColor = "Black"
      GraphicsWindow.PenWidth = 11


    Ich bin Neu

    Friday, September 14, 2012 10:50 AM
  • This is what this line does:

    Controls.SetTextBoxText(mlTextBox,"This is a multiLine textbox"+EOL+"for you to text in"+EOL+EOL+"You need to end of lines in though")

    It is equivalent to:

    GraphicsWindow.DrawBoundText(10, 60, 340, "Tutorial zum erstellen eines Banners:")

    Writing to the textbox means the whole thing can easily be hidden and re-shown.

    With the DrawBoundText you get the advantage of not having to put EOLs in (bound), but you have to erase it and redo it all if you want it again.

    To Erase I would not use GraphicsWindow.Clear(), but rather do a GraphicsWindow.FillReactangle over the area you want to clear.  The GraphicsWindow.Clear also removes all shapes and controls.

    Friday, September 14, 2012 11:41 AM
    Moderator
  • LitDev,

    In the above you suggest using GraphicsWindow.FillRectangle() which actually just overlays the graphics window with a filled rectangle.  As far as I can see though, if you want to drawtext back over the same area that you just cleared it doesn't allow it to show as the rectangle has that part of the graphics window covered up.  The only way that I can see is to actually clear the window and lay it out again.  Or am I missing something?

    JR


    JR

    Friday, September 14, 2012 8:06 PM
    Answerer
  • Hi JR,

    This works I think, or do you mean something else:

    GraphicsWindow.DrawBoundText(20,20,300,"This is my text")
    Controls.AddButton("TEST",150,20)
    Program.Delay(2000)
    GraphicsWindow.BrushColor = GraphicsWindow.BackgroundColor
    GraphicsWindow.FillRectangle(20,20,300,300)

    The Draw methods act on the background layer (that below shapes) and can be cleared with a FillRectangle, not removing shapes or controls above them.

    A GraphicsWindow.Clear() removes the background and  Shapes/Controls layers.

    EDIT

    I see the problem redrawing text after the FillRectangle - NO its not a problem.

    EDIT again - No I think it is OK - I forgot to reset the brush colour after doing the FillRectangle clear on my test before drawing the new text

    GraphicsWindow.DrawBoundText(20,20,300,"This is my text")
    Controls.AddButton("TEST",150,20)
    Program.Delay(2000)
    GraphicsWindow.BrushColor = GraphicsWindow.BackgroundColor
    GraphicsWindow.FillRectangle(20,20,300,300)
    Program.Delay(2000)
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawBoundText(20,20,300,"A new message")
    Friday, September 14, 2012 8:19 PM
    Moderator
  • Here's a code snippet I've made a long time ago when I rebelled against GraphicsWindow.Clear() removing all Shapes & Controls besides clearing the screen:

    Sub ClearScreen
      ' Clears GraphicsWindow w/o erasing Shapes nor Controls objects.
    
      Stack.PushValue("Color"  GraphicsWindow.BrushColor)
    
      GraphicsWindow.BrushColor= GraphicsWindow.BackgroundColor
      GraphicsWindow.FillRectangle(0,0  GraphicsWindow.Width , GraphicsWindow.Height)
    
      GraphicsWindow.BrushColor= Stack.PopValue("Color")
    
    EndSub

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

    Friday, September 14, 2012 9:11 PM
    Answerer
  • GoToLoop and LitDev,

    Both of your answers were great!  In my testing I was thinking the fillrectangle just covered over the section of the graphics window.  I didn't even think about resetting the brushcolor back to original.  So, when I put drew new text in the area of course it didn't show.  GoToLoops answer using the stack is a great idea.

    Thanks,

    JR


    JR

    Saturday, September 15, 2012 12:12 AM
    Answerer
  • Yeah, it is a nice idea to reset the brush colour. I will try this. Perhaps looked I false, but is there a way to hide the rectangel too?

    And a little other question: Is it possible (perhaps with an extension) to set an icon for the program? I am only able to add an icon for the taskbar and the programbar (with Power Extension).


    Ich bin Neu

    Saturday, September 15, 2012 5:11 AM