VERSION 5.00 Begin VB.Form ConnectForm Caption = "P4OFC - Connecting..." ClientHeight = 1860 ClientLeft = 60 ClientTop = 405 ClientWidth = 6750 ClipControls = 0 'False ControlBox = 0 'False LinkTopic = "Form1" ScaleHeight = 1860 ScaleWidth = 6750 StartUpPosition = 1 'CenterOwner Begin VB.CommandButton cmdCancel Cancel = -1 'True Caption = "Cancel Operation" Default = -1 'True Height = 375 Left = 2400 TabIndex = 2 Top = 1320 Width = 1935 End Begin VB.TextBox txtPort Enabled = 0 'False Height = 375 Left = 2760 TabIndex = 1 Top = 240 Width = 3255 End Begin VB.Label ConnectingStatus Alignment = 2 'Center Caption = "Connecting..." BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 240 TabIndex = 3 Top = 840 Width = 5775 End Begin VB.Label Label1 Caption = "Connecting to Perforce server:" Height = 375 Left = 240 TabIndex = 0 Top = 240 Width = 2775 End End Attribute VB_Name = "ConnectForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private m_result As String Private m_finished As Boolean Private m_timer_count As Integer Private m_Launcher As LaunchP4Connect Private WithEvents m_Timer As CTimer Attribute m_Timer.VB_VarHelpID = -1 Private Const cTimeInterval = 200 ' milliseconds Private Const cDisplayFormTimerCount = 3 ' number of counts to wait before showing form (x above interval) Private Sub cmdCancel_Click() On Error GoTo Error_Block Dim T As Tracker: Set T = GStackTrace.Enter(TypeName(Me), "cmdCancel_Click") Dim InfoArr() As String Dim ErrorArr() As String m_Timer.Interval = 0 Me.Hide ResultForm.DisplayResult Me.Caption, "", 1, InfoArr, ErrorArr Exit Sub Error_Block: T.Report End Sub Public Function Connect() As Boolean Dim T As Tracker: Set T = GStackTrace.Enter(TypeName(Me), "Connect") Dim p4 As P4COM.p4 If InIDE() Then ' Can't spawn threads when running interactively for debug Connect = True Exit Function End If m_finished = False m_timer_count = 0 Set p4 = NewP4 txtPort.Text = p4.port Screen.MousePointer = vbDefault If GStacker.Tracing Then GStacker.TraceMsg "ConnectForm: ThreadStarted" End If Set m_Launcher = New LaunchP4Connect m_Launcher.LaunchThreads Set m_Timer = New CTimer m_Timer.Interval = cTimeInterval SetParent Me, g_p4interface.App.Caption ShowForm If m_result = "Success" Then Connect = True End If ' Just let the thread finish by itself which it will ' m_Launcher.FinishThreads Set m_Launcher = Nothing Unload Me End Function ' Show form in modal way or approximate it Private Sub ShowForm() Dim T As Tracker: Set T = GStackTrace.Enter(TypeName(Me), "ShowForm") ' Loop waiting for timer event handler to indicate being finished Me.Hide While Not m_finished Sleep cTimeInterval DoEvents Wend End Sub ' This fires when timer goes off Private Sub m_Timer_ThatTime() On Error GoTo Error_Block Dim T As Tracker: Set T = GStackTrace.Enter(TypeName(Me), "m_Timer_ThatTime") m_Timer.Interval = 0 ' Turn ourselves off - only want to fire once m_timer_count = m_timer_count + 1 ConnectingStatus.Caption = ConnectingStatus.Caption & "." If Not m_Launcher Is Nothing Then If m_Launcher.ThreadFinished(m_result) Then If GStacker.Tracing Then GStacker.TraceMsg "ConnectForm: ThreadFinished: " & m_result End If m_finished = True Me.Hide Else m_Timer.Interval = cTimeInterval If m_timer_count = cDisplayFormTimerCount Then ' Finally show the form after n times of timer firing Me.Show vbModal m_finished = True End If End If Else m_finished = True Me.Hide End If Exit Sub Error_Block: If err.Description <> "Method '~' of object '~' failed" Then T.Report End If End Sub