VERSION 5.00
Begin VB.Form p4comTestForm
Caption = "Test p4 from vb"
ClientHeight = 5670
ClientLeft = 60
ClientTop = 345
ClientWidth = 12000
LinkTopic = "Form1"
ScaleHeight = 5670
ScaleWidth = 12000
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdJobSpec
Caption = "&Jobspec"
Height = 495
Left = 6720
TabIndex = 9
Top = 4920
Width = 1455
End
Begin VB.CommandButton cmdSubmit
Caption = "S&ubmit"
Height = 495
Left = 5040
TabIndex = 8
Top = 4920
Width = 1455
End
Begin VB.CommandButton cmdEnv
Caption = "&Env"
Height = 495
Left = 3360
TabIndex = 7
Top = 4920
Width = 1455
End
Begin VB.CommandButton cmdClear
Caption = "Clear"
Height = 495
Left = 120
TabIndex = 6
Top = 1320
Width = 1455
End
Begin VB.CommandButton cmdRun
Caption = "&Run"
Default = -1 'True
Height = 495
Left = 1680
TabIndex = 4
Top = 4920
Width = 1455
End
Begin VB.TextBox txtCmd
Height = 375
Left = 1680
TabIndex = 1
Text = "info"
Top = 120
Width = 5775
End
Begin VB.ListBox ResultBox
Height = 3960
ItemData = "p4comTestForm.frx":0000
Left = 1680
List = "p4comTestForm.frx":0002
TabIndex = 3
Top = 720
Width = 8895
End
Begin VB.CommandButton cmdClose
Cancel = -1 'True
Caption = "Close"
Height = 495
Left = 8520
TabIndex = 5
Top = 4920
Width = 1455
End
Begin VB.Label Label2
Alignment = 1 'Right Justify
Caption = "P4 cmd to execute:"
Height = 375
Left = 120
TabIndex = 0
Top = 120
Width = 975
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Result:"
Height = 375
Left = 600
TabIndex = 2
Top = 720
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 <robert@vaccaperna.co.uk>
'
' 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 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
OutputArr = m_p4.run(txtCmd.Text)
DisplayResult
m_p4.Disconnect
Exit Sub
Error_Block:
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
DisplayResult
End Sub
Private Sub DisplayResult()
ResultBox.AddItem "Cmd:" & txtCmd.Text
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
Dim j As Integer
Dim lines() As String
ResultBox.AddItem msg
For i = LBound(arr) To UBound(arr)
lines = Split(arr(i), vbLf)
For j = 0 To UBound(lines)
ResultBox.AddItem lines(j)
Next
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()
Set m_p4 = New P4COM.p4
Set m_p4form = New P4COM.p4
m_p4.SetProtocol "api", "57"
m_p4form.SetProtocol "api", "57"
m_p4.ExceptionLevel = 1
m_p4form.ExceptionLevel = 1
m_p4form.ParseForms ' For use with -o/-i commands.
End Sub
Private Sub TestJobSpec()
Dim output() As String
m_p4form.Connect
output = m_p4form.run("jobspec -o")
DisplayArray "Jobspec output", output
output = m_p4form.ArrayVar("Fields")
DisplayArray "Fields", output
End Sub
Private Sub cmdJobSpec_Click()
TestJobSpec
End Sub