Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Some Project and Declaration questions

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 20 February 2006, 14:57 PM    Post subject: Some Project and Declaration questions Reply with quote

1. How do I declare "Option Explicit" such that it applies to all the files in a project?

2. I wish to declare a constant with project wide scope. Where do I do this?

3. Suppose I have a project with 2 modules declared. The first module is MyMain.bas (where Sub Main() lives) and the the second is MyComm.bas. They both are in the Property Projects window. If I make a change to MyComm.bas and do not save the change then the compiler never sees it and won't until I save MyComm.bas. Is there a way to configure the IDE to save all files in a project then compile the entire project. I see a Build in the tools menu but it is always disabled.

4. If the file MyComm.bas is declared to be in MyProject.pjt why do I have to also #include it in my MyMain.bas? What, exactly, is the meaning of a project?

Any enlightenment will be appreciated. Smile

Vic
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 20 February 2006, 16:07 PM    Post subject: Re: Some Project and Declaration questions Reply with quote

victorf wrote:
1. How do I declare "Option Explicit" such that it applies to all the files in a project?

This option is for compatibility only and has no effect. Read the following manual page for more detail: http://www.zbasic.net/doc/ZBasicRef/ZBasicRef14.html
victorf wrote:
2. I wish to declare a constant with project wide scope. Where do I do this?

Use the Public keyword in any module. This applies to constants, variables and routines. Private makes it local to the module only. As a side note I prefer to explicitly use Public and Private instead of Dim and only use Dim inside routines where Public/Private cannot be used.
victorf wrote:
3. Suppose I have a project with 2 modules declared. The first module is MyMain.bas (where Sub Main() lives) and the the second is MyComm.bas. They both are in the Property Projects window. If I make a change to MyComm.bas and do not save the change then the compiler never sees it and won't until I save MyComm.bas. Is there a way to configure the IDE to save all files in a project then compile the entire project. I see a Build in the tools menu but it is always disabled.

The file with the current focus is saved before compilation. I guess the IDE errs on the side of safety and prefers the user to explicitly save other files. This is standard practice with most IDEs. Unsaved files get an asterisk to indicate that they need saving.
victorf wrote:
4. If the file MyComm.bas is declared to be in MyProject.pjt why do I have to also #include it in my MyMain.bas? What, exactly, is the meaning of a project?

The PJT file includes all of the files of the project. Perhaps you are using Ctrl-F7 which just compiles one file versus using F7 which compiles a project. The Compile option on the Project menu should be enabled if you open a project (PJT).
Back to top
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 20 February 2006, 19:18 PM    Post subject: Reply with quote

Here are the first few lines of code from my Sub Main routine:
Code:

Sub Main()

   Public Const MyTest as byte = 10
   Const ADCBAT as byte = 20   'pin for ADC Low Battery
   Const FRAMUSRADR as UnsignedInteger = 32700   'begin user data storage

Yadda
Yadda
Yadda

End Sub


I added the declaration of the Const MyTest to check the compile. When Compiled, the line causes this error:
Quote:

Error: expected statement or 'End Sub'


If it is possible to declare a project wide constant in any module apparently does not include the "Main" module? What am I doing wrong Question

Quote:

The file with the current focus is saved before compilation. I guess the IDE errs on the side of safety and prefers the user to explicitly save other files. This is standard practice with most IDEs. Unsaved files get an asterisk to indicate that they need saving.


At least the compiler should compile the code that is currently in the IDE or, at a minimum, warn the user that a file is unsaved. I believe that IDEs like VB and Delphi give the user the option of saving before compile. It is very easy to make some small change in a project module and forget to save it and do a compile and later find out that the chance was NOT included in the compile. I understand that this is a minor complaint. Smile

Vic
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 20 February 2006, 19:34 PM    Post subject: Reply with quote

The module for the subroutine Main is not necessarily named "Main" but it depends on the file that the code is in such as Test42.bas. You cannot declare Public stuff inside a routine. The corrected code is as follows:
Code:
Public Const MyTest as byte = 10

Sub Main()
   Const ADCBAT as byte = 20   'pin for ADC Low Battery
   Const FRAMUSRADR as UnsignedInteger = 32700   'begin user data storage
End Sub

My favorite IDE (Eclipse) leaves it up to the user to save files when desired and does not compile or autosave these files. This allows for temporary "works in progress" which are clearly indicated with an asterisk. I think this is one of those personal preference items.
Back to top
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 20 February 2006, 21:08 PM    Post subject: Reply with quote

Mike,

Wow Exclamation I have learned a lot with this thread. I want to thank you. Smile

