I have an array called idfArray(12) it is 13 pointers long.
I have an input box that gets the variable fName I check to see that fName has value [if fname = "" then wscript.quit] I now want to be sure fname is valid by looking it up in the array above.
I have tried this forward and backward and I keep missing something about arrays.
Just remember... an array is always numbered from 0 to whatever. For example, your array has 13 elements, but they are numbered 0 thru 12. So, the LBound(idfArray) would return the number 0, and the UBound(adfArray) would return the number 12.
Now, in your case, I think it would be easier to use a dictionary object. Instead of
Try something like this:
There won't be much noticeable performance increase (if any), but this way you don't have to go around worrying about what number element you are on, or how many you have. So if you find that you need to add another 15 entries, you don't have to about renumbering all of your code, etc. Plus, it uses the .Exists property, so ginolard should be happy.
< Message edited by DiGiTAL.SkReAM -- 5/24/2006 7:02:38 AM >
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
Thanks you really are the best! Now... when the code executes...
For i = 0 to UBound(idfArray) If idfArray(i) = fName then wscript.echo "The IDF names are: " & VbCrLf & Join(idfArray,VbCrLf) wscript.echo "fName and IDF are: " & fName & " and " & idfArray(i) Else wscript.quit end if Next
It always quits even when fName and idfArray(i) are equal When the Else is not commented the echo'd don't work
Hi DiGiTAL.SkReAM, looks like your fixed codeblock loop will stop on the first element of idfArray not equal to fname. Not exactly what you'd expect of a search loop.
Hi mcsd99, if you want to scan an array for some element, give your loop the change to see all items of the array:
bFound = False
For i = 0 to UBound(idfArray) If idfArray(i) = fName then wscript.echo "The IDF names are: " & VbCrLf & Join(idfArray,VbCrLf) wscript.echo "fName and IDF are: " & fName & " and " & idfArray(i) bFound = True Exit For ' no need to search further end if Next If Not bFound Then wscript.quit