April 26, 2024, 06:25:40 AM

News:

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


Global variables

Started by Andy, July 24, 2017, 08:02:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

I'm creating a lib file, in this lib file there is a sub routine, lets call it X.

In the sub X, I'm building up an ISTRING[255] (call it MyIstring).

How do I return the value of MyIstring - completely forgot this one.

The lib file is built as a project, I have an include file that declares extern all the sub routines of the lib file.

So altogether I have three files:

Myprog.iwb which uses the lib file functions.
MyInclude.inc which declares the lib file routines.
MyLibfile.lib - the actual file that contains the functions.

How do I call sub routine X in Myprog so I can access the istring contents.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

July 24, 2017, 09:37:22 AM #1 Last Edit: July 24, 2017, 10:58:23 AM by billhsln
Have you looked at doing GLOBAL variables in a PROJECTGLOBAL.

Example from Help:

'in the defining source file
GLOBAL myvariable
GLOBAL myfunction
DEF myvariable as UINT

SUB myfunction(a as INT),UINT
    RETURN a+5
ENDSUB
-----

'in another source file
EXTERN myvariable as UINT
DECLARE EXTERN myfunction(a as INT),UINT
myvariable = myfunction(7)

OR:

'in the defining source file; "myglobals.iwb"
'file added to project just like all other source files

PROJECTGLOBAL "on"
  INT myvariable_1
  INT myvariable_2
  DIALOG mydialog_1
PROJECTGLOBAL "off"

-----

'in all other source files
'add this line at beginning of file
$INCLUDE "myglobals.iwb"


Bill
When all else fails, get a bigger hammer.

LarryMc


in lib

export mysub
global sub mysub(),string
istring x(255)

x=blah.....

return x
endsub


and then in your inc file

$use "mylib.lib"
declare extern mysub(),string


then in an application:

$include "mylib.inc"

istring b(255)
b= mysub()


If I understand your question correctly
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Quote from: LarryMc on July 24, 2017, 12:59:46 PM
If I understand your question correctly

Andy
Did I understand you correctly?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Larry,

Sorry for not getting back, I was really busy.

Yes you did, it fixed it for me, it's been such a long time since I was trying to do something like this I just simply couldn't remember - thanks!

I'm working on code to copy / rename a registry key and all it's sub keys and values - getting there!

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Well thanks to Bill and Larry,

I've now managed to create two new registry commands:

RegCopyKey, and RegRenameKey.

Attached is a screen shot of the results from RegCopyKey where I copy a key (and sub keys / values) from "Test" to "Test2".

RegRenameKey uses the copy key command (above) and if all is well then deletes the original key.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.