 |
VBScript For questions and discussions related to VBScript. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

September 20th, 2011, 12:54 PM
|
Registered User
|
|
Join Date: Aug 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
"Object required" error
I'm getting an "Object required" error when I return to a Sub to write another record (In red below) after the file has been open. Below is the Sub. I have several output files, but don't always have output data for each file depending on the input. I do the check to prevent empty output files.
Any idea on why the objOutputFile_CIF_OneRow doesn't exist when I come back into the SUB? I have verified I'm not closing the object.
Public Sub subWriteOutput ( sDocType, sFileNameOut, sAcctType, sAcct, sDocTypeId, sDocDate, sScanOper, sDescPrompt, sConvToPDF)
'*********** Calculate length of sFileName and remove extension and change to .TIF for PDF conversion - above add in sOutRec below
iInactive = 0
iReceived = 1
sScanDate = Date
msgbox "output"
If sDocType = "CIF" Then
sOutRec = strImgOutput_file_path & sFileNameOut & vbTab & sDocTypeId & vbTab & sCif & vbTab & sDocDate & _
vbTab & iReceived & vbTab & iInactive & vbTab & sScanDate & vbTab & sScanOper & vbTab & sDescPrompt & _
vbTab & sCif & "-" & sDocTypeId & vbCrLf
'msgbox sOutRec
If sConvToPDF = "Y" Then
If sOneRowOnly = "Y" Then
If sOpen_CIF_OneRow = "N" Then
strOutput_Cif_OneRow = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-OneRow.txt"
If objFSO.FileExists(strOutput_Cif_OneRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_OneRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_CIF_OneRow = objFSO.OpenTextFile(strOutput_Cif_OneRow,ForWritin g,True)
End If
sOpen_CIF_OneRow = "Y"
End If
objOutputFile_CIF_OneRow.Write sOutrec
Else
If sOpen_CIF_NewRow = "N" Then
strOutput_Cif_NewRow = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-NewRow.txt"
If objFSO.FileExists(strOutput_Cif_NewRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_NewRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_CIF_NewRow = objFSO.OpenTextFile(strOutput_Cif_NewRow,ForWritin g,True)
End If
sOpen_CIF_NewRow = "Y"
End If
objOutputFile_CIF_NewRow.Write sOutrec
End If
Else
If sOneRowOnly = "Y" Then
If sOpen_CIF_OneRowPDF = "N" Then
strOutput_Cif_OneRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-OneRowPDF.txt"
If objFSO.FileExists(strOutput_Cif_OneRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_OneRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_CIF_OneRowPDF = objFSO.OpenTextFile(strOutput_Cif_OneRowPDF,ForWri ting,True)
End If
sOpen_CIF_OneRowPDF = "Y"
End If
objOutputFile_CIF_OneRowPDF.Write sOutrec
Else
If sOpen_CIF_NewRowPDF = "N" Then
strOutput_Cif_NewRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-NewRowPDF.txt"
If objFSO.FileExists(strOutput_Cif_NewRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_NewRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_CIF_NewRowPDF = objFSO.OpenTextFile(strOutput_Cif_NewRowPDF,ForWri ting,True)
End If
sOpen_CIF_NewRowPDF = "Y"
End If
objOutputFile_CIF_NewRowPDF.Write sOutrec
End If
End If
End If
If sDocType = "ACCT" Then
sOutRec = strImgOutput_file_path & sFileNameOut & vbTab & sDocTypeId & vbTab & sAcctType & sAcct & vbTab & sDocDate & _
vbTab & iReceived & vbTab & iInactive & vbTab & sScanDate & vbTab & sScanOper & vbTab & sDescPrompt & _
vbTab & sAcctType & sAcct & "-" & sDocTypeId & vbCrLf
If sConvToPDF = "Y" Then
If sOneRowOnly = "Y" Then
If sOpen_Acct_OneRow = "N" Then
strOutput_Acct_OneRow = strTxtOutput_file_path & strLoanDepSwitch & "-OneRow.txt"
If objFSO.FileExists(strOutput_Deposit_OneRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_OneRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_Acct_OneRow = objFSO.OpenTextFile(strOutput_Acct_OneRow,ForWriti ng,True)
End If
sOpen_Acct_OneRow = "Y"
End If
objOutputFile_Acct_OneRow.Write sOutrec
Else
If sOpen_Acct_NewRow = "N" Then
strOutput_Acct_NewRow = strTxtOutput_file_path & strLoanDepSwitch & "-NewRow.txt"
If objFSO.FileExists(strOutput_Acct_NewRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_NewRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_Acct_NewRow = objFSO.OpenTextFile(strOutput_Acct_NewRow,ForWriti ng,True)
End If
sOpen_Acct_NewRow = "Y"
End If
objOutputFile_Acct_NewRow.Write sOutrec
End If
Else
If sOneRowOnly = "Y" Then
If sOpen_Acct_OneRowPDF = "N" Then
strOutput_Acct_OneRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-OneRowPDF.txt"
If objFSO.FileExists(strOutput_Deposit_OneRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_OneRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_Acct_OneRowPDF = objFSO.OpenTextFile(strOutput_Acct_OneRowPDF,ForWr iting,True)
End If
sOpen_Acct_OneRowPDF = "Y"
End If
objOutputFile_Acct_OneRowPDF.Write sOutrec
Else
If sOpen_Acct_NewRowPDF = "N" Then
strOutput_Acct_NewRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-NewRowPDF.txt"
If objFSO.FileExists(strOutput_Acct_NewRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_NewRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"loc al")
subExitProgram
Else
Set objOutputFile_Acct_NewRowPDF = objFSO.OpenTextFile(strOutput_Acct_NewRowPDF,ForWr iting,True)
End If
sOpen_Acct_NewRowPDF = "Y"
End If
objOutputFile_Acct_NewRowPDF.Write sOutrec
End If
End If
End If
End Sub
|

September 20th, 2011, 06:55 PM
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
Could you get that code inside the code tags that this forum supplies. It looks like the hash sign.
Also could you retain the indented formatting. There is a reason for having that in code and the main reason being able to read the code to quickly identify errors.
Re post as required, then we'll be able to help you!
__________________
Apocolypse2005, I'm a programmer - of sorts.
|

September 21st, 2011, 08:55 AM
|
Registered User
|
|
Join Date: Aug 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
formated code
Sorry, didn't see the code tags to keep it formatted
Code:
Public Sub subWriteOutput ( sDocType, sFileNameOut, sAcctType, sAcct, sDocTypeId, sDocDate, sScanOper, sDescPrompt, sConvToPDF)
'*********** Calculate length of sFileName and remove extension and change to .TIF for PDF conversion - above add in sOutRec below
iInactive = 0
iReceived = 1
sScanDate = Date
If sDocType = "CIF" Then
sOutRec = strImgOutput_file_path & sFileNameOut & vbTab & sDocTypeId & vbTab & sCif & vbTab & sDocDate & _
vbTab & iReceived & vbTab & iInactive & vbTab & sScanDate & vbTab & sScanOper & vbTab & sDescPrompt & _
vbTab & sCif & "-" & sDocTypeId & vbCrLf
'msgbox sOutRec
If sConvToPDF = "Y" Then
If sOneRowOnly = "Y" Then
If sOpen_CIF_OneRow = "N" Then
strOutput_Cif_OneRow = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-OneRow.txt"
If objFSO.FileExists(strOutput_Cif_OneRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_OneRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_CIF_OneRow = objFSO.OpenTextFile(strOutput_Cif_OneRow,ForWriting,True)
End If
sOpen_CIF_OneRow = "Y"
End If
objOutputFile_CIF_OneRow.Write sOutrec
Else
If sOpen_CIF_NewRow = "N" Then
strOutput_Cif_NewRow = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-NewRow.txt"
If objFSO.FileExists(strOutput_Cif_NewRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_NewRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_CIF_NewRow = objFSO.OpenTextFile(strOutput_Cif_NewRow,ForWriting,True)
End If
sOpen_CIF_NewRow = "Y"
End If
objOutputFile_CIF_NewRow.Write sOutrec
End If
Else
If sOneRowOnly = "Y" Then
If sOpen_CIF_OneRowPDF = "N" Then
strOutput_Cif_OneRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-OneRowPDF.txt"
If objFSO.FileExists(strOutput_Cif_OneRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_OneRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_CIF_OneRowPDF = objFSO.OpenTextFile(strOutput_Cif_OneRowPDF,ForWriting,True)
End If
sOpen_CIF_OneRowPDF = "Y"
End If
objOutputFile_CIF_OneRowPDF.Write sOutrec
Else
If sOpen_CIF_NewRowPDF = "N" Then
strOutput_Cif_NewRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-Cif-NewRowPDF.txt"
If objFSO.FileExists(strOutput_Cif_NewRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Cif_NewRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_CIF_NewRowPDF = objFSO.OpenTextFile(strOutput_Cif_NewRowPDF,ForWriting,True)
End If
sOpen_CIF_NewRowPDF = "Y"
End If
objOutputFile_CIF_NewRowPDF.Write sOutrec
End If
End If
End If
If sDocType = "ACCT" Then
sOutRec = strImgOutput_file_path & sFileNameOut & vbTab & sDocTypeId & vbTab & sAcctType & sAcct & vbTab & sDocDate & _
vbTab & iReceived & vbTab & iInactive & vbTab & sScanDate & vbTab & sScanOper & vbTab & sDescPrompt & _
vbTab & sAcctType & sAcct & "-" & sDocTypeId & vbCrLf
If sConvToPDF = "Y" Then
If sOneRowOnly = "Y" Then
If sOpen_Acct_OneRow = "N" Then
strOutput_Acct_OneRow = strTxtOutput_file_path & strLoanDepSwitch & "-OneRow.txt"
If objFSO.FileExists(strOutput_Deposit_OneRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_OneRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_Acct_OneRow = objFSO.OpenTextFile(strOutput_Acct_OneRow,ForWriting,True)
End If
sOpen_Acct_OneRow = "Y"
End If
objOutputFile_Acct_OneRow.Write sOutrec
Else
If sOpen_Acct_NewRow = "N" Then
strOutput_Acct_NewRow = strTxtOutput_file_path & strLoanDepSwitch & "-NewRow.txt"
If objFSO.FileExists(strOutput_Acct_NewRow) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_NewRow
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_Acct_NewRow = objFSO.OpenTextFile(strOutput_Acct_NewRow,ForWriting,True)
End If
sOpen_Acct_NewRow = "Y"
End If
objOutputFile_Acct_NewRow.Write sOutrec
End If
Else
If sOneRowOnly = "Y" Then
If sOpen_Acct_OneRowPDF = "N" Then
strOutput_Acct_OneRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-OneRowPDF.txt"
If objFSO.FileExists(strOutput_Deposit_OneRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_OneRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_Acct_OneRowPDF = objFSO.OpenTextFile(strOutput_Acct_OneRowPDF,ForWriting,True)
End If
sOpen_Acct_OneRowPDF = "Y"
End If
objOutputFile_Acct_OneRowPDF.Write sOutrec
Else
If sOpen_Acct_NewRowPDF = "N" Then
strOutput_Acct_NewRowPDF = strTxtOutput_file_path & strLoanDepSwitch & "-NewRowPDF.txt"
If objFSO.FileExists(strOutput_Acct_NewRowPDF) Then
msg_num = Err.Number
msg_desc = "Output file already exists = " & strOutput_Acct_NewRowPDF
Call LogEvent (strEventLog,strSourceName,msg_num,msg_desc,1,"local")
subExitProgram
Else
Set objOutputFile_Acct_NewRowPDF = objFSO.OpenTextFile(strOutput_Acct_NewRowPDF,ForWriting,True)
End If
sOpen_Acct_NewRowPDF = "Y"
End If
objOutputFile_Acct_NewRowPDF.Write sOutrec
End If
End If
End If
End Sub
|

September 21st, 2011, 07:35 PM
|
Friend of Wrox
|
|
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
|
|
That is a lot of code for a single sub, can you take out any repeated code and put into other subs, then you can more closely identify the problem.
__________________
Apocolypse2005, I'm a programmer - of sorts.
|

September 22nd, 2011, 05:23 PM
|
Registered User
|
|
Join Date: Aug 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Found problem
I had not declared the variable for the object. 
|
|
 |