May 09, 2024, 11:43:21 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How do I reference SUBS from one source file to another

Started by jakala, November 25, 2007, 08:41:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jakala

Sir(s):
I am a complete newbie with a lot of questions. I'm probably trying the impossible.
Is there a way to have the primary source file to recognize the sub 'newgame' in a resource 'custom' file? Or should I be
doing this at all?
I've tried many combinations of GLOBAL, DEFINE, EXTERN to no avail.
Thank-you

'-----------Primary program---------------
DEF MainWindow:Window
'$INCLUDE "C:\Program Files\EBDev\projects\myproject\IDE2.inc"   'Results in duplicate window declaration error

'***********************
'*      Program        *
'***********************
$MAIN
NewGame()
OPENWINDOW(MainWindow,0,0,0,0,@MINBOX|@MAXBOX|@SIZE|@MAXIMIZED,NULL,"Caption",&MainWinProc)
WAITUNTIL MainWindow = False
END

'***********************
'*     MainWindow      *
'***********************
SUB MainWinProc
    SELECT @MESSAGE
   CASE @IDCLOSEWINDOW
       CLOSEWINDOW(MainWindow)
    ENDSELECT
    RETURN
ENDSUB

'-----------Resource File-------
EXTERN MainWindow:WINDOW
DECLARE NewGame   
DECLARE StartGameDlgProc
DEF StartGameDlg:Dialog

SUB NewGame
    DEF Rst:INT
   
    CREATEDIALOG StartGameDlg,0,0,209,240,@CAPTION|@SYSMENU,MainWindow,"New Game!",&StartGameDlgProc
    Rst = DOMODAL StartGameDlg

    RETURN
ENDSUB   

SUB StartGameDlgProc
    Select @MESSAGE
        Case @IDINITDIALOG
       CENTERWINDOW(StartGameDlg)
   CASE @IDCLOSEWINDOW
       CLOSEDIALOG(StartGameDlg)
     ENDSELECT
     RETURN
ENDSUB

LarryMc

Need some additional info in order to help.

Since you are using  "$main" is it correct to assume you created a "project" from the IDE menu?

If so, are both the 'main' .eba file and the 'resource' .eba file added to the project.


Or, are you trying to accomplish your task with a single .eba file and an .inc file that contains the subs?

Larry

Something I noticed in your code is that you are calling the dialog before you ever create its 'parent' window.

At any rate, answer my questions above and I'll see if I can help you.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

jakala

Thank-you for the speedy responce.

To answer your questions:
     - Yes I am attempting to use the 'Project' with the 'rebuild all'
     - Yes, I added the 'Resource' file as a 'Custom' file
     - I've changed the 'NewGame' call to be after the 'OPENWINDOW' command.
     - I've tried adding a menu (which worked) but I still get the 'NewGame' referenced as an 'undeclared function'

Sorry I do not much about these things. I'm accustomed to using RapidQ. 

LarryMc

Noticed several things wrong.
Major item is that it appears you are trying to add what you are calling the 'custom' file as a 'resource' with a type of "custom'.

I have modified your code and placed it in the 2 files to follow.


'-----------TEST1  Primary program---------------
global MainWindow
DEF MainWindow:Window
declare extern InitNewGame()
extern StartGameDlg:Dialog
'$INCLUDE "C:\Program Files\EBDev\projects\myproject\IDE2.inc"   'Results in duplicate window declaration error

'***********************
'*      Program        *
'***********************
$MAIN

OPENWINDOW(MainWindow,0,0,600,480,@MINBOX|@MAXBOX|@SIZE,NULL,"Caption",&MainWinProc)
BEGINMENU MainWindow
    MENUTITLE "Option"
        MENUITEM "New Game", 0, 1
        SEPARATOR
        MENUITEM "Quit", 0, 2
ENDMENU
InitNewGame()
WAITUNTIL MainWindow = False
END

'***********************
'*     MainWindow      *
'***********************
SUB MainWinProc
DEF Rst:INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW MainWindow
CASE @IDCLOSEWINDOW
CLOSEWINDOW(MainWindow)
CASE @IDMENUPICK
SELECT @MENUNUM
            CASE 1: ' user selected Print
                Rst = DOMODAL StartGameDlg
            CASE 2: ' user selected Quit
                CLOSEWINDOW MainWindow
        ENDSELECT
    ENDSELECT
    RETURN
