Consegui criar um comando simples no AS400 gravando algumas macros do AS400 e adicionando alguns códigos através do arquivo .ebs. Ele estava funcionando bem quando eu estava usando, mas quando ele foi aplicado a 10 usuários, ele geralmente mostra um erro dizendo, "Alguém está trabalhando em 'J: \ AS400 Automation \ tk.csv' agora. Por favor, tente novamente mais tarde. "
Abaixo está o código que eu fiz:
'----------------------------------------------------------------------
' This macro was created by the macro recorder.
' Macro File: \******\****\Global\AS400 Automation\TKFinder.ebs
' Date: Thu Sep 20 07:01:38 2018
' Recorded for profile: N***e*n AS400 S1
'----------------------------------------------------------------------
Function requestData(connStr As String, sqlStr As String)
' returns the result of the data.
' use isempty(requestData) to identify if the request has result or none
Dim xlCon As Object
Dim xlRs As Object
Dim rsData As Variant
Set xlCon = CreateObject("ADODB.Connection")
Set xlRs = CreateObject("ADODB.Recordset")
xlCon.Mode = 1 ' adModeRead / Indicates read-only permissions.
xlCon.Open connStr ' open the csv database
xlRs.LockType = 1 ' adLockReadOnly / Indicates read-only records. You cannot alter the data.xlRs.Open sqlStr, xlCon ' send query
xlRs.Open sqlStr, xlCon
If Not xlRs.EOF Then
' execute only if there is record found in the query
if isnull(xlRs.Fields.item(0).value) then
msgbox "No requirement."
else
msgbox xlRs.Fields.item(0).value
end if
Else
msgbox "Query not found."
End If
xlRs.Close
xlCon.Close
Set xlRs = Nothing
Set xlCon = Nothing
End Function
Sub Main
Dim HostExplorer as Object
Dim MyHost as Object
Dim Rc as Integer
On Error goto GenericErrorHandler
Set HostExplorer = CreateObject("HostExplorer") ' Initialize HostExplorer Object
Set MyHost = HostExplorer.HostFromProfile("N***e*n AS400 S1") ' Set object for the desired session
If MyHost is Nothing Then Goto NoSession
If Not MyHost.Area(6,2,6,3).Value="SC" Then Exit Sub
On Error goto ShipperCodeError
Dim shipperCode As long
shipperCode = MyHost.Area(6,5,6,11).Value
shipperCode = trim(shipperCode)
Dim dbName As String, connStr As String, sqlStr As String
Dim leadData
dbpath = "J:\global\AS400 Automation"
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath & ";Extended Properties=""text;HDR=Yes;FMT=Delimited;"""
if isempty(shippercode) then exit sub
dbName = "tk.csv"
sqlStr = "SELECT Requirement " & _
"FROM [" & dbName & "] Where [Shipper Code] = " & shipperCode & ";"
requestData connStr, sqlStr
Exit Sub
'-------------------- Runtime Error Handlers --------------------
GenericErrorHandler:
Msgbox "Error " & Err & " : """ & Error(Err) & """ has occurred on line " & Erl-1 & "." & Chr(10) & "Unable to continue macro execution.", 16, "HostExplorer Basic Macro Error"
Exit Sub
ShipperCodeError:
Msgbox "Shipper code is empty."
Exit sub
NoSession:
Msgbox "Profile ""NewPenn AS400 S1"" is not running." & Chr(10) & "Unable to execute macro.", 16, "HostExplorer Macro Error"
Exit Sub
OnKeyboardError:
Msgbox "Unable to type string on host screen." & Chr(10) & "Unable to continue macro execution.", 16, "HostExplorer Basic Macro Error"
Exit Sub
End Sub
A macro foi atribuída a um comando de teclado e está funcionando bem até ser compartilhada com vários usuários.
Eu não sei como consertar o código desde que eu sou novo com o AS / 400 e SQL. O que devo fazer?