VBS中如何添加窗体

ybxyl ybxyl 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本人用一款叫 ansoft maxwell的 电磁场有限元计算软件 ,这个软件支持使用 VBS脚本 ,下面是这个软件一个脚本的代码 ,它的输入参数是用“Inputbox”函数传递进去的 ,本人想做一个界面 ,里面有文本框,在文本框里输入参数,从而替代原来脚本所使用的 “Inputbox”,不知道如何实现 ,想在这里问问大家,小弟先谢谢您的热心帮助了!


下面是这个脚本的源代码, 红色的部分,就是我要做个有文本框的界面的地方

Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
Set oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface")
Set oDesktop = oAnsoftApp.GetAppDesktop()
oDesktop.RestoreWindow
Set oProject = oDesktop.GetActiveProject()
Set oDesign = oProject.GetActiveDesign()
dim TimeSelect
dim TimeSelectSub
dim FileInc
Dim project_path
i = 0
j = 0
'find the directory where the vb script is located (Project Directory Location)
project_path = oProject.GetPath()
'Prompt User for Input Data
StartTimein = Inputbox("Enter the Starting Time (sec)" &chr(13) & "(as defined in Saved Fields)")
EndTimein = Inputbox("Enter the End Time (sec)" &chr(13) & "(as defined in Saved Fields)")
dtin = Inputbox("Enter the Time Step (sec)" &chr(13) & "(as defined in Saved Fields)")
NamedExpression = Inputbox("Enter the name of the Named Expression" &chr(13) & "(e.g. AverageLoss_1)")
TotalTimeSteps = (int(((EndTimein - StartTimein)/dtin)+1)*100)/100
TotalSteps_s = "FYI: The total number of Field Solutions used for Averaging is " & TotalTimeSteps &chr(13) &chr(13) & _
"Click OK to Continue, Hit Esc to interrupt script."
msgbox (TotalSteps_s)
StartTime=StartTimein*1e9 'Converts to ns for use in the Fields Calculator
EndTime=EndTimein*1e9
dt=dtin*1e9

Set oModule = oDesign.GetModule("FieldsReporter")
oModule.EnterQty "TotalLoss" 'Load Core Loss and Smooth it
oModule.CalcOp "Smooth"
For n = StartTime to EndTime Step dt
TimeSelect = n
TimeSelectSub = CStr(TimeSelect) & "ns"
i = 1+i
FileInc = i
Filename = "\Test_" & CStr(FileInc) & ".fld"
'Save Fields to a File in Fields Calculator
oModule.CalculatorWrite project_path & Filename, _
Array("Solution:=", "Setup1 : Transient"), _
Array("Time:=", TimeSelectSub)
Next

'ReLoad Saved Core Loss Fields and Add Fields together
j=j+1
FileInc = j
Filename = "\Test_" & CStr(FileInc) & ".fld"
oModule.CalculatorRead project_path & Filename, _
"Setup1 : Transient", "Fields", _
Array("Time:=", TimeSelectSub)
For j = 2 to i
FileInc = j
Filename = "\Test_" & CStr(FileInc) & ".fld"
oModule.CalculatorRead project_path & Filename, _
"Setup1 : Transient", "Fields", _
Array("Time:=", TimeSelectSub)
oModule.CalcOp "+"
Next

'Divide all fields by total number of ouput field results, i
oModule.EnterScalar CStr(i)
oModule.CalcOp "/"
oModule.AddNamedExpression NamedExpression, "Fields"
msgbox ("The Script is Complete. " &chr(13) & _
"After selecting the geometry to plot the averaged field," &chr(13) & _
"the Named Expression can be selected under Field Overlays -> Fields -> Named Expressions.")

...全文
评论 20
收藏 已收藏
分享
返回顶部
ybxyl
VB基础类 7,788 成员 197,583 内容