I had never seen the F7 Compile on the Projects Menu. Works great. I WAS using Ctrl+F7 on the Tools menu. It might be cool to have the various Compile Keys on one menu. Confused

What is the Build Shift+F7 on the Tools menu for?

Thanks again Very Happy

Vic
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 21 February 2006, 5:00 AM    Post subject: Reply with quote

Quote:
What is the Build Shift+F7 on the Tools menu for?


In the bas.properties file there is a series of entries that described the actions to take for compiling, building, etc. Generally, the action taken is dependent on the extension of the file currently being displayed (except for project-oriented actions). For example, the entry below describes how to compile a .bas file. This action is associated with ctrl-F7 and selecting the Comile entry on the Tools menu. The Compile entry will be enabled only if there is a compile command defined for the extension of the file currently being displayed.

Code:
command.compile.$(file.patterns.bas)=$(ZBasic) --directory="$(FileDir)/" "$(FileName).$(FileExt)"


Similarly, the entry below tells how build a project. Again, the Build entry will only be enabled when there is a command defined for the extension of the file currently being displayed.

The SciTE editor as distributed by others has no project organization at all. I added that part to it when building the ZBasic IDE. To support this, I added more "commands" that you can specify to tell the IDE how to build a project. These commands are different in that it doesn't matter what file is currently being displayed. Instead, the build command keys off of the currently loaded project. The entry in bas.properties that defines the "Project Build" action (listed as Compile on the Project menu) is:

Code:
command.project.build=$(ZBasic) --directory="$(project.dir)/" --project="$(project.name).$(project.ext)"


The Compile entry on the Tools menu is useful for small projects that comprise a single file. This allows you to compile that one file into a .zxb file without having to create a .pjt file. Of course, if you need or want additional compiler options you'll either have to add them to the command.compile entry in bas.properties or create a .pjt file and put them in it.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 22 February 2006, 18:43 PM    Post subject: Reply with quote

In case I didn't explain clearly enough, here's the scoop on a few menu items related to compiling, building and running:


Project|Compile (F7)
This is only enabled if a ZBasic project is loaded. Invoking this will cause the IDE to execute the command assigned to the IDE variable command.project.build. By default (as set in bas.properties), this is set to invoke the ZBasic compiler, passing it the project file name in the --project= option.


Project|Go (F5)
This is only enabled if a ZBasic project is loaded. Invoking this will cause the IDE to execute the command assigned to the IDE variable command.project.go. By default (as set in bas.properties), this is set to invoke the ZX downloader that is internal to the ZBasic IDE, passing it the name of the .zxb file to download.


Note: Unless you have some special circumstances, you can safely ignore the Compile, Build, and Go entries on the Tools menu when using the IDE for ZBasic. For the sake of completeness, the function of those entries is described below.


Tools|Compile (ctrl-F7)
This is only enabled if there is a compile command defined corresponding to the extension of the file currently being viewed. By default (as set in bas.properties) the variable command.compile.bas is set to invoke the ZBasic compiler, passing it the name of the file currently being viewed. N.B. this has the effect of compiling the currently viewed file irrespective of its membership in the current (or any other) project.

This is primarily useful to compile a simple application that is contained in a single .bas file. The resulting .zxb file will have the same name as the currently viewed file with the extension replaced by .zxb.


Tools|Build (shift-F7)
This is only enabled if there is a build command defined corresponding to the extension of the file currently being viewed. By default (as set in bas.properties) the variable command.build.pjt is set to invoke the ZBasic compiler, passing it the name of the file currently being viewed as the parameter to the --project= option. N.B. this has the effect of compiling the project contained in the currently viewed file irrespective of the currently loaded project.

This may be useful to compile a different project without changing the currently loaded project. Note that a .bxp file is also considered to be a ZBasic project file for the purposes of this menu item.


Tools|Go (shift-F5)
This is only enabled if there is a go command defined corresponding to the extension of the file currently being viewed. By default (as set in bas.properties), the variable command.go.bas is set to invoke the ZX downloader that is internal to the ZBasic IDE, passing it the name of the file to download as the currently viewed file with the extension replaced by .zxb.

This is primarily useful to run a simple application that is compiled from a single .bas file (using Tools|Compile).

To reiterate, the SciTE editor (on which the IDE is based) does not have a Project menu or any project-oriented features. Using SciTE, you would have to make project file the current file and then select Build from the Tools menu in order to build the project. This may be suitable for some situations but for ZBasic it seemed cumbersome. Hence, the Project menu was added. The IDE knows what the current project is irrespective of what file is currently being viewed.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group