Page 1 of 1

How do you write a program?

Posted: Wed Nov 24, 2010 7:00 am
by Hot Pockets
I couldn't find a sub or include keyword and where do you put your structures and constants?Do you put them in every routine that needs them? Thanks in advance:
Hot Pockets

Re: How do you write a program?

Posted: Wed Nov 24, 2010 7:14 am
by STARGĂ…TE

Re: How do you write a program?

Posted: Wed Nov 24, 2010 7:04 pm
by Hot Pockets
Thank You for Being so help full!
Hot Pockets :)

Re: How do you write a program?

Posted: Wed Nov 24, 2010 7:41 pm
by Henrik
If i were you, i would download kales book
"PureBasic - A Beginner's Guide To Computer Programming"

link : http://www.purebasic.fr/english/viewtop ... 14&t=37059


Edit* Your subject doesn't fit your question

Regards
Henrik

Re: How do you write a program?

Posted: Wed Nov 24, 2010 7:45 pm
by utopiomania
Install PB and check out some of the examples that comes with it.

Re: How do you write a program?

Posted: Thu Nov 25, 2010 8:41 am
by blueznl
Hotpockets, it depends on your coding style. I typically throw all inits etc. togeter in one procedure leading to a basic structure like this:

Code: Select all

;
;
EnableExplicit
Define init()
Define main()
init()
main()
;

Procedure init()
  ;
  ; define structures, code, constants, whatever
  ;
EndProcedure

Procedure main()
  ;
  ; loop, event handling, whatever 
  ;
EndProcedure
Collections of routines that I keep using (in my case I have a file called x_lib.pb, it's included with CodeCaddy) have a similar structure:

Code: Select all

Procedure x_init()
  ;
EndProcedure

Procedure x_something()
  ;
EndProcedure
In my main programs I include the x_lib.pb file, and call x_init() once to get the thing moving:

Code: Select all

;
;
EnableExplicit
Define init()
Define main()
IncludeFile("x_lib.pb")
x_init()
init()
main()
;

Procedure init()
  ;
  ; define structures, code, constants, whatever
  ;
EndProcedure

Procedure main()
  ;
  ; loop, event handling, whatever 
  ;
  x_whatever()
EndProcedure

Re: How do you write a program?

Posted: Thu Nov 25, 2010 3:24 pm
by netmaestro
Structures and constants have a global scope and can go anywhere north of the first line in which they are used, including inside procedures but good coding style (to me at least) is to group them at the top of your program and clearly identify what they're for using comments.