1

I am trying to create basic vbscript program that acts a to-do list. It will have features to add to-do item to an array, modify item, delete item, and generate items. I am having trouble getting the program to execute the insert to-do item correctly. it shows an error at my if statement for choice= "1"

Also, any other suggestions about my code would be much appreciated!

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 Answer 1

1

For me, in this code

to_do_list_array = AddtoArray(to_do_list_array) 

fn = InputBox("enter text file to open: ", "open text file")

the first line is executed first, and what the AddtoArray function does is

Function AddtoArray(CurrentArray)
Dim Value
    If IsArray(CurrentArray) Then
        Do
            Value = InputBox(Join(CurrentArray,vbLf),"Add to your array.")
....

Probably that first line should not be where it is

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, i moved that line, and the program executes in order. However, now when i try to call the function choice = "1" insert, it does not execute correctly, it runs into an error
@matthewarnold, Without more information on what the error is, I will point to the fact that the first line in the function AddtoArray is a call to itself. Try to remove this line.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.