How do you write a program?

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

How do you write a program?

Post 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
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: How do you write a program?

Post by STARGÅTE »

PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Hot Pockets
User
User
Posts: 51
Joined: Mon Jun 01, 2009 3:56 am

Re: How do you write a program?

Post by Hot Pockets »

Thank You for Being so help full!
Hot Pockets :)
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Re: How do you write a program?

Post 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
Last edited by Henrik on Wed Nov 24, 2010 7:51 pm, edited 4 times in total.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: How do you write a program?

Post by utopiomania »

Install PB and check out some of the examples that comes with it.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: How do you write a program?

Post 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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How do you write a program?

Post 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.
BERESHEIT
Post Reply