解決了~
'入口表单的Form_Activate()事件
程序代码:
Private Sub Form_Activate()
Dim FileName As String, strCommandLine() As String
Dim ICType As String, MyForm As Form
If Command <> "" Then
AutoMode = True: Me.Hide
strCommandLine() = Split(Command, " ")
If UBound(strCommandLine) = 2 Then
If IsFileExist(strCommandLine(0)) = True And IsFileExist(strCommandLine(1)) = True And IsFileExist(strCommandLine(2)) = True Then
KTP_Path = Trim(strCommandLine(2)): XML_Path = Trim(strCommandLine(0)): LOG_Path = Trim(strCommandLine(1))
If InStr(KTP_Path, "\") <> 0 Then
ICType = Mid$(KTP_Path, InStrRev(KTP_Path, "\") + 1, Len(KTP_Path) - InStrRev(KTP_Path, "\") - Len(".KTP"))
Else
ICType = Mid$(KTP_Path, 1, InStr(KTP_Path, ".") - 1)
End If
Set MyForm = LoadTheForm(ICType) '重点在这行~获取到表单的Object后Assign给一个表单型态变量~此时会去运行指定表单的Form_Load()事件
'Call LoadCompareData(ICType, MyForm) '所以这行就不用写了~直接改到指定表单的Form_Load()事件里即可~
Else
MsgBox "FilePath Error !"
End If
End If
End If
If AutoMode = True Then Unload Me
End Sub
Private Function LoadTheForm(FormName As String) As Variant '只是为了这段~又学到一招~
Dim MyFrm As Form
Set MyFrm = Forms.Add("frm" & FormName)
Set LoadTheForm = MyFrm
End Function
'另一个表单的Form_Load()事件
程序代码:
Private Sub Form_Load()
If App.PrevInstance Then '避免程式执行两次以上
Call MsgBox("This program has been executed", vbCritical, "Warning")
End
End If
frmMain.Caption = frmMain.Caption & " Ver " & App.Major & "." & App.Minor & "." & App.Revision & ".16"
frmMain.Caption = frmMain.Caption & " 【 For " & ProductName & " 】 "
cmdOpenXMLFile.Enabled = False
cmdOpenDataLog.Enabled = False
CheFirst.Enabled = False
Info.Enabled = True: TexSiteNum.Locked = True
txtTargetPath.BackColor = &H80000005
LineCount.Text = 0 & " / " & 0
labProgressBar.Caption = ""
AutoMode = False
OutputTargetF = True
SetCurrentDirectory App.Path
ProgressBar1.Min = 0: ProgressBar1.Max = 100
ReDim ErrorData(0)
Call XDFProcess(False)
T_Coordinate.Enabled = True: ProductMode.Enabled = True: cmdExit.Enabled = True: Info.Enabled = True
If AutoMode = False Then Call LoadCompareData(ProductName, Me)
cmdOpenKTPFile.Enabled = True: ProgressBar1.Value = 100: ProgressBar1.ToolTipText = "[目前进度]"
If AutoMode = True Then Call AutoRunMode
End Sub
Private Function XDFProcess(Mode As Boolean) '流程控制区 + 变量初始化
If Mode = False Then
ProductMode.Enabled = False: T_Coordinate.Enabled = False: Info.Enabled = False: txtTargetPath.Locked = True
txtMaxBin.Locked = False: SetPass.Locked = True: cmdExit.Enabled = False: CheFirst.Enabled = False
ProgressBar1.Value = 0: LineCount.Text = 0 & " / " & 0: labPercent.Caption = "0 %"
cmdOpenKTPFile.Enabled = False: cmdOpenXMLFile.Enabled = False: cmdOpenDataLog.Enabled = False
ReDim ErrorData(0): ErrorCount = 0: ContactNumber = 0
ReDim ROMAX(2, 0): ReDim Path1(0): ReDim Path2(0)
txtTargetPath.BackColor = &H80000005: labProgressBar.Caption = "": cmdBower.Enabled = False
Else
ProductMode.Enabled = True: T_Coordinate.Enabled = True: Info.Enabled = True: txtTargetPath.Locked = False
txtMaxBin.Locked = False: SetPass.Locked = False: cmdExit.Enabled = True
ProgressBar1.Value = 100
cmdOpenKTPFile.Enabled = True: cmdOpenXMLFile.Enabled = True: cmdOpenDataLog.Enabled = True: cmdBower.Enabled = True
txtKTPFile.Text = "": txtXMLFile.Text = "": txtDataLog.Text = "": DataLogFilePath = "": DataLogFileName = ""
cmdExit.Enabled = True: cmdConvert.Enabled = False: cmdOpenXMLFile.Enabled = False: cmdOpenDataLog.Enabled = False
Erase Site, SoftBin, Path1, Path2, ROMAX, LogFileNameArray, ErrorData
ErrorCount = 0: ContactNumber = 0: LogCount = 0
XMLLotID = "": XMLSlotID = "": XMLTesterName = ""
txtTargetPath.BackColor = &H80000005: OutputTargetF = True
End If
End Function
'模块中的读取设定档功能
程序代码:
Public Function LoadCompareData(FileName As String, frm As Form) As Boolean '读取设定档资讯
Dim TempString As String, Temp As String, BuffTemp() As String
Dim FileNum As Integer, count As Integer, i As Integer
Dim UISETFlag As Boolean, CompareDataFlag As Boolean, ROMAXFlag As Boolean, LegendListFlag As Boolean
FileNum = FreeFile: FileName = App.Path & "\Library\" & FileName & ".dll": count = 0: TempString = ""
UISETFlag = False: CompareDataFlag = False: ROMAXFlag = False: LegendListFlag = False
Open FileName For Input As #FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, TempString
If TempString <> "" Then
If InStr(TempString, "<") <> 0 And InStr(TempString, ">") <> 0 Then
Temp = Mid(TempString, InStr(TempString, "<") + 1, InStr(TempString, ">") - InStr(TempString, "<") - 1)
Select Case Temp
Case "UISET"
UISETFlag = True: CompareDataFlag = False: ROMAXFlag = False: LegendListFlag = False
count = 0
Case "CompareData"
UISETFlag = False: CompareDataFlag = True: ROMAXFlag = False: LegendListFlag = False
count = 0
Case "ROMAX"
UISETFlag = False: CompareDataFlag = False: ROMAXFlag = True: LegendListFlag = False
count = 0
Case "LegendList"
UISETFlag = False: CompareDataFlag = False: ROMAXFlag = False: LegendListFlag = True
count = 0
End Select
End If
If UISETFlag = True Then
If InStr(TempString, "OperatingMode") <> 0 Then
If Len(TempString) > InStr(TempString, "=") Then
If Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")) = 0 Then
AutoMode = False '手动模式
Else
AutoMode = True '自动模式
End If
End If
ElseIf InStr(TempString, "UsePath") <> 0 Then
If Len(TempString) > InStr(TempString, "=") Then
If Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")) = 0 Then
UsePath = False '不写路径 = app.path
Else
UsePath = True '写路径
End If
End If
End If
If AutoMode = True Then
If InStr(TempString, "MaxBin") <> 0 Then
If Len(TempString) > InStr(TempString, "=") Then
frm.txtMaxBin.Text = Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "="))
End If
ElseIf InStr(TempString, "PassBin") <> 0 Then
If Len(TempString) > InStr(TempString, "=") Then
frm.SetPass.Text = Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "="))
End If
ElseIf InStr(TempString, "Target") <> 0 Then
If Len(TempString) > InStr(TempString, "=") Then
frm.txtTargetPath.Text = Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "="))
End If
ElseIf InStr(TempString, "T_Coordinate") <> 0 Then
If Len(TempString) > InStr(TempString, "=") Then
frm.T_Coordinate.Value = CInt(Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")))
End If
End If
End If
ElseIf CompareDataFlag = True Then
If InStr(TempString, "=") <> 0 And Len(TempString) > InStr(TempString, "=") Then
BuffTemp = Split(TempString, "=")
ReDim Preserve Path1(count): ReDim Preserve Path2(count)
Path1(count) = BuffTemp(0): Path2(count) = BuffTemp(1)
count = count + 1
Erase BuffTemp
End If
ElseIf ROMAXFlag = True Then
If InStr(TempString, ",") <> 0 And Len(TempString) > InStr(TempString, ",") Then
If Trim(TempString) <> "" Then
BuffTemp = Split(TempString, ",")
For i = 0 To 2
ReDim Preserve ROMAX(2, count)
ROMAX(i, count) = BuffTemp(i)
Next i
count = count + 1
End If
Erase BuffTemp
End If
ElseIf LegendListFlag = True Then
If InStr(TempString, "[") <> 0 And InStr(TempString, "]") <> 0 And InStr(TempString, "__") <> 0 Then
If Trim(TempString) <> "" Then
ReDim Preserve LegendList(count)
LegendList(count) = TempString
count = count + 1
End If
End If
End If
End If
Loop
Close #FileNum
End Function
贴的只是一小段(真的是很小一段)~主要只是关于从入口表单去呼叫工程中任一指定表单的代码实现过程~
P.S 但是这样搞也没办法完全获取到表单内的所有资讯~例如表单内定义的变量就无法取得~表单内定义的事件也无法取得~
不过山不转路转~路不转我转~改个方式就可以解决~只是有点遗憾~
[
本帖最后由 wube 于 2011-7-7 23:28 编辑 ]