| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 812 人关注过本帖
标题:关于字符串和对象的问题~
只看楼主 加入收藏
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
回复 7楼 不说也罢
看起来感觉好像可以~
只是现在下班到家了~
代码忘了带走遗留在公司~
要明天才能试~
先谢了~

不要選我當版主
2011-07-06 21:25
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
回复 9楼 不说也罢
嗯~你打字好快 = =.

不要選我當版主
2011-07-06 21:26
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:20 
这里给你写一个通用函数吧。你应当能做到的呀
程序代码:
Private Sub Command1_Click()
    LoadTheForm "Form2" '调用通用的过程加载窗体。最好注意大小写
End Sub

Public Sub LoadTheForm(ByVal FormName As String)
   Dim MyFrm As Form
   Set MyFrm = Forms.Add(FormName)
   MyFrm.Show
End Sub



[ 本帖最后由 不说也罢 于 2011-7-6 21:32 编辑 ]

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2011-07-06 21:31
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
回复 10楼 不说也罢
我明天会贴上来~

LoadCompareData()整段函式~其实只是读取INI的资料用的~
再把读到的值写到控件上而已~只是我没用API去做~
因为不太熟API自己写比较保险点~哈....

不要選我當版主
2011-07-06 21:33
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
回复 13楼 不说也罢
太感谢了....已经可以直接结案了~

不要選我當版主
2011-07-06 21:35
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
回复 15楼 wube
不要客气。共同提高。我已经注意到你也是很乐意帮助别人的。

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2011-07-06 21:40
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
解決了~

'入口表单的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 编辑 ]

不要選我當版主
2011-07-07 23:12
快速回复:关于字符串和对象的问题~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.088602 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved