Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Array lookup or hicup or DoH!

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,34845
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array lookup or hicup or DoH!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Array lookup or hicup or DoH! - 5/24/2006 6:29:49 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
Some day I will be able to do arrays!

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.

Argggg... "She did it again!"

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF
 
 
Post #: 1
 
 RE: Array lookup or hicup or DoH! - 5/24/2006 6:40:51 AM   
  DiGiTAL.SkReAM


Posts: 1170
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Here's a fixed codeblock for ya.


      

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

(in reply to mcds99)
 
 
Post #: 2
 
 RE: Array lookup or hicup or DoH! - 5/24/2006 7:09:10 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
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

did I do something wrong when I setup the array?

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 3
 
 RE: Array lookup or hicup or DoH! - 5/24/2006 10:36:49 PM   
  ehvbs

 

Posts: 2106
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline

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






(in reply to mcds99)
 
 
Post #: 4
 
 RE: Array lookup or hicup or DoH! - 5/24/2006 11:20:22 PM   
  DiGiTAL.SkReAM


Posts: 1170
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline

Yer right.  Doggone it.  This is what happens when you rush through something and then never go back to doublecheck it.

But at least the dictionary code would have worked! heheheheh

_____________________________

"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

(in reply to ehvbs)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array lookup or hicup or DoH! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts