IonicWind Software

IWBasic => General Questions => Topic started by: Andy on July 24, 2017, 08:02:41 AM

Title: Global variables
Post by: Andy on July 24, 2017, 08:02:41 AM
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.

Title: Re: Global variables
Post by: billhsln on July 24, 2017, 09:37:22 AM
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
Title: Re: Global variables
Post by: LarryMc on July 24, 2017, 12:59:46 PM

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
Title: Re: Global variables
Post by: LarryMc on July 25, 2017, 10:22:14 PM
Quote from: LarryMc on July 24, 2017, 12:59:46 PM
If I understand your question correctly

Andy
Did I understand you correctly?
Title: Re: Global variables
Post by: Andy on July 25, 2017, 11:00:52 PM
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.
Title: Re: Global variables, RegCopyKey & RegRenameKey coming soon.
Post by: Andy on July 27, 2017, 07:30:13 AM
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.