VBScript script uses (the Script Program and Host Program)

xiaoxiao2021-03-06  86

People who have worked industrially, know that support for scripting languages ​​is a basic function (such as IFIX, configuring king, etc.) that standard configuration software. If we use VB to develop similar features, can I achieve it? I would like to know that Microsoft provides MicrSoft Script Control 1.0 control, and I also see the use of this control in the VB version (if you use the ExecuteStatement method ExecuteStatement ("Msgbox" Hello ") ???). But the most important point, the ActiveX script interacts with the host application data, but there is no complete solution. I also explored a long time, I also figured out a little data transfer and interaction skills, now share it, for everyone to discuss research. Example Program Introduction: 1, first load MicrSoft Script Control 1.0 control. For it, it is basically no configuration, the default language VBScript, please download the VBScript command set (http://blog.9cbs.net/yefanqiu [Yailan resources] [03] VBScript instruction set) 2, add a window FRMTEST, add the following code: '*********************************************** ****************************************

'** Module Name: frmtest

'**: YFSoft copyright 2004 - 2005 (C)

'** created: Ye Fan

'** Japan: 2004-10-15 11:00:32

'** modified:

'** date:

'** Description: Exploration of scripting language

'** version: v1.0.0

'********************************************************** ***********************

Option expedition

'********************************************************** ***********************

'** function name: chkrun_click

'** → no

'** output: no

'** function description: script running control

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 11:19:31

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private sub chkrun_click ()

If Chkrun.Value = 1 THEN

Tmrrun.Interval = cmbruntime.text 'Running interval

TMRRun.enabled = true 'starts running at fixed interval loop

TXTEDIT.Enabled = falseelse

Tmrrun.enabled = false 'stops running

TXTEDIT.ENABLED = TRUE

END IF

End Sub

'********************************************************** ***********************

'** function name: CMBTYPE_CLICK

'** → no

'** output: no

'** function description: operation type switching

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 12:56:19

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private sub cMbType_click ()

cmdscdemo1_click

End Sub

'********************************************************** ***********************

'** function name: cmdrun_click

'** → no

'** output: no

'** function description: single run script

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 11:51:29

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private sub cmdrun_click ()

Call Tmrrun_timer

End Sub

'********************************************************** ***********************

'** function name: cmdscdemo1_click

'** → no

'** output: no

'** function description: Parameter delivery demonstration

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 11:03:29

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private subcmdscdemo1_click ()

DIM STRTYPE AS STRING

'Internal variable definition Similar to the data dictionary in the King

Valmem.clear

Valmem.SetValue "Value1", TXTVALUE (0) Valmem.SetValue "Value2", TXTVALUE (1)

Valmem.SetValue "Value3", 0

Select Case CMBTYPE.LISTINDEX

Case 0:

Strtype = " "

Case 1:

Strtype = "-"

Case 2:

Strtype = "*"

Case 3:

Strtype = "/"

End SELECT

TXTEDIT = "DIM LNGVALUE1" & VBCRLF

TXTEDIT = TXTEDIT & "DIM LNGVALUE2" & VBCRLF

TXTEDIT = TXTEDIT & "DIM LNGVALUE3" & VBCRLF

TXTEDIT = TXTEDIT & "LNGVALUE1 = VM.GetValue (" & Chr (34) & "Value1" & Chr (34) & ")" & VBCRLF

TXTEDIT = TXTEDIT & "LNGVALUE2 = VM.GetValue (" & Chr (34) & "Value2" & chr (34) & ")" & vbcrlf

TXTEDIT = TXTEDIT & "LNGVALUE3 = CINT (LNGVALUE1)" & Strtype & "CINT (LNGVALUE2) & VBCRLF

TXTEDIT = TXTEDIT & "VM.SetValue" & chr (34) & "Value3" & Chr (34) & ", LNGValue3" & VBCRLF

End Sub

'********************************************************** ***********************

'** function name: cmdscdemo2_click

'** → no

'** output: no

'** function description: Object operation presentation

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 13:41:23

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private sub cmdscdemo2_click ()

TXTEDIT = "DIM LNGC" & VBCRLF

TXTEDIT = TXTEDIT & "LNGC = ClNG (fm.txtDemo.text)" & vbcrlf

TXTEDIT = TXTEDIT & "LNGC = LNGC 10" & vbcrlfxtXtedit = TXTEDIT & "IF LNGC> 255 THEN LNGC = 0" & VBCRLF

TXTEDIT = TXTEDIT & "FM.PICDemo.backcolor = RGB (LNGC, 0, 0)" & VBCRLF

TXTEDIT = TXTEDIT & "FM.TXTDEMO.TEXT = CSTR (LNGC)" & VBCRLF

End Sub

'********************************************************** ***********************

'** function name: Form_Load

'** → no

'** output: no

'** function description: initialization

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 11:13:03

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private sub flow_load ()

'Adding parameters to use the internal actual variable name externally

Sccommand.addObject "VM", Valmem, True

'Add external available objects to scripts

'Last parameters: true indicates that its subclass attribute method can operate in the script to indicate that the object itself can be used

Sccommand.addObject "FM", ME, TRUE

'Script running interval setting

CMBRUNTIME.LISTINDEX = 0

'Parameter operation type

CMBTYPE.LISTINDEX = 0

End Sub

'********************************************************** ***********************

'** function name: TMRRUN_TIMER

'** → no

'** output: no

'** function description: Script run

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 11:29:46

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Private Sub Tmrrun_timer ()

On Error Goto TOEXIT 'Open Error Trap

'--------------------------------------------------

DIM I as long

'Parameter input

Valmem.SetValue "Value1", TXTVALUE (0) .Text

Valmem.SetValue "Value2", TXTVALUE (1) .text

Valmem.SetValue "Value3", 0

'Script running

Sccommand.executestatement TXTEDIT.TEXT

'Parameter output

Lstvalueout.clear

For i = 1 to valmem.count

Lstvalueout.Additem Valmem.getValue (", i)

NEXT

'--------------------------------------------------

EXIT SUB

'----------------

TOEXIT:

TXTERROR = "error number:" & err.Number & "Time:" & Format (now, "YYYY-MM-DD HH: mm: SS") & vbcrlf

TXTERROR = TXTERROR & "Error Message:" & Err.Description & Vbrlf

TXTERROR = TXTERROR & "Error Source:" & Err.Source

End Sub

3, add a module (MDLBase), add the following code: '****************************************** ***********************************************

'** Module Name: MDLBase

'**: YFSoft copyright 2004 - 2005 (C)

'** created: Ye Fan

'** Japanese: 2004-10-15 11:10:58

'** modified:

'** date:

'** Description: Public variable area

'** version: v1.0.0

'********************************************************** ***********************

Option expedition

Public Valmem as new clsscriptio 'script language parameter exchange variable setting area 4, add a class (clsscriptio), class named Clsscriptio, add the following code:' *************** *********************************************************** *******

'** Module Name: Clsscriptio

'**: YFSoft copyright 2004 - 2005 (C)

'** created: Ye Fan

'** Japan: 2004-10-15 11:56:32

'** modified:

'** date:

'** Description: Class module with scripting language parameters

'** version: v1.0.0

'********************************************************** ***********************

Option expedition

Private CLTScriptMem As New Collection 'Variable Setup Area

'********************************************************** ***********************

'** function name: count

'** → no

'** Out: (Variant) -

'** function description: Memory variable

'** global variable:

'** call module:

'** author: Ye Fan

'** Japanese: 2004-10-15 12:00:57

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Public property get count () AS VARIANT

Count = CLTScriptMem.count

End Property

'********************************************************** ***********************

'** function name: getValue

'** input: strkey (string) - Variable name

'**: Optional LNGNO (long = 0) - Variable index

'** Out: (VARIANT) - Return Value

'** function description: Variable value for obtaining the name

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 12:01:59

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Public Function GetValue (StrKey As String, Optional LNGNO As long = 0) As Variant

On Error Goto TOEXIT 'Open Error Trap

'--------------------------------------------------

If LNGNO> 0 THEN 'If you enter an index number, return the variable specified by the index number.

GetValue = CLTScriptMem.Item (LNGNO)

Else

GetValue = CLTScriptMem.Item (StrKey)

END IF

'--------------------------------------------------

EXIT FUNCTION

'----------------

TOEXIT:

END FUNCTION

'********************************************************** ***********************

'** function name: setValue

'* 输 入: strkey (string) - Variable name

'**: Value (variant) - Set variables

'** output: no' ** function description: assignments for the specified variable

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 12:07:05

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Public SUB SETVALUE (StrKey As String, Value As Variant)

On Error Goto TOEXIT 'Open Error Trap

'--------------------------------------------------

CLTScriptMem.Remove (strkey)

CLTScriptMem.Add Value, StrKey

'--------------------------------------------------

EXIT SUB

'----------------

TOEXIT:

Resume next

End Sub

'********************************************************** ***********************

'** function name: DelValue

'* 输 入: strkey (string) - Variable name

'**: OPTIONAL LNGNO (long = 0) - Index number

'** output: no

'** function description: Delete the set variable

'** global variable:

'** call module:

'** author: Ye Fan

'** Japan: 2004-10-15 12:08:55

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Public Sub Delvalue (StrKey As String, Optional LNGNO As long = 0)

On Error Goto TOEXIT 'Open Error Trap

'--------------------------------------------------

If LNGNO> 0 THEN 'If you enter an index number, delete the variable specified by the index number.

CLTScriptMem.Remove (LNGNO)

Else

CLTScriptMem.Remove (strkey)

END IF

'--------------------------------------------------

EXIT SUB

'----------------

TOEXIT:

End Sub

'********************************************************** ***********************

'** function name: Clear

'** → no

'** output: no

'** function description: Delete variable

'** global variable:' ** Call Module:

'** author: Ye Fan

'** Japan: 2004-10-15 13:15:15

'** modified:

'** date:

'** version: v1.0.0

'********************************************************** ***********************

Public Sub Clear ()

On Error Goto TOEXIT 'Open Error Trap

'--------------------------------------------------

While CLTScriptMem.count> 0

CLTScriptMem.Remove (1)

Wend

'--------------------------------------------------

EXIT SUB

'----------------

TOEXIT:

Resume next

End Sub

Function Demo: 1, Parameter Pass (click the [Transfer Parameter Demo] button to automatically add the corresponding script code. You can perform an additional and subtraction and division and other operations. The following image demonstrates the error capture (0 removal) 2, object operation (click [Object Operation Demo] button, automatically add the corresponding script code. You can perform the assignment of the control and background color change operation.

VBScript uses the ActiveX (R) script to dialogue with the host application. Using ActiveX Script, browser, and other host applications no longer need special integration code for each script. ActiveX scripts allow the host to compile Script, get and call the entry point and manage developers available namespace available. Through ActiveX Script, language vendors can establish standard script runtime language. Microsoft will provide VBScript runtime support.

转载请注明原文地址:https://www.9cbs.com/read-105894.html

New Post(0)