⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6470.html

📁 VB技巧问答10000例,是一个教程
💻 HTML
字号:
<html>
  <head>
    <title>字串变数的????我大概解出来了喔!!</title>
  </head>
  <body bgcolor="#FFFFFF" vlink="#808080">
    <center>
      <h1>字串变数的????我大概解出来了喔!!</h1>
    </center>
<hr size=7 width=75%>

<hr size=7 width=75%><p>
Posted by <a href="mailto:phhuang@mail.systex.com.tw">小瓜呆</a> on October 14, 1998 at 15:34:04:<p>
In Reply to: <a href="6285.html">看了所有的讨论, 还是莫宰羊---字串变数的????</a> posted by 笨鸟而且慢飞 on October 07, 1998 at 01:02:40:<p>
里面有一些是微软站的资料!!供大家参考!!<br>Command4_click() 才是本题正解!!<p>Private Sub Command1_Click()<br>  Dim sc<br>  Dim strProgram As String<br>  strProgram = "Sub Main" & vbCrLf & _<br>  "MsgBox ""Hello World""" & vbCrLf & _<br>  "End Sub"<p>  Set sc = CreateObject("ScriptControl")<br>  sc.Language = "VBScript"<br>  sc.AddCode strProgram<br>  sc.Run "Main"<br>End Sub<p>Private Sub Command2_Click()<br>ScriptControl1.AllowUI = True<br>Dim strX As String<br>strX = "Sub Hello" & vbCrLf & _<br>       "MsgBox ""Hello World""" & vbCrLf & _<br>       "End Sub"<br>ScriptControl1.AddCode strX<br>ScriptControl1.Run "Hello" ' No UI allowed!<br>End Sub<p>Private Sub Command3_Click()<br>     MsgBox ("EvalFunc")<br>     EvalFunc<br>     MsgBox ("Try This")<br>     TryThis<br>   <br>     'MsgBox ("MyErr")<br>     'MyError<br>End Sub<p>Private Sub Command4_Click()<br>   <br> Para1 = """String1"""           '因为在 script control 内必须为字串<br> Para2 = """String2"""<br> With ScriptControl1<br>    .Language = "VBScript"<br>    .ExecuteStatement "Xstr1=" + Para1  ' 必须是 "Xstr1 = ""MyStr"" " 的型态<br>    .ExecuteStatement "Xstr2=" + Para2<br>   '.ExecuteStatement "test"<br>   '.ExecuteStatement "MsgBox AB"<br>   <br> End With<br> qq = ScriptControl1.Eval("Xstr1+Xstr2")<br> MsgBox qq<br>           <br>End Sub<br> <br>Private Sub command5_click()<br>  Dim strCode As String<br>  strX = "Sub SayHello" & vbCrLf & _<br>       "MsgBox ""Hello World""" & vbCrLf & _<br>       "End Sub"<br>       <br>  strCode = " Sub NameMe() " & vbCrLf & _<br>            " Dim strName As String " & vbCrLf & _<br>            " strName = InputBox(""Name?"")" & vbCrLf & _<br>            " MsgBox ""Your name is "" & strName " & vbCrLf & _<br>            "End Sub"<br>            <br>  ScriptControl1.Language = "VBScript"<br>  MsgBox strCode<br>  ScriptControl1.AddCode (strX)<br>  ScriptControl1.Run "SayHello"<br>  ScriptControl1.AddCode (strCode)     '不知问题在那里!!<br>  ScriptControl1.Run "NameMe"<br>End Sub<br> <br>Private Sub command6_click()<br>  ' The code is contained in the Textbox named<br>  ' txtScript on the form named frmScript.<br>  'ScriptControl1.AddCode myfrm.mytxt.Text<br>End Sub<p>'You can add arguments to a procedure or function.<p>Private Sub EvalFunc()<br>  ' Create the function.<br>  Dim strFunction As String<br>  strFunction = "Function ReturnThis(x, y)" & vbCrLf & _<br>                " ReturnThis = x * y" & vbCrLf & _<br>                "End Function"<br>  ' Add the code, then run the function.<br>  ScriptControl1.AddCode strFunction<br>  MsgBox ScriptControl1.Run("ReturnThis", 3, 25)<br>End Sub<p>'-----Run the Procedure<br>'The Run method runs any complete procedure that has been added to the Script Control. The following code fragment runs three defined procedures:<p>'ScriptControl1.Run "FindName"<br>'ScriptControl1.Run "AddName"<br>'ScriptControl1.Run "Quit"<br> <br>'-----Executing Scripting Statements and Evaluating the Results<p>'You can execute a scripting statement using the ExecuteStatement method. You can evaluate an expression using the eval method. In the following example, the ExecuteStatement method is used to assign the value 100 to variable x. The next two lines use the eval method to test the statements x = 100 and x = 100/2. The second line returns True; the third line returns False.<br>Private Sub TryThis()<br>  ScriptControl1.ExecuteStatement "x = 100"<br>  MsgBox ScriptControl1.Eval("x = 100")  ' True<br>  MsgBox ScriptControl1.Eval("x = 100/2")  ' False<br>End Sub<p>'-----sing the Error Property<p>'Script Control errors may come from two sources: the Script Control itself, or the script that the Control is attempting to run. To debug scripting code, use the Error property, which returns a reference to the Error object. Using the Error object, the Script Control can return the number and description of the error and also the line number where the error occurs in the script.<br>'Run the following code to see an example of the Script Control finding an error:<p>Private Sub MyError()<br>  ' The scripting code below divides by zero raising<br>  ' an error.<br>  Dim strCode As String<br>  strCode = "Sub DivideByZero()" & vbCrLf & _<br>            "Dim prime" & vbCrLf & _<br>            "prime = 3" & vbCrLf & _<br>            "MsgBox prime/0" & vbCrLf & _<br>            "End Sub"<br>  On Error GoTo scError<br>  With ScriptControl1<br>    .AddCode strCode<br>    .Run "DivideByZero"<br>  End With<br>  Exit Sub<br>scError:<br>  ' Use the Error object to inform the user of the<br>  ' error, and what line it occurred in.<br>  Debug.Print ScriptControl1.Error.Number & _<br>  ":" & ScriptControl1.Error.Description & _<br>  " in line " & ScriptControl1.Error.Line<br>  Exit Sub<br>End Sub<p><br>
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 6470-->
</ul><!--end: 6470-->
<br><hr size=7 width=75%><p>

</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -