March 28, 2024, 05:28:39 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Unable to print passed string variable in static text box in module

Started by AdrianFox, November 13, 2008, 10:51:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

I've now sorted out most of my initial difficulties in working with projects and calling subs in other source files. (Thanks for the help and advice folks! )  However, I've now got a strange problem with printing a passed string variable in a static text box created in a subroutine.

I've used the necessary global, extern etc commands : in the called file I've defined the subs:

declare window2(mystring as string)   'window2 is my sub
declare d2_handler(mystring as string) 'this is the handler for the dialog box d2
global d2                                        'make the dialog box global
def d2:dialog                                   'define d2 as a dialog

Now using my string variable, mystring, which has been given its 'value'  in the main (starting) module, I can successfully use it to print it in the caption of the dialog box in the subroutine of the second module, so the variable has been passed into this module ok.

I've also made the d2 handler  a global sub

global SUB d2_handler(mystring as string)  'should pass the string into the handler??

but when I try to print into the static text box using mystring  (chunk of code here....)

                       CASE @IDINITDIALOG
         CENTERWINDOW d2
         /* Initialize any controls here */
         SETCONTROLTEXT d2,1,mystring

all I get are a couple of odd characters or hieroglyphics in the static text box.

I've  found I could work round this by copying mystring into a new string (newstring) defined at the beginning of the second module.
           
                                     newstring=mystring  (inserted near the beginning of the module)

and  surprise, surprise!             setcontroltext d2,1,NEWSTRING                               WORKS!

BUT WHY?   I'm utterly baffled about why this will only work by  making the original variable into something else.

I'm sure one of you guys with a complete grasp of logic and program flow can enlighten this poor sap who would just like to understand what's going on.

Regards and best wishes,

Adrian
Adrian Fox

Ionic Wind Support Team

Handlers don't have any parameters.  You can't expect it to do anything.

Remove the parameter from the declaration and sub statements.

Use:

extern mystring as STRING

in the second source file. And...

def global mystring as string

in the first source file.

Study up on the difference between local, file global and project global variables...

- A local variable is only accessible within the subroutine in which it is defined, it can be passed to other subroutines.
- A file global variable is one that is defined outside of any subroutine, but not marked with the GLOBAL keyword.  They can be accessed by any code within that source file, but not by any other source file.
- A project global variable is one that is "DEF GLOBAL" in one and only one source file, and marked as external in all others, as I indicated above,

A simple method of handling project global variables is to use the PROJECTGLOBAL keyword... this is how it works...

Create one source file, call it "globals.eba" and add it to your project.  Format it like this:


PROJECTGLOBAL "on"
string mystring
dialog mydialog
...etc,
PROJECTGLOBAL "off"


Then in all other source files you only need to:

$include "globals.eba"

And the compiler takes care of the rest.  It automatically handles extern/global for those variables.

Paul.
Ionic Wind Support Team

AdrianFox

 ;D   Thanks very much Paul.

I'm amazed at the speed of your reply and thanks for the very helpful advice.  The ProjectGlobal keyword is not one I'd found yet, but sounds very useful.

Thanks again for your help, it really is appreciated.

Adrian
Adrian Fox