Apologies for the shabby formatting... The following script refers to a simple single-line csv text file on my root directory containing server-name, username and password strings. I appreciate that it is probably the most inelegant, convoluted and inefficient piece of .vbs you've ever seen, but please bear with me, I'm learning. :P The script runs fine and performs all but one operation as expected. When the very last "elseif" statement is encountered it abruptly ends, no messagebox, nothing... I can't fathom how to get the array and iteration to cofunction... Please afford me your time, kindness and assistance, I will be immeasurably grateful.
dim objfso, objinputfile, filepath, searchstr, tmpstr, result, arr(2)
result = msgbox ("Please select" & vbCrLf & " " & vbCrLf & "Yes = Save password" & vbCrLf & "No = Load password ", vbyesnocancel, "Password Manager")
select case result
case vbyes
dim server, user, pass
set fso = createobject("scripting.filesystemobject")
do
server = inputbox ("Please enter server name", "Password manager")
if server = "" then
wscript.quit ()
end if
loop until server <> ""
do
user = inputbox ("Please enter username", "Password manager")
if user = "" then
wscript.quit ()
end if
loop until user <> ""
do
pass = inputbox ("Please enter password", "Password manager")
if pass = "" then
wscript.quit ()
end if
loop until pass <> ""
set file = fso.opentextfile("C:\passwords.txt",8,true)
file.write server & ", " & user & ", " & pass & ", "
file.close
msgbox "Entry added to C:\password.txt"
case vbno
set objfso = createobject("scripting.filesystemobject")
filepath = "C:\passwords.txt"
call SEARCH
sub SEARCH
if objfso.fileexists(filepath) then
do
searchstr = inputbox ("Please enter server name", "Password manager")
if searchstr = "" then
wscript.quit ()
end if
loop until searchstr <> ""
set objinputfile = objfso.opentextfile(filepath)
tmpstr = objinputfile.readline
if instr(lcase(tmpstr),lcase(searchstr)) <= 0 then
result = msgbox ("No matches", vbretrycancel, "Password Manager")
if result = 4 then
call SEARCH
elseif result = 2 then
wscript.quit ()
end if
elseif instr(lcase(tempstr),lcase(searchstr)) > 0 then
for i = 1 to 3
arr(i)
result = msgbox ("Match found" & vbCrLf & " " & vbCrLf & "Username = " & arr(0) & vbCrLf & "Password = " & arr(1), vbretrycancel, "Password Manager")
next
end if
else
result = msgbox ("C:\passwords.txt does not exist", vbokonly, "Password Manager")
end if
end sub
case vbcancel
wscript.quit ()
end select
SEARCH) outside of yourselect casestatement. Then repost your code (unless it starts working, then nevermind). :)