在VB程式設計中,假設三個變數文字框A,B,C
我該如何寫才能讓使用者自行設定三個的公式關係並求出答案呢?
如使用者可設 A B C或A*(B C).......等
就如同Excel的公式設定一般?
2005-12-07 11:04:53 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
謝謝您!一個我未曾想過的解決方案!不過可否告知ScriptControl的相關可查訊資訊呢(VB的MSDN好像找不到)?
2005-12-08 08:27:01 · update #1
說明檔查到嚕!謝謝
2005-12-08 08:50:54 · update #2
'設置4個TextBox 命名為 Text1,TextA,TextB,TextC,及1個CommandButton
Private Sub Command1_Click()
Dim Sc As Object, M As Object, S As String
Set Sc = CreateObject("ScriptControl")
Sc.Language = "VBScript"
Sc.AllowUI = True
Set M = Sc.Modules.Add("Module1")
S = "(TextA + TextB) * TextC"
Text1 = S: TextA = 1: TextB = 2: TextC = 3
MsgBox "輸入Text1內容為: " & S
S = Replace(S, "TextA", TextA, , , 1)
S = Replace(S, "TextB", TextB, , , 1)
S = Replace(S, "TextC", TextC, , , 1)
MsgBox "計算式:(TextA + TextB) * TextC = " & M.Eval(S)
S = "TextA = TextB + TextC": TextA = ""
Text1 = S
MsgBox "輸入Text1內容為: " & S
S = Replace(S, "TextB", TextB, , , 1)
S = Replace(S, "TextC", TextC, , , 1)
M.ExecuteStatement S
TextA = M.Eval(TextA.Name)
Set Sc = Nothing
End Sub
2005-12-07 15:31:45 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