Page 2 of 3

Posted: Tue Jun 09, 2009 4:37 pm
by rsts

Re: Program Layout

Posted: Tue Jun 09, 2009 5:16 pm
by Trond
Hot Pockets wrote:Would it work as well if I reversed the order of items 4 and 5. (Just an idea.)
Only if you had declared the procedures called by 5. Else it would be like this:

Code: Select all

RunMainProgram() ; 5

Procedure RunMainProgram() ;4
  ; Do something nice
EndProcedure
And that wouldn't work, because the compiler would not yet know about RunMainProgram() at point 5 (try it). To remedy this error, one can place the procedure before the call to it, or place a declare (see the manual) before both.

Posted: Tue Jun 09, 2009 5:26 pm
by srod
I always keep a separate include file for declares.

That way when I need to modify a functions parameter list, for example, I am not hunting through various include files looking for the appropriate declare statement. :)

Program Layout

Posted: Wed Jun 10, 2009 2:09 am
by Hot Pockets
Thanks for the Help All !! Reversing the order is the way I'll go(it just seems more logical(to me) and using an INclude file with Declarations is a Pretty good idea too, I would Think you put Enumerations and Costants in that same File. I think my program will not run correctly because i did't use the procedure word in either.

Posted: Wed Jun 10, 2009 10:31 am
by srod
Enumerations and constants in yet another include file for me! :wink:

Posted: Wed Jun 10, 2009 1:05 pm
by Kale
Trond wrote:Kale, here is a (bad) example
You're not wrong. :P

Code that won't run one proc after another has run

Posted: Wed Jun 10, 2009 8:38 pm
by Hot Pockets
When I run the code below it will not run the second procedure but it will run the 1st. If I remark out Splashscr() and run it, it will run the Menu and Menu works. Why can't I get the procedures to run concurrently? :roll:

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

Posted: Wed Jun 10, 2009 8:55 pm
by Kaeru Gaman
please use code-tags.

why don't you continue the other topic?

the question was already answered.

Why wont it work?

Posted: Thu Jun 11, 2009 1:27 am
by Hot Pockets
Mr Gaman
I've never seen a code Tag or heard of a code tag. Is that the same as COMMENTS? There are already comments with the code displayed. If you mean't comments then I don't think(Since I know nothing about purebasic } I could have any comments to make. Purebasic seems to be very far removed from any basic I've used before(That is neither bad or good) Just an observation! I still need to know why The 1st Procedure
works and the next will not follow. Thanks for trying to help me. This is very vexing because it seems to me it should be a simple problem. In some other basics they use the Call statement to force it to work, but I can not find an equivalent. :cry:

Posted: Thu Jun 11, 2009 1:34 am
by pdwyer
Just put

[ code ]
all your code here
[ / code ]

(without the spaces

and it will use a fixed width font and make it green like this

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

Posted: Thu Jun 11, 2009 3:18 am
by GBeebe
I've had this problem in the past... the not seeing the menu or any gadgets on a window that has a SDL (sprite) surface on it. I don't remember my solution, but it had something to do with the main loop. Try replacing yours with this and see if it helps:

Code: Select all

Repeat
      Select WaitWindowEvent()
        Case  #PB_Event_CloseWindow
          End
        Case  #PB_Event_Gadget
          Select EventGadget()
            
          EndSelect
      EndSelect
    ForEver

Why won't it work?

Posted: Thu Jun 11, 2009 4:47 am
by Hot Pockets
Thanks for the help to the last two gentleman. To Mr Gaman. Anybody who can make 3400 or so posts and can't answer my simple question because the code was not in the right color needs help. Your aditude is
atrocious. You could of simply showed me how to do it and I would of cheerrily complied. Since 1 of the gentlemen was gracious enuff to give me something I shall try, perhaps you could be gentleman enuff to look at the Now green code and try your hand at a possible solution.

Re: Why won't it work?

Posted: Thu Jun 11, 2009 7:48 am
by Trond
Hot Pockets wrote:Thanks for the help to the last two gentleman. To Mr Gaman. Anybody who can make 3400 or so posts and can't answer my simple question because the code was not in the right color needs help.
No one here is obliged to help you. Here, as other places, it's more likely that you get help if do your best to make it easy to help you.
The code tag is not about the colour, it's about the indentation (spaces at the start of each line). Without it it's very hard to make sense of the code.

Additionally, you're posting the same question in two topics. This is like asking people for help, and when they don't help you, you just keep asking them. It's considered bad taste.

It's very hard to help you with the code because you seem to have a fundamental misunderstanding of how procedural programming (that's just normal programming) works. Each line is executed in succession, they don't execute all at once. You should start by writing your own codes rather than re-using code that you don't understand. That way you will learn faster.

I suggest you take a look here: http://www.xs4all.nl/~bluez/datatalk/pure1.htm
It's a beginner's guide to PureBasic, which also covers advanced topics. It will probably help you a lot.

Here is the program:

Code: Select all

Procedure SplashScr()
  If LoadImage(0, "C:\map.bmp")
    If OpenWindow(0, 0, 0, ImageWidth(0), ImageHeight(0), "Image", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
      ImageGadget(0, 0, 0, 0, 0, ImageID(0))
      Delay(1000)
    EndIf
  EndIf
  CloseWindow(0)
EndProcedure

Procedure MainMenu()
 OpenWindow(1, 0, 0, 512, 384, "Command", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  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
        Break
    EndSelect
  ForEver
EndProcedure

SplashScr()
MainMenu()

By the way, the point of a splash screen is to show something while the program loads. In this case the splash screen is bascially just wasted time because nothing happens while it's shown.

Why won't it run?

Posted: Thu Jun 11, 2009 11:02 pm
by Hot Pockets
My sincere apology to Mr Gaman. I overlooked the fact that My program lost its indentation because I saved it as Text. If I would of known how great Tags were I would of used them,(Great idea!)
Trend:
Thanks for setting me straight. I have already downloaded that book and printed all 350 Pages. Now I gusess it will end up in the dumper along with the money I spent buying PB.I don't think I'll ever be able to learn
PB. It is far more complicated from my point of view then Dark Basic or
Blitz Basic or Visual Basic 4. The only thing I almost learned that had almost as many constants was Ibasic. Again I am not really a programer. I wrote 1 very large Check register program in MS Basic7.11 That works well for me and I've been trying to re=write it for windows. Hah!! I doubt I'll ever suceed I am 80 years old, you never know tho, my health is good. Thanks for all your help!! :wink:

Posted: Fri Jun 12, 2009 12:12 am
by netmaestro
I don't think I'll ever be able to learn PB.
That isn't true. You don't have to master the whole language to make use of PureBasic. In fact, few if any of us can honestly say we "know" PB in the sense that no part of it holds anything new for us. I know I can't. Displaying a basic window and putting some simple controls on it is a matter of a few easy lines in PureBasic, yet just this much can yield a very useful program. You can do it, believe me. I just have a few suggestions for you:

1) Stick to programming challenges that you find really interesting.

2) Take your time, there's no rush.

3) Once you've mastered something, use it. Something you've used twelve times will be nearly second nature, no matter how hard it was to get that first one working.

4) Make yourself a sourcecode folder where you keep snippets of code that you can skim through when you want to remember how to do something. It's embarassing how many times I've had to search the forums for my own postings to refresh my memory on a given solution.

Lastly, feel free to PM me any time with coding questions or snippets you need help with. I'll do my best to help you in any way I can.