Home > Software engineering >  VB to perform dynamic code variable scope
VB to perform dynamic code variable scope

Time:09-23

Younger brother in a program to implement dynamic code, code is generated in the process of application, written string, reoccupy ExecuteStatement to execute the code in the string, as shown below, after tests found that can run, but the inside of the value of the variable is wrong, estimation is scoped out of the question, as follows, in ExecuteStatement after "a=5", the outside change a=3, then run ExecuteStatement msgbox "a" is still a 5, when the demand is changed the value of a variable in the ExecuteStatement, also follow changes in the outside, and after the outside changes the value of a variable, too, don't know how to deal with, thank you very much!

 Private Sub Command1_Click () 
Dim As a Integer
Dim ob As Object
Set ob=CreateObject (scriptcontrol)
Ob. Language="VBscript"
Ob. ExecuteStatement "a=5"
A=3
Ob. ExecuteStatement msgbox "a"

CodePudding user response:

But I'm afraid we can't do that, especially in the "outside" change were less likely to "inside",
In this way, even if the inside of the "change" outside may also is difficult,
The "dynamic code" is clearly attributes you explain execution code,
And "outside" variables, determine the memory address is compile time,
There is no connection between them,

Don't know scriptcontrol how powerful script,
Anyway, think even to achieve "inside to the outside," it's not so easy thing,

CodePudding user response:

Feel the original poster should change the way of thinking to solve the problem,
The dynamic code estimation is very limited

CodePudding user response:

Directly change the quantity is not enough.
Just to do such a thing before, also calculate to all that trouble.

You have to make a class, you need to change the value of the definition for this class of public variables.

For example:
Clase SSS
The public as a string
.
End clase

Then you instantiated within program:
Dim SS as new SSS

And then you can script or callbyname, (in fact, you can do to a variable that is assigned a value)

CodePudding user response:

please add the following "A language" is replaced by "VB6", "B" is replaced by the dynamic code "in the" VB6:

Don't be A language code is modified to B language code busywork,
Also don't use A language code to directly invoke B language code base, this complicated things so easy to get wrong,
Just make A, B language code of input and output is redirected to A text file, or modify A, B language code let it through text file input and output,
Can easily make A, B coordination between the two languages,
For example:
A will request data written to A file a.t xt, renamed after finish aa. TXT
B find aa. TXT, read its contents, call the corresponding function, and writes the results file b.t xt, after finish delete aa. TXT, changed its name to bb. TXT
Found A bb. TXT, read the content, after finish delete bb. TXT
Above can be replaced by any kind of A language or development environment, B can be replaced by any kind of with the development of A different language or development environment,
Unless A or B does not support to determine whether A file exists, file read and write and file name,
But who can name does not support to determine whether a file exists, file read and write and file name for the development of language or development environment?
Can put the temporary files on the RamDisk efficiency decrease wear disk,
Data structure is very complex, a text file format problems refer to a json or XML

The communication methods between the temporary text file sharing this process there are plenty of advantages, compared to other method only listed below I can think of now:
Loose coupling between process,
Can be on the same machine, process, also can cross machine, across the operating system, hardware platform, and even multinational,
, convenient debugging, and monitoring, only let the third party or artificial view the temporary text files,
Switch, convenient online service, need to delete or create the temporary text files,
, is convenient to realize distributed and load balancing,
Services to provide convenient, queue, queue is full and it is almost impossible to happen (unless the hard disk space full)
DE...

"Across different languages, machine, across the operating system, hardware platform, multinational, cross *. *" misery,
Back is "the use of Shared a plain text file information communication" of the shore!

CodePudding user response:

Inside/outside
The bottom/top
The machine/remote
Domestic/foreign
Windows/Linux
General embedded OS/OS
English/Chinese characters
Old environment/latest
8/16/32-bit/64
.
Winner-take-all!

CodePudding user response:

Zhao four repeater really liked!

You have to hand in the variables A this object,
Writing is wrong,

CodePudding user response:

refer to 6th floor vansoft response:
zhao four repeater really liked!

You have to hand in the variables A this object,
Spelled wrong,

Lottery! Lottery!
  •  Tags:  
  • API
  • Related