使用msscript控件可以调用vbs和js的过程,计算其表达式

解决方案 »

  1.   

    ScriptControl Object
    引用 Microsoft Script Control 1.0
      

  2.   


    Dim moScript As MSScriptControl.ScriptControl
    Set moScript = New MSScriptControl.ScriptControl
    moscript.language="JavaScript" 'or "VBScript"
    msgbox moScript.Eval("escape('a')")
      

  3.   


    Dim moScript As MSScriptControl.ScriptControl
    Set moScript = New MSScriptControl.ScriptControl
    moscript.language="JavaScript" 'or "VBScript"
    msgbox moScript.Eval("escape('a')")
      

  4.   

    Dim Adsffsd As String
    Adsffsd = "45345634534565  fd"Text2.Text = ScriptControl1.Eval("escape(Adsffsd)")显示“Adsffsd 未定义”
    错在哪了?
      

  5.   

    因為你定義的變量Adsffsd不是在javascript中定義的
    修正如下:Dim Adsffsd As String
    Adsffsd = "45345634534565  fd"ScriptControl1.AddCode ("Adsffsd = '45345634534565  fd'")
    Text2.Text = ScriptControl1.Eval("escape(Adsffsd)")
    試一試!應該沒有問題.
      

  6.   

    '這個程式需要2個Command,3個TextBox
    Option Explicit
    Private Const MAX_PATH As Long = 260
    Private Const ERROR_SUCCESS As Long = 0Private Const URL_DONT_ESCAPE_EXTRA_INFO As Long = &H2000000
    'Don't convert the # or ? character, or any characters following them in the string.
    Private Const URL_ESCAPE_SPACES_ONLY As Long = &H4000000
    'Only escape space characters. This flag cannot be combined with URL_ESCAPE_PERCENT or URL_ESCAPE_SEGMENT_ONLY
    Private Const URL_ESCAPE_SEGMENT_ONLY As Long = &H2000
    'Escape the sections following the server component, but not the extra information sections following a # or ? character.
    Private Const URL_ESCAPE_PERCENT As Long = &H1000
    'Escape the % character. By default, this character is not escapedPrivate Const URL_UNESCAPE_INPLACE As Long = &H100000
    'Use pszURL to return the converted string instead of pszUnescaped.
    Private Const URL_INTERNAL_PATH As Long = &H800000Private Declare Function UrlEscape Lib "shlwapi" Alias "UrlEscapeA" (ByVal pszURL As String, ByVal pszEscaped As String, pcchEscaped As Long, ByVal dwFlags As Long) As Long
    Private Declare Function UrlUnescape Lib "shlwapi" Alias "UrlUnescapeA" (ByVal pszURL As String, ByVal pszUnescaped As String, pcchUnescaped As Long, ByVal dwFlags As Long) As Long
    Private Sub Form_Load()
    Text1.Text = "http://vbnote.cjb.net/s o m t t e x t h e r e.html"
    Text2.Text = ""
    Text3.Text = ""
    Command1.Caption = "去除空白"
    Command2.Caption = "回復空白"
    End Sub
    Private Sub Command1_Click()
    Dim SUrl As String, dwSize As Long
    Dim sUrlEsc As StringSUrl = Text1.Text
    sUrlEsc = Space(MAX_PATH)
    dwSize = Len(sUrlEsc)UrlEscape SUrl, sUrlEsc, dwSize, URL_ESCAPE_SPACES_ONLYsUrlEsc = Left(sUrlEsc, dwSize)Text2.Text = sUrlEsc
    End SubPrivate Sub Command2_Click()
    Dim sUrlEsc As String, dwSize As Long
    Dim sUrlUnEsc As String
    sUrlEsc = Text2.Text
    sUrlUnEsc = Space(MAX_PATH)
    dwSize = Len(sUrlUnEsc)
    UrlUnescape sUrlEsc, sUrlUnEsc, dwSize, URL_INTERNAL_PATH
    sUrlUnEsc = Left(sUrlUnEsc, dwSize)
    Text3.Text = sUrlUnEsc
    End Sub