VERSION 5.00 Begin VB.Form p4comTestForm Caption = "Test p4 from vb" ClientHeight = 7335 ClientLeft = 60 ClientTop = 345 ClientWidth = 9570 LinkTopic = "Form1" ScaleHeight = 7335 ScaleWidth = 9570 StartUpPosition = 3 'Windows Default Begin VB.TextBox txtITem Height = 375 Left = 1680 ScrollBars = 1 'Horizontal TabIndex = 13 Top = 1080 Width = 7335 End Begin VB.CommandButton cmdBrowse Caption = "&Browse..." Height = 495 Left = 4560 TabIndex = 11 Top = 6720 Width = 1455 End Begin VB.TextBox txtInput Height = 375 Left = 1680 TabIndex = 3 Top = 600 Width = 7335 End Begin VB.ComboBox txtCmd Height = 315 Left = 1680 TabIndex = 1 Text = "info" Top = 120 Width = 7335 End Begin VB.CommandButton cmdSubmit Caption = "S&ubmit" Height = 495 Left = 6240 TabIndex = 9 Top = 6720 Width = 1455 End Begin VB.CommandButton cmdEnv Caption = "&Env" Height = 495 Left = 2880 TabIndex = 8 Top = 6720 Width = 1455 End Begin VB.CommandButton cmdClear Caption = "Clear" Height = 495 Left = 120 TabIndex = 6 Top = 2280 Width = 1455 End Begin VB.CommandButton cmdRun Caption = "&Run" Default = -1 'True Height = 495 Left = 1200 TabIndex = 7 Top = 6720 Width = 1455 End Begin VB.ListBox ResultBox Height = 4545 ItemData = "p4comTestForm.frx":0000 Left = 1680 List = "p4comTestForm.frx":0002 TabIndex = 5 Top = 1800 Width = 7335 End Begin VB.CommandButton cmdClose Cancel = -1 'True Caption = "Close" Height = 495 Left = 7920 TabIndex = 10 Top = 6720 Width = 1455 End Begin VB.Label Label4 Alignment = 1 'Right Justify Caption = "Curr item:" Height = 375 Left = 600 TabIndex = 12 Top = 1200 Width = 975 End Begin VB.Label Label3 Alignment = 1 'Right Justify Caption = "&Input:" Height = 375 Left = 360 TabIndex = 2 Top = 600 Width = 975 End Begin VB.Label Label2 Alignment = 1 'Right Justify Caption = "P4 &cmd to execute:" Height = 375 Left = 120 TabIndex = 0 Top = 120 Width = 1455 End Begin VB.Label Label1 Alignment = 1 'Right Justify Caption = "Result:" Height = 375 Left = 600 TabIndex = 4 Top = 1800 Width = 975 End End Attribute VB_Name = "p4comTestForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit '******************************************************************************* ' ' 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 Files() As String Dim m_p4 As P4COM.p4 Dim m_p4form As P4COM.p4 ' Note this will be used with ParseForms Private Sub cmdBrowse_Click() Dim dlg As P4Dialogs.OpenDepot Set dlg = New P4Dialogs.OpenDepot Dim FileTypes(1) As String FileTypes(0) = "All Word Files (*.doc;*.dot)" FileTypes(1) = "All Files (*.*)" ResultBox.AddItem "Selected file:" & dlg.run(0, FileTypes) End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdEnv_Click() EnvForm.ShowEnv m_p4 m_p4form.Charset = m_p4.Charset m_p4form.Client = m_p4.Client m_p4form.Cwd = m_p4.Cwd m_p4form.Host = m_p4.Host m_p4form.Language = m_p4.Language m_p4form.Password = m_p4.Password m_p4form.Port = m_p4.Port m_p4form.User = m_p4.User End Sub Private Sub cmdRun_Click() On Error GoTo Error_Block Dim Result As Long m_p4.Connect m_p4.SetProg "P4OFCTest" m_p4.SetVersion "Ver1.0" m_p4.Input = txtInput.Text OutputArr = m_p4.run(txtCmd.Text) DisplayResult txtCmd.Text CheckForLogin m_p4.Disconnect Exit Sub Error_Block: MsgBox "Error: " & Err.Number & vbCrLf & Err.Description DisplayResult txtCmd.Text End Sub Private Sub DisplayResult(cmd As String) Static AlreadyDone As Boolean If Not AlreadyDone Then ResultBox.AddItem "Server2:" & m_p4.ServerVersion End If ResultBox.AddItem "Cmd:" & cmd WarningArr = m_p4.Warnings ErrorArr = m_p4.Errors DisplayArrayOpt "Output:", OutputArr DisplayArrayOpt "Warnings:", WarningArr DisplayArrayOpt "Errors:", ErrorArr If Len(m_p4.TempFilename) > 0 Then ResultBox.AddItem "TempFilename:" & m_p4.TempFilename End If ResultBox.AddItem " " End Sub Private Sub DisplayArray(ByVal msg As String, arr() As String) Dim i As Integer ResultBox.AddItem msg For i = LBound(arr) To UBound(arr) ResultBox.AddItem arr(i) Next End Sub Private Sub DisplayArrayOpt(ByVal msg As String, arr() As String) Dim i As Integer On Error Resume Next If UBound(arr) >= LBound(arr) Then DisplayArray msg, arr End If End Sub Private Sub cmdSubmit_Click() SubmitForm.DoSubmit m_p4form m_p4form.Disconnect End Sub Private Sub cmdClear_Click() ResultBox.Clear End Sub Private Sub Form_Load() ChDir "C:\bruno_ws" txtCmd.AddItem "login -s" txtCmd.AddItem "logout" txtCmd.AddItem "fstat //depot/main/jam/jam.c" Set m_p4 = New P4COM.p4 Set m_p4form = New P4COM.p4 m_p4.ExceptionLevel = 0 m_p4form.ExceptionLevel = 1 m_p4form.ParseForms ' For use with -o/-i commands. m_p4form.SetProtocol "api", "57" End Sub Private Sub CheckForLogin() Dim Result As Long Const LoginReqd = "Perforce password (P4PASSWD) invalid or unset." Dim Answer As VbMsgBoxResult ' Search for success string - if found then don't display results If Not IsEmptyArray(ErrorArr) Then Dim i As Integer i = LBound(ErrorArr) If (InStr(1, ErrorArr(i), LoginReqd) <> 0) Then If EnterPasswordForm.Answer(m_p4) = vbOK Then m_p4.Input = m_p4.Password OutputArr = m_p4.run("login") DisplayResult "login" End If End If End If End Sub Private Sub ResultBox_Click() txtITem.Text = ResultBox.List(ResultBox.ListIndex) End Sub