IonicWind Software

IWBasic => Console Corner => Topic started by: Logman on January 28, 2011, 08:12:55 AM

Title: Adding a Command to IWBasic
Post by: Logman on January 28, 2011, 08:12:55 AM
Sapero/Larry:

I need help setting up a new subroutine. I've referenced previous threads, but still cannot get this to work out correctly.

First, I opened the IDE and created a new project called "newproject" and selected the project type as "Static Library". I saved the project to the c:\EBDev\projects folder.

Then I created a source file I named "mysub" and saved it to the c:\EBDev\projects folder. I compiled the project as "newproject.lib" and saved the resulting library file in the c:\EBDev\libs folder.

Here is my source program that went into the library:



GLOBAL SUB mysub(a as INT, b as INT), INT
DEF c AS INT
c = a + b
   RETURN c
ENDSUB



Then I created an .incc text file I named "newmathsub.incc" using Notepad and saved it in the c:\ebdev\bin folder.

Here are the contents of the text file:



'*NAME|new sub routines
'*VERSION|1.00
'*REQUIRE|newproject.lib
'*HELPFILE|HelpSmithTest.chm,Test Help Guide

$command MYSUB(a as int, b as int),int



Once I saved this file, I shut down the IDE and restarted it to register the .incc file.

Then I closed out the project and created a test program to use the new library sub.

Here is the code for the tes1t.eba source file:



OPENCONSOLE
DEF c AS INT

PRINT "This is a test of a new sub."

c = mysub(3,2)

DO:UNTIL INKEY$ <> ""

CLOSECONSOLE
END



I received this error message when I attempted to compile/link the program:



Linking...
Emergence Linker v1.22 Copyright 2009 IW Software
Unresolved external MYSUB
Error: Unresolved extern MYSUB
Error(s) in linking C:\Program Files\EBDev\projects\test1.exe



I'm not sure what's going on. I followed Larry's instructions from a previous thread, but can't get the new sub procedure to work.

I even tried putting $use "newproject.lib" in the test program--it didn't work.

Logman
Title: Re: Adding a Command to IWBasic
Post by: LarryMc on January 28, 2011, 08:21:14 AM
for starters, where's your
use$ "newproject.lib"

It should be before the first command$ statement in the .incc file


LarryMc
Title: Re: Adding a Command to IWBasic
Post by: Logman on January 28, 2011, 08:36:08 AM
Larry:

I thought the use$ statement went in the source code for the test program. Let me redue this and see if I can get it to work.

Thanks for getting back so soon.

Logman
Title: Re: Adding a Command to IWBasic
Post by: Logman on January 28, 2011, 08:44:52 AM
Larry:

I fixed the .incc file to read:



'*NAME|new sub routines
'*VERSION|1.00
'*REQUIRE|newproject.lib
'*HELPFILE|CXmlLM Help.chm,CXmlLM Library

$use "newproject.lib"

$command MYSUB(a as int, b as int),int



I recompiled and got the following errors:



Compiling
mysub
File: C:\Program Files\EBDev\projects\mysub.eba (6) undefined variable - use$ - "
File: C:\Program Files\EBDev\projects\mysub.eba (6) syntax error - "
Error(s) in compiling "C:\Program Files\EBDev\projects\mysub.eba



mmm. Still not sure what's going wrong.
Logman
Title: Re: Adding a Command to IWBasic
Post by: LarryMc on January 28, 2011, 09:02:55 AM
there shouldn't be a use$ statement in the mysub.eba file as you posted above.

Overdue for my morning nap

If you're still having problems when I get up I'll build you a complete go-by.

LarryMc
Title: Re: Adding a Command to IWBasic
Post by: Logman on January 28, 2011, 09:40:30 AM
Larry:

I'd really appreciate that. I look forward to seeing the code and will check in with you later. I'm at my wits end--I've tried everything I know of to no avail.

Thanks again for your assistance.

Logman
Title: Re: Adding a Command to IWBasic
Post by: sapero on January 28, 2011, 10:13:14 AM
Logman, the two names must exactly match:

GLOBAL SUB mysub
$command MYSUB ' error: different case used
Title: Re: Adding a Command to IWBasic
Post by: LarryMc on January 28, 2011, 11:33:26 AM
Here's what worked for me:

mysub.eba
*notice lower case mysub()
declare mysub(a as INT, b as INT), INT

GLOBAL SUB mysub(a as INT, b as INT), INT
DEF c AS INT
c = a + b
    RETURN c
ENDSUB


newmathsub.incc
*notice matching lowercase mysub() per Sapero
*notice $use statement - if you put it here you don't have to put it in your program file
Quote'*NAME|new sub routines
'*VERSION|1.00
'*REQUIRE|newproject.lib
'*HELPFILE|HelpSmithTest.chm,Test Help Guide

$use "newproject.lib"
$command mysub(a as int, b as int),int

test1.eba
*notice that MysuB() doesn't have to match the case of the other two.
OPENCONSOLE
DEF c AS INT

PRINT "This is a test of a new sub."

c = MysuB(3,2)

DO:UNTIL INKEY$ <> ""

CLOSECONSOLE
END

Hope that gets you on the right track.

Couple of thing you need to be aware of with incc files.
1. Make sure your command names are unique enough to never be duplicated in an official IWB release(present or future) or you will have problems with them being in conflict with each other.
2. The current versions of the IDE  limit the number of help files that can be picked out of incc files and added to the help menu to a total of 10 in the bottom section of the menu including the standard help file entries.

LarryMc
Title: Re: Adding a Command to IWBasic
Post by: Logman on January 28, 2011, 11:34:11 AM
Sapero:

Holy cow. I've been beating my brains out all day and it was something as simple as case. This never occurred to me.

The library and test program both work like champs now.  :D

Thanks for your help. I was doing everything Larry had laid out in an earlier thread and was ready to give up. You came through again.

Logman

Thanks again Larry, you always seem to have the answer. :) I love the way we can extend the language to suit our needs.