Option Strict Off Option Explicit On Friend Class p4comTestForm Inherits System.Windows.Forms.Form #Region "Windows Form Designer generated code " Public Sub New() MyBase.New() If m_vb6FormDefInstance Is Nothing Then If m_InitializingDefInstance Then m_vb6FormDefInstance = Me Else Try 'For the start-up form, the first instance created is the default instance. If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then m_vb6FormDefInstance = Me End If Catch End Try End If End If 'This call is required by the Windows Form Designer. InitializeComponent() End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean) If Disposing Then If Not components Is Nothing Then components.Dispose() End If End If MyBase.Dispose(Disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer Public ToolTip1 As System.Windows.Forms.ToolTip Public WithEvents cmdSubmit As System.Windows.Forms.Button Public WithEvents cmdEnv As System.Windows.Forms.Button Public WithEvents cmdClear As System.Windows.Forms.Button Public WithEvents cmdRun As System.Windows.Forms.Button Public WithEvents txtCmd As System.Windows.Forms.TextBox Public WithEvents ResultBox As System.Windows.Forms.ListBox Public WithEvents cmdClose As System.Windows.Forms.Button Public WithEvents Label2 As System.Windows.Forms.Label Public WithEvents Label1 As System.Windows.Forms.Label 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components) Me.cmdSubmit = New System.Windows.Forms.Button() Me.cmdEnv = New System.Windows.Forms.Button() Me.cmdClear = New System.Windows.Forms.Button() Me.cmdRun = New System.Windows.Forms.Button() Me.txtCmd = New System.Windows.Forms.TextBox() Me.ResultBox = New System.Windows.Forms.ListBox() Me.cmdClose = New System.Windows.Forms.Button() Me.Label2 = New System.Windows.Forms.Label() Me.Label1 = New System.Windows.Forms.Label() Me.SuspendLayout() ' 'cmdSubmit ' Me.cmdSubmit.BackColor = System.Drawing.SystemColors.Control Me.cmdSubmit.Cursor = System.Windows.Forms.Cursors.Default Me.cmdSubmit.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdSubmit.Location = New System.Drawing.Point(336, 328) Me.cmdSubmit.Name = "cmdSubmit" Me.cmdSubmit.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdSubmit.Size = New System.Drawing.Size(97, 33) Me.cmdSubmit.TabIndex = 8 Me.cmdSubmit.Text = "S&ubmit" ' 'cmdEnv ' Me.cmdEnv.BackColor = System.Drawing.SystemColors.Control Me.cmdEnv.Cursor = System.Windows.Forms.Cursors.Default Me.cmdEnv.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdEnv.Location = New System.Drawing.Point(224, 328) Me.cmdEnv.Name = "cmdEnv" Me.cmdEnv.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdEnv.Size = New System.Drawing.Size(97, 33) Me.cmdEnv.TabIndex = 7 Me.cmdEnv.Text = "&Env" ' 'cmdClear ' Me.cmdClear.BackColor = System.Drawing.SystemColors.Control Me.cmdClear.Cursor = System.Windows.Forms.Cursors.Default Me.cmdClear.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdClear.Location = New System.Drawing.Point(8, 88) Me.cmdClear.Name = "cmdClear" Me.cmdClear.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdClear.Size = New System.Drawing.Size(97, 33) Me.cmdClear.TabIndex = 6 Me.cmdClear.Text = "Clear" ' 'cmdRun ' Me.cmdRun.BackColor = System.Drawing.SystemColors.Control Me.cmdRun.Cursor = System.Windows.Forms.Cursors.Default Me.cmdRun.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdRun.Location = New System.Drawing.Point(112, 328) Me.cmdRun.Name = "cmdRun" Me.cmdRun.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdRun.Size = New System.Drawing.Size(97, 33) Me.cmdRun.TabIndex = 4 Me.cmdRun.Text = "&Run" ' 'txtCmd ' Me.txtCmd.AcceptsReturn = True Me.txtCmd.AutoSize = False Me.txtCmd.BackColor = System.Drawing.SystemColors.Window Me.txtCmd.Cursor = System.Windows.Forms.Cursors.IBeam Me.txtCmd.ForeColor = System.Drawing.SystemColors.WindowText Me.txtCmd.Location = New System.Drawing.Point(112, 8) Me.txtCmd.MaxLength = 0 Me.txtCmd.Name = "txtCmd" Me.txtCmd.RightToLeft = System.Windows.Forms.RightToLeft.No Me.txtCmd.Size = New System.Drawing.Size(385, 25) Me.txtCmd.TabIndex = 1 Me.txtCmd.Text = "info" ' 'ResultBox ' Me.ResultBox.BackColor = System.Drawing.SystemColors.Window Me.ResultBox.Cursor = System.Windows.Forms.Cursors.Default Me.ResultBox.ForeColor = System.Drawing.SystemColors.WindowText Me.ResultBox.Location = New System.Drawing.Point(112, 48) Me.ResultBox.Name = "ResultBox" Me.ResultBox.RightToLeft = System.Windows.Forms.RightToLeft.No Me.ResultBox.Size = New System.Drawing.Size(489, 264) Me.ResultBox.TabIndex = 3 ' 'cmdClose ' Me.cmdClose.BackColor = System.Drawing.SystemColors.Control Me.cmdClose.Cursor = System.Windows.Forms.Cursors.Default Me.cmdClose.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.cmdClose.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdClose.Location = New System.Drawing.Point(448, 328) Me.cmdClose.Name = "cmdClose" Me.cmdClose.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdClose.Size = New System.Drawing.Size(97, 33) Me.cmdClose.TabIndex = 5 Me.cmdClose.Text = "Close" ' 'Label2 ' Me.Label2.BackColor = System.Drawing.SystemColors.Control Me.Label2.Cursor = System.Windows.Forms.Cursors.Default Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText Me.Label2.Location = New System.Drawing.Point(8, 8) Me.Label2.Name = "Label2" Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label2.Size = New System.Drawing.Size(65, 25) Me.Label2.TabIndex = 0 Me.Label2.Text = "P4 cmd to execute:" Me.Label2.TextAlign = System.Drawing.ContentAlignment.TopRight ' 'Label1 ' Me.Label1.BackColor = System.Drawing.SystemColors.Control Me.Label1.Cursor = System.Windows.Forms.Cursors.Default Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText Me.Label1.Location = New System.Drawing.Point(40, 48) Me.Label1.Name = "Label1" Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label1.Size = New System.Drawing.Size(65, 25) Me.Label1.TabIndex = 2 Me.Label1.Text = "Result:" Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopRight ' 'p4comTestForm ' Me.AcceptButton = Me.cmdRun Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.CancelButton = Me.cmdClose Me.ClientSize = New System.Drawing.Size(638, 376) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdSubmit, Me.cmdEnv, Me.cmdClear, Me.cmdRun, Me.txtCmd, Me.ResultBox, Me.cmdClose, Me.Label2, Me.Label1}) Me.Location = New System.Drawing.Point(4, 23) Me.Name = "p4comTestForm" Me.Text = "Test p4 from vb" Me.ResumeLayout(False) End Sub #End Region #Region "Upgrade Support " Private Shared m_vb6FormDefInstance As p4comTestForm Private Shared m_InitializingDefInstance As Boolean Public Shared Property DefInstance() As p4comTestForm Get If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then m_InitializingDefInstance = True m_vb6FormDefInstance = New p4comTestForm() m_InitializingDefInstance = False End If DefInstance = m_vb6FormDefInstance End Get Set m_vb6FormDefInstance = Value End Set End Property #End Region '******************************************************************************* ' ' Copyright (c) 2003, Robert Cowham and Vaccaperna Systems Ltd. All rights reserved. ' ' Redistribution and use in source and binary forms, with or without ' modification, are permitted provided that the following conditions are met: ' ' 1. Redistributions of source code must retain the above copyright ' notice, this list of conditions and the following disclaimer. ' ' 2. Redistributions in binary form must reproduce the above copyright ' notice, this list of conditions and the following disclaimer in the ' documentation and/or other materials provided with the distribution. ' ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ' ARE DISCLAIMED. IN NO EVENT SHALL VACCAPERNA SYSTEMS LTD. BE LIABLE FOR ANY ' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ' ' ******************************************************************************* ' ' Name: p4comtestform.frm ' ' Author: Robert Cowham ' ' Description: ' Very simple demo of p4com - COM interface to Perforce. ' ' Executes any command which the users types in txtCmd and puts the results ' into the ResultBox. ' ' Please note that there is no real error handling. ' ****************************************************************************** Dim OutputArr() As String Dim WarningArr() As String Dim ErrorArr() As String Dim m_p4 As P4COM.p4 Private Sub cmdClose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClose.Click Me.Close() End Sub Private Sub cmdEnv_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEnv.Click EnvForm.DefInstance.ShowEnv(m_p4) End Sub Private Sub cmdRun_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRun.Click On Error GoTo error_Block Dim Result As Integer m_p4.Connect() m_p4.ExceptionLevel = 1 OutputArr = m_p4.run(txtCmd.Text) DisplayResult() m_p4.Disconnect() Exit Sub error_Block: MsgBox("Error: " & Err.Number & vbCrLf & Err.Description) End Sub Private Sub DisplayResult() ResultBox.Items.Add("Cmd:" & txtCmd.Text) WarningArr = VB6.CopyArray(m_p4.Warnings) ErrorArr = VB6.CopyArray(m_p4.Errors) DisplayArrayOpt("Output:", OutputArr) DisplayArrayOpt("Warnings:", WarningArr) DisplayArrayOpt("Errors:", ErrorArr) If Len(m_p4.TempFilename) > 0 Then ResultBox.Items.Add("TempFilename:" & m_p4.TempFilename) End If ResultBox.Items.Add(" ") End Sub Private Sub DisplayArray(ByVal msg As String, ByRef arr() As String) Dim i As Short ResultBox.Items.Add(msg) For i = LBound(arr) To UBound(arr) ResultBox.Items.Add(arr(i)) Next End Sub Private Sub DisplayArrayOpt(ByVal msg As String, ByRef arr() As String) Dim i As Short If UBound(arr) >= LBound(arr) Then DisplayArray(msg, arr) End If End Sub Private Sub cmdSubmit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSubmit.Click SubmitForm.DefInstance.DoSubmit(m_p4) m_p4 = New P4COM.p4() End Sub Private Sub cmdClear_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClear.Click ResultBox.Items.Clear() End Sub Private Sub p4comTestForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load m_p4 = New P4COM.p4() End Sub End Class