Only 1 procedure will run, why?

Just starting out? Need help? Post your questions and find answers here.
Hot Pockets
User
User
Posts: 51
Joined: Mon Jun 01, 2009 3:56 am

Only 1 procedure will run, why?

Post by Hot Pockets »

When I try to run the program below only 1 Procedure will Display. If I run it as is the 1st procedure will run correctly. If rmark out either 1 the Other will run correctly. I don't understand it but then I don't know Purebasic. Please elighten me!! :roll:

Code: Select all

Declare SplashScr()
Declare MainMenu()
Enumeration
  #WIN_MAIN
  #IMAGE_FILE
  #IMAGE_DISPLAY
EndEnumeration
Global Quit.b = #False

SplashScr()

MainMenu() 

Procedure SplashScr()
#FLAGS = #PB_Window_BorderLess | #PB_Window_ScreenCentered
If OpenWindow(#WIN_MAIN, 0, 0, 1024, 768, "Image", #FLAGS)
  If LoadImage(#IMAGE_FILE, "StarMap3.bmp")
     ImageGadget(#IMAGE_DISPLAY, 0, 0, 1024, 768, ImageID    (#IMAGE_FILE))
     StartTime = ElapsedMilliseconds()             ; Get the actual value
     Delay(1000)                                   ; Wait 1000 milliseconds
     ElapsedTime = ElapsedMilliseconds()-StartTime ; 'ElapsedTime' value should be about
     Quit = #True 
  EndIf
EndIf
CloseWindow(Image)
 MainMenu.s() 
EndProcedure
  ; Create the menu. The indent is very important here for a good lisibility
Procedure MainMenu()  
#Result = #PB_Window_TitleBar | #PB_Window_ScreenCentered
 OpenWindow(1, 0, 0, 1024, 768, "Command")
  If CreateMenu(1, WindowID(1))
    MenuTitle("File")
      MenuItem( 1, "&Load...")
      MenuItem( 2, "Save")
      MenuItem( 3, "Save As...")
      MenuBar()
      OpenSubMenu("Recents")
        MenuItem( 5, "Pure.png")
        MenuItem( 6, "Basic.jpg")
        OpenSubMenu("Even more !")
          MenuItem( 12, "Yeah")
        CloseSubMenu()
        MenuItem( 13, "Rocks.tga")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "&Quit")

    MenuTitle("Edition")
      MenuItem( 8, "Cut")
      MenuItem( 9, "Copy")
      MenuItem(10, "Paste")
      
    MenuTitle("?")
      MenuItem(11, "About")

  EndIf
  
  DisableMenuItem(1, 3, 1)
  DisableMenuItem(1, 13, 1)
  ; This is the 'event loop'. All the user actions are processed here.
  Repeat

    Select WaitWindowEvent()
      Case #PB_Event_Menu
        Select EventMenu()  ; To see which menu has been selected
          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
        EndSelect
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until Quit = 1
EndProcedure

End
Edited by Berikco, added code tags
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

[ code ] tags please, it's very hard to read

Thanks
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Post by rrpl »

Main problem appears to be you have "Quit = #True" in the Procedure SplashScr(). Delete this as its not needed and you should be fine. :)

I can see some other problems in the code also but they shouldn't stop it working, so give it a close look over. If you want me to tell you, let me know.
zikitrake
Addict
Addict
Posts: 883
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

rrpl wrote:Main problem appears to be you have "Quit = #True" in the Procedure SplashScr(). Delete this as its not needed and you should be fine. :)

I can see some other problems in the code also but they shouldn't stop it working, so give it a close look over. If you want me to tell you, let me know.
quit is defined as Global, so in the sencond procedure this var = #true... you can try

Code: Select all

Procedure MainMenu()
	#quit = #false ;<----------------------- INITIALIZE THIS VAR AGAIN
	#Result = #PB_Window_TitleBar | #PB_Window_ScreenCentered
	OpenWindow(1, 0, 0, 1024, 768, "Command")
	If CreateMenu(1, WindowID(1))
		MenuTitle("File")
....
Hot Pockets
User
User
Posts: 51
Joined: Mon Jun 01, 2009 3:56 am

Why doesn't it run?

Post by Hot Pockets »

Thanks
I was surprised that there was other erros in code as code was written by someone else and I just modified it, sustituting my StarMap.bmp file for theirs
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Please think about it for a while. It's not errors in the two pieces of code. But they don't work together like you expect them to, because both expects Quit to be 0, but the first sets it to 1, so when the second procedure is reached it quits immediately.
Post Reply