ENDSUB



'-----------TEST 2  Resource File-------
EXTERN MainWindow:WINDOW
DECLARE NewGame   
DECLARE StartGameDlgProc
global StartGameDlg
DEF StartGameDlg:Dialog

global SUB InitNewGame()   
    CREATEDIALOG StartGameDlg,0,0,209,240,@CAPTION|@SYSMENU,MainWindow,"New Game!",&StartGameDlgProc
    RETURN
ENDSUB   

global SUB StartGameDlgProc
    Select @MESSAGE
        Case @IDINITDIALOG
       CENTERWINDOW(StartGameDlg)
   CASE @IDCLOSEWINDOW
       CLOSEDIALOG(StartGameDlg)
     ENDSELECT
     RETURN
ENDSUB


Now follow these steps carefully:

1. Create the 2 files above on your computer.
2. From the IDE menu select file/new/project
3. Give the project any name you want, in any directory you want,  with a project type of windows executable
4. The project is now open - leave it open
5. open the test1.eba file
6. right click on the file - at the bottom of thhe popup menu is "Insert File in Project" - click on it
7. open the test2.eba file
8.right click on the file - at the bottom of thhe popup menu is "Insert File in Project" - click on it
9. the FileView window at the lower right of the IDE screen should have the project name with the 2 files listed.

10. Now, compile and run the program.

I modified your code to appear closer to what I'm use to seeing,
I initialize the dialog after I creat the main window.
I add a menu to the main window. 
Click on the NewGame option to open the modal dialog.

Hope this helps.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

Quote
Hope this helps.

Larry

It helped me a lot. Thanks.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

jakala

I've been busy wih Xmas, etc.  I should have got back to you sooner. Your coding worked very well. Thanks!

JoaoAfonso

Hmm...

I am having the problem of using lots of subs in my program, and I am wanting to separate them in multiple files, for better work with them. I used until now 3 .inc files, but now I am using some subs that need variables from a main program.

From what I understud, if I create a project adding all .eba files, it is the solution.

What I've done to test was change all .inc files to .eba files, and added all of them into my project (removed the $include statements from what was my main program). There were lots of erros when compiling and then I've added all the declares, types and such to just one file and still shows errors.

Is there a way to make it work with just an .eba + various .inc, or just in a projec? And in a project, how to use it correctly (I tried to do what Larry told with no success)?
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900

LarryMc

This is what I do and it works every time

At the beginning of each of the files that have routines in I have a the following line:
$define Exxx
Where E is just a letter I picked and xxx is a 3 digit numerical string.
So if I have 3 files with subroutines I would use E100, E101, E102.
They can be any name you want as long as the system doesn't use it and it isn't the name of a variable you're using somewhere.
I usually use E100 for my main program file.

Then I create and include file that looks something like this:
$ifdef E101
global in_classesAU :declare in_classesAU(fname as string)
$else
declare extern in_classesAU(fname as string)
$endif

$ifdef E102
global in_methodsAU :declare in_methodsAU(fname as string)
global mparam_parseAU :declare mparam_parseAU(string a$)
$else
declare extern in_methodsAU(fname as string)
declare extern mparam_parseAU(string a$)
$endif

$ifdef E103
global in_functionsAU :declare in_functionsAU(fname as string)
global fparam_parseAU :declare fparam_parseAU(string a$)
global pub_pri_pro_flag :int pub_pri_pro_flag
$else
declare extern in_functionsAU(fname as string)
declare extern fparam_parseAU(string a$)
extern pub_pri_pro_flag:int
$endif

$ifdef E104
global in_constantsAU :declare in_constantsAU(fname as string)
$else
declare extern in_constantsAU(fname as string)
$endif

That follows the pattern:
QuoteIf I'm in the file Exxx then
     define it as global and declare the function
else I'm not in Exxx then
     declare the function as external
This works with variables as wel as subroutines.

I then add the inc file to all the source files right after where I did the $define Exxx thing.

I've got modules(src files)that contain code I use in multiple programs and it makes it easy to just plug them in to the current project I'm working on.

Hope this helps.
If not, send me all your source files and I'll try to set it up for you.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library