Home > Software engineering >  The Eval function string variable problem
The Eval function string variable problem

Time:09-21




Interface on A text10 controls, A formula is A - B
The following code, using VBScript language identification text box in the eval function formula "A - B", but the results have been incorrectly,
I will Label10=s.E val (Text10) Text) to Label10=s.E val (A - B) the result is right,
According to the judgment, the process of execution, Text10) Text="A - B", is more than double quotes, lead to the result is 0, is not normal, so, the great god, please help me to solve the following, how to write this part,

 Private Sub Command13_Click () 
Dim As Long A
Dim As Long B
A=2
B=444
Dim s
If Text10="" Then Exit Sub
On Error GoTo errHandler

The Set s=CreateObject (ScriptControl)
S.L anguage="VBScript"
Label10=s.E val (Text10. Text) problems here, if you write A - B running normally, if written Text10) Text, abnormal, content of the Text box or A - B but, here, became "A - B", this double quotes if go out, there's no way to do,

The Set s=Nothing
Flag=True
The Exit Sub
ErrHandler:
Text10=Err. The Description
End Sub

CodePudding user response:

 Private Sub Command13_Click () 
Dim As Long A
Dim As Long B
Dim s
Dim TMP As String

A=2
B=444
If Text10="" Then Exit Sub
On Error GoTo errHandler

The Set s=CreateObject (ScriptControl)
S.L anguage="VBScript"

TMP=Replace (Text10) Text, ""," ")
If TMP="A - B" Then Label10=s.E val (A - B)
The Set s=Nothing
Flag=True
The Exit Sub
ErrHandler:
Text10=Err. The Description
End Sub


CodePudding user response:

 Private Sub Command13_Click () 
Dim As Long A
Dim As Long B
Dim s

A=2
B=444
If Text10="" Then Exit Sub
On Error GoTo errHandler

The Set s=CreateObject (ScriptControl)
S.L anguage="VBScript"

Text10. Text=Replace (Text10, "A", A)
Text10. Text=Replace (Text10, "B", B)
Label10=s.E val (Text10. Text)

The Set s=Nothing
Flag=True
The Exit Sub
ErrHandler:
Text10=Err. The Description
End Sub
VB does not know you Text10 characters "A" is A reference variables, and character "B" is A reference variable B, so use the default value is 0,

CodePudding user response:

 Private Sub Command13_Click () 
'-- defined here cannot be Eval calls -
'Dim As Long A
'Dim As Long B
'A=2
'B=444

Dim s
If Text10="" Then Exit Sub
On Error GoTo errHandler

The Set s=CreateObject (ScriptControl)
S.L anguage="VBScript"

'- add variables (both Dim statements can be omitted) -
S.A ddCode "A=2"
S.A ddCode "B=444
"
Label10=s.E val (Text10. Text)

The Set s=Nothing
Flag=True
The Exit Sub
ErrHandler:
Text10=Err. The Description
End Sub

CodePudding user response:

You the s.E val (A - B) is equal to the s.E val (2-444), of course, have the effect, because in vb wrote A - B is the hands of the vb, but you write s.E val (" A - B ") is to handle the VBScript script host,

So either variable assignment in the script, if in the vb inside then completes the docking, see you what is the purpose of,
The second floor is to make the two docking, 3/f is AB variable assignment code will be moved to the script execution,

  • Related