Skip to content

cPLI Methods Reference

🚀 Core Methods

Request

Calls external program and returns result.

vb
Public Function Request(ParamArray Data() As Variant) As String

Parameters:

  • Data() - Variable parameter array, all parameters will be passed to external program after Base64 + UTF-8 encoding

Returns: External program's standard output content

Exceptions:

  • 404 - VBMAN.PLI file not found
  • Timeout error - Execution time exceeds TimeOut setting

Example:

vb
Dim PLI As New cPLI
Dim result As String

' No parameter call
result = PLI.Request()

' Single parameter call
result = PLI.Request("hello")

' Multiple parameter call
result = PLI.Request("param1", "param2", "param3")

' Pass complex data
result = PLI.Request("user", "123", "{\"action\":\"login\"}")

⚙️ Configuration Properties

TimeOut

Command execution timeout (milliseconds).

vb
Public TimeOut As Long

Default: 30000 (30 seconds)

Example:

vb
Dim PLI As New cPLI

' Set 10 second timeout
PLI.TimeOut = 10 * 1000

' Set 5 minute timeout (long task)
PLI.TimeOut = 5 * 60 * 1000

' Set 1 second timeout (quick check)
PLI.TimeOut = 1000

Dim result As String
result = PLI.Request("long-task")

📋 Complete Usage Examples

Call Python Script

Assuming VBMAN.PLI is a Python packaged executable:

python
# Python side code example (VBMAN.PLI)
import sys
import base64

def main():
    # Decode parameters
    args = sys.argv[1:]
    decoded_args = [base64.b64decode(arg).decode('utf-8') for arg in args]
    
    # Process data
    action = decoded_args[0]
    data = decoded_args[1]
    
    if action == "process":
        result = process_data(data)
        print(result)
    elif action == "analyze":
        result = analyze_data(data)
        # Write large result to file
        with open("VBMAN.DAT", "w") as f:
            f.write(result)
        print("VBMAN.DAT")  # Return filename
    
def process_data(data):
    # Processing logic
    return f"Processed: {data}"

def analyze_data(data):
    # Analysis logic
    return f"Analysis result for: {data}"

if __name__ == "__main__":
    main()
vb
' VB6 call side
Private Sub CallPython()
    Dim PLI As New cPLI
    Dim result As String
    
    ' Simple call
    result = PLI.Request("process", "some data")
    Debug.Print result  ' Output: Processed: some data
    
    ' Long task
    PLI.TimeOut = 60 * 1000  ' 1 minute
    result = PLI.Request("analyze", "large dataset")
    Debug.Print result  ' May return "VBMAN.DAT"
End Sub

JSON Data Exchange

vb
Private Sub ExchangeJSON()
    Dim PLI As New cPLI
    Dim jsonSend As New cJson
    Dim jsonRecv As New cJson
    
    ' Build request data
    jsonSend.AddItem "action", "calculate"
    jsonSend.AddItem "num1", 100
    jsonSend.AddItem "num2", 200
    
    ' Call external program
    Dim result As String
    result = PLI.Request(jsonSend.Encode())
    
    ' Parse return result
    jsonRecv.Decode result
    
    If jsonRecv.GetItem("success") = True Then
        Debug.Print "Result: " & jsonRecv.GetItem("result")
    Else
        Debug.Print "Error: " & jsonRecv.GetItem("error")
    End If
End Sub

Error Handling

vb
Private Sub SafeCall()
    Dim PLI As New cPLI
    
    On Error GoTo ErrorHandler
    
    Dim result As String
    result = PLI.Request("risky-operation")
    
    Debug.Print "Success: " & result
    Exit Sub
    
ErrorHandler:
    Select Case Err.Number
        Case 404
            MsgBox "PLI program not found, please check installation"
        Case Else
            If Err.Description Like "*timeout*" Then
                MsgBox "Operation timeout, please retry"
            Else
                MsgBox "Error: " & Err.Number & " - " & Err.Description
            End If
    End Select
End Sub

File Processing

vb
Private Sub ProcessFile()
    Dim PLI As New cPLI
    
    ' Pass file path
    Dim filePath As String
    filePath = "C:\data\input.csv"
    
    Dim result As String
    result = PLI.Request("convert", filePath, "json")
    
    ' Check if returned file
    If result = "VBMAN.DAT" Then
        ' Read returned data file
        Dim output As String
        output = ToolsStream.LoadFileAsText(App.Path & "\VBMAN.DAT")
        
        ' Delete temp file after processing
        Kill App.Path & "\VBMAN.DAT"
        
        Debug.Print "Processing result: " & output
    Else
        Debug.Print "Direct return: " & result
    End If
End Sub

  • cSTDIO - Standard input/output execution component
  • ToolsBase64 - Base64 encoding utility
  • ToolsStream - File stream operation utility

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation