April 26, 2024, 08:49:19 AM

News:

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


Adding a Command to IWBasic

Started by Logman, January 28, 2011, 08:12:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Logman

January 28, 2011, 08:12:55 AM Last Edit: January 28, 2011, 09:42:49 AM by Logman
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
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

LarryMc

January 28, 2011, 08:21:14 AM #1 Last Edit: January 28, 2011, 08:27:26 AM by LarryMc
for starters, where's your
use$ "newproject.lib"

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


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

Logman

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
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

Logman

January 28, 2011, 08:44:52 AM #3 Last Edit: January 28, 2011, 09:37:39 AM by Logman
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
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Logman

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
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!

sapero

Logman, the two names must exactly match:

GLOBAL SUB mysub
$command MYSUB ' error: different case used

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Logman

January 28, 2011, 11:34:11 AM #8 Last Edit: January 28, 2011, 11:37:00 AM by Logman
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.
Education is what you get when you read the fine print.<br />Experience is what you get when you don't!