Hi both,

I saw Bill's answer, and immidiately thought: this doesn't work.
At least not as a MapBasic program. Tried it in 4.1 and it didn't.
And you were thinking of utilizing this in MB code, Gary ?

The problem is the scope. Or name space if you prefer that term.
Each MB program has its own separate scope in which it defines it variables
etc.
The "run command" taps into a different (but similar) scope, the user's
scope.
That you can also refer via the MapBasic window. And yes, you can do
MB programming stuff directly in that window, including variable
definitions, assignments etc. Just not looping and other structured
programming.
That's why Bill's suggestion works there, but not compiled as a program.

More specifically it fails if used as a program in defining the two
variables
(iSample and bTruth) in the default (i.e. MB) scope, while the "run
command"
assumes they are defined in the user scope. If you change the variable
definitions,
assignements and usage to occur in the user scope (using "run command") it
works.
I.e.:

'Not:
dim iSAMPLE as integer
'but:
run command "dim iSAMPLE as integer"

'Not:
iSAMPLE = 10
'but:
run command "iSAMPLE = 10"

'Not:
print bTruth
'but:
run command "print bTruth"

Getting variable values back from the user scope to the program scope
presents a problem. It can be done via tables, and it may be possible to
access them using DDE - haven't tried it though.

A pitfall is, that the user scope is persistent, i.e. permanent while MI
runs.
So you can't run the same program twice in the same session because the
variable definitions fails the second time around because the variable's
already been defined. However, using "undim" to remove the variables
after usage will fix that problem.

Regards
Lars Nielsen

**********************************************************
Lars Nielsen                                [EMAIL PROTECTED]
Development Manager, Special Products Contact
Kampsax Geoplan Odense               http://www.mapinfo.dk
Authorized MapInfo Distributor in Denmark & Norway
Address: Rugaardsvej 55, DK-5000 Odense C
Telephone: +45 6313-5000           Facsimile +45 6313-5090
**********************************************************




Bill Thoen <[EMAIL PROTECTED]> on 19-05-99 19:38:39

To:   "Gary S. Spring" <[EMAIL PROTECTED]>
cc:   [EMAIL PROTECTED]
Subject:  Re: MI: Using indirect variables in MB




Heheh... there's always someone out there who would want to
invent the perpetual motion machine or write self-modifying
code... but while the former is a pipe dream, the latter is
possible in MapBasic. They way to do it is to ensure that all
your expressions in the table lookup are actual expression that
evaluate to either True of False (i.e. all variables are declared
by runtime, and that they are syntactically correct expressions.
The hard way is to write your own recursive descent parser and
evaluate each, updating symbol tables as needed, as if your
expressions were lines of code. That's harder, but you can
implement your own language and make up any rules you like that
way.

Try entering this in the MapBasic window to see how the "run
command" statement can be used to evaluate simple expressions:
-----
dim iSAMPLE as integer
dim sExpression as string
dim bTruth as logical

iSAMPLE = 10
sExpression = "iSAMPLE = 10"
run command "bTruth = (" + sExpression + ")"

'The expression should be true here
print bTruth

iSAMPLE = 7
run command "bTruth = (" + sExpression + ")"
'The expression should be false now
print bTruth
-----

Good luck!
- Bill Thoen


"Gary S. Spring" wrote:
>
> I'm writing code that requires that I be able to store expressions in a
> table.  So, for example, let's say I do the following:
>
> ' Get the contents of row 1, col 1 from table GARY and
> ' put them into a variable called sVALUE
>
> fetch first from GARY
> sVALUE = GARY.COL1
>
> Let's assume that the cell contains "iSAMPLE = 10"  thus sVALUE would
> take on that string value.  Nothing unusual so far.  But, now I would
> like to use the string as a precondition in an IF statement.  For
> example, say I have an integer variable called iSAMPLE that has been
> assigned a specific value.  I want to use the contents of sVALUE to see
> if it equals 10.
>
> IF sVALUE THEN X = 2
>
> So if iSAMPLE = 10, then X would equal 2.
>
> Is this possible in MB, and if so, what type of variable would sVALUE
> be?
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]




----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]

Reply via email to