Вы находитесь на странице: 1из 3

' Set-up the variables

Dim BaanObj As Object


Dim B_function As String
Dim B_function2 As String
Dim Query As String
Dim temp_string As String
Dim value_string As String
Dim query_id As Long
Dim RetVal As Long
Dim main_f$, Main_t$, sub_t$, sub_f$, comp$, file1$, file2$
Dim dllname As String
Dim dllfunction As String
Dim msg As String

Sub Run_function_server()
'
' Baseline Macro
'
Row = 2

dllname = "otisfcdll9475"
Sheets("Run Parameters").Activate
main_f = Sheets("Run Parameters").Cells(Row, 1)
Call open_baan
While main_f <> ""
' Read in DLL parameters and make sure it is text
comp$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 1) & Chr(34) & ","
main_f$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 2) & Chr(34) & ","
Main_t$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 3) & Chr(34) & ","
sub_f$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 4) & Chr(34) & ","
sub_t$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 5) & Chr(34) & ","
year_f = Sheets("Run Parameters").Cells(Row, 6) & ","
year_t = Sheets("Run Parameters").Cells(Row, 8) & ","
date_f = Sheets("Run Parameters").Cells(Row, 7) & ","
date_t = Sheets("Run Parameters").Cells(Row, 9) & ","
efficiency = Format(Sheets("Run Parameters").Cells(Row, 10), "####.00") &
","
salary_perc = Sheets("Run Parameters").Cells(Row, 11) & ","
file1$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 12) & Chr(34) & ","
' Input File
file2$ = Chr(34) & Sheets("Run Parameters").Cells(Row, 13) & Chr(34) & ","
' Report File
dllfunction = "sfcdll9475.process.records" & "("
dllfunction = dllfunction & comp$ ' Company
dllfunction = dllfunction & main_f$ ' main from
dllfunction = dllfunction & Main_t$ ' main to
dllfunction = dllfunction & sub_f$ ' sub from
dllfunction = dllfunction & sub_t$ ' sub to
dllfunction = dllfunction & year_f ' year from
dllfunction = dllfunction & year_t ' year to
dllfunction = dllfunction & date_f ' date from
dllfunction = dllfunction & date_t ' date to
dllfunction = dllfunction & efficiency ' Efficiency
dllfunction = dllfunction & salary_perc ' Salary Perc.
msg = "Start" + String(130, " ")
dllfunction = dllfunction & file1$ ' Input File
dllfunction = dllfunction & file2$ ' Report File
dllfunction = dllfunction & Chr(34) & msg & Chr(34) ' Report File
dllfunction = dllfunction & ")"
Call SendtoBAAN
strlen = Len(BaanObj.functioncall)
compos = InStr(1, BaanObj.functioncall, "commmsg:", 1)
msg = Mid(BaanObj.functioncall, compos + 8, strlen - 3)
msg = RTrim(Mid(msg, 1, Len(msg) - 2))
If (msg <> "Done") Then
MsgBox msg
End If
Row = Row + 1
main_f = Sheets(1).Cells(Row, 1)
Wend
Call close_baan

' Save as for the sub-totals


End Sub

'**********************************************************************************
*****
' Name : SendtoBaan
' Short Description : Send/Receive information to/from Baan
' Comments : Check if Baan is active otherwise connect to Baan
' send information to Baan with parseexecfunction
with 2 parameters
' a) dllname
' b) dllfunction (includes parameters)
' return information checked for errors and messages
displayed
' Also if a record has an error the error flag switch
is turned on
'**********************************************************************************
*****
'Sub SendtoBAAN(ByVal dllname As String, ByVal dllfunction As String)
Sub SendtoBAAN()
BaanObj.ParseExecFunction dllname, dllfunction
' check result
errormsg = ""
If BaanObj.Error <> 0 Then
Select Case BaanObj.Error
Case Is = -1
errormsg = "DLL Unknown"
Case Is = -2
errormsg = "Function Unknown"
Case Is = -3
errormsg = "Syntax Error in Function Call"
End Select
MsgBox ("Call to Baan DLL failed, error = " & errormsg)
close_baan
End If
returnvalue = Val(BaanObj.returnvalue)
Errorsw = False
If returnvalue = False Then
Errorsw = True
End If
Exit Sub
AutomationError:
MsgBox "Baan IV automation error: " & BaanObj.Error
End Sub
Sub open_baan()
' The DLL "ottdllsql_query" contains a function to convert this string to a Baan
query and
' other functions to parse and execute the query. The DLL also contains functions
to retrieve
' the result of the query, e.g. function "olesql_getstring".
On Error GoTo CannotCreateBaan

'My connection was Automatic since I changed a registry entry to


'run a different .bwc file.
'run Baan Application
Set BaanObj = CreateObject("Baan4.Application")
BaanObj.Timeout = 3600
On Error GoTo BaanAutomationError
Exit Sub

' error handling


CannotCreateBaan:
MsgBox "Unable to start Baan"
Exit Sub

BaanAutomationError:
MsgBox "Baan IV automation error: " & BaanObj.Error
MsgBox "Return value function: " & B_function & " " & BaanObj.returnvalue
BaanObj.Quit
Set BaanObj = Nothing
Exit Sub

End Sub
Sub close_baan()
' exit Baan
If Not BaanObj Is Nothing Then
BaanObj.Quit
Set BaanObj = Nothing
End If
End Sub

Вам также может понравиться