2013-07-04 77 views
1

我對函數和類比較陌生,所以不太確定這是否是初學者的錯誤。我越來越:76函數錯誤對象需要800a01a8

Microsoft VBScript runtime error '800a01a8' 

Object required: 'EngineerNote(...)' 

/backup-check/backup_frontendlist_import_NEW.asp, line 76 

線路是:

Set NoteArray=EngineerNote(company, servername, backupsolution) 

這三個變量的我傳遞的所有字符串。所有功能和類別都設置在:

Class EngineerNoteClass 
public note 
public notesubmitdate 
End Class 

Function EngineerNote(Company, ServerName, Solution) 
Set RecordSet = Server.CreateObject("ADODB.Recordset") 
RecordSetSQLString = "SELECT note, submitdate FROM tbl_BackupChecks_AuditInformation WHERE Company='" & company & "' AND ServerName='" & servername & "' AND Solution='" & solution & "' ORDER BY submitdate desc;" 
RecordSet.Open RecordSetSQLString, DatabaseConnection 
If Recordset.EOF Then 
'Do Nothing 
Else 
Dim NoteResults 
Set NoteResults = new EngineerNoteClass 
noteresults.note = RecordSet("note") 
noteresults.notesubmitdate = RecordSet("submitdate") 
Set Engineernote = NoteResults 
End If 
Recordset.Close 
End Function 

回答

4

很可能您的數據庫查詢未返回任何結果。您只需將您的函數的返回值時,該記錄是不是EOF

If Recordset.EOF Then 
    'Do Nothing 
Else 
    ... 
    Set Engineernote = NoteResults 
End If 

設置在Then分支的返回值來Nothing(或爲空EngineerNoteClass對象)應該讓錯誤消失:

If Recordset.EOF Then 
    Set EngineerNote = Nothing 
Else 
    ... 
    Set Engineernote = NoteResults 
End If 

請確保在腳本的其餘部分正確處理返回的值/對象。

+0

這恰恰是它 - 從我那裏不好的做法。非常感謝! – Trinitrotoluene

+0

我正在編輯一些奇怪的代碼(不是我的!),我從你的答案中得到了提示..你保存了我的一天..謝謝.. –