1
我想創建一個基本的vbscript程序,它是一個待辦事項列表。它將具有將待辦事項添加到數組,修改項目,刪除項目和生成項目的功能。我無法讓程序正確執行插入待辦事項。它顯示錯誤在我的if語句的選擇=「1」vbscript函數沒有正確執行
此外,任何其他關於我的代碼的建議將不勝感激!
Option Explicit
dim choice
dim fn
dim fh
dim num_items
dim new_item
Dim to_do_list_array, objSHL
to_do_list_array = Array()
fn = InputBox("enter text file to open: ", "open text file")
set fh =CreateObject("Scripting.FileSystemObject").OpenTextFile(fn,8,true)
Do
choice=InputBox("Administrator To-do List " & chr(13) & "'1' - Insert new
to-to item, " & chr(13) & "'2'- Modify existing to-do item, " & chr(13) &
"'3'- Remove existing to-do item," & chr(13) & "'4' - Generate list of to-do
items," & chr(13) & "'5' - quit", "Administrator To-do List")
If choice= "" Then MsgBox "You must enter a numeric value.", 48, "Invalid
Entry"
If choice= "1" Then AddtoArray(CurrentArray)
If choice= "2" Then document.write("test")
If choice= "3" Then document.write("test")
If choice= "4" Then document.write("test")
If choice= "5" Then WScript.quit()
Loop
Function AddtoArray(CurrentArray)
to_do_list_array = AddtoArray(to_do_list_array)
Dim Value
If IsArray(CurrentArray) Then
Do
Value = InputBox(Join(CurrentArray,vbLf),"Add to your array.")
ReDim Preserve CurrentArray(UBound(CurrentArray) + 1)
CurrentArray(UBound(CurrentArray)) = Value
Loop Until Value = ""
End If
AddtoArray = CurrentArray
End Function
fh.close
謝謝你,我搬了那條線,程序按順序執行。但是,現在當我嘗試調用函數選擇=「1」插入時,它不會正確執行,它會運行到錯誤 – matthewarnold
@matthewarnold,如果沒有關於錯誤的更多信息,我會指出事實:第一個函數AddtoArray中的行是對它自己的調用。嘗試刪除這一行。 –