Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Search for string in Array

jamesjames1 (TechnicalUser) (OP)
17 Dec 07 14:17
Hi,

I have an array of groups which for troubleshooting is echoing to screen.  What I really need to do is search through the array for a particular group name, from here I can construct some type of IF or select statement to run a chunk of code.


Any help would be good.

ta
jasonp45 (Programmer)
17 Dec 07 15:39
Not sure what you're working with but I'll assume each array value is text. Something like this should work:

Dim sSearchString 'as String
Dim MyArray(3) 'as String
MyArray(1) = "Group1"
MyArray(2) = "Group2"
MyArray(3) = "Group3"
sSearchString = "Group2"

For a = 1 to UBound(MyArray)
  If MyArray(a) = sSearchString Then MsgBox MyArray(a)
Next
Swi (Programmer)
17 Dec 07 16:01
Why not store the information in a dictionary and utilizes its .Exists method?

Swi

jamesjames1 (TechnicalUser) (OP)
17 Dec 07 17:42
Hi,  Thanks for your feedback.

I went with the dictionary.exists method in the end and it was just what I was looking for.  Here is what I came up with

Set objDictionary = CreateObject("scripting.dictionary")
objDictionary.Add "comp1", "server1"
'WScript.Echo objDictionary.item ("comp1")

if objDictionary.Exists("comp1") Then
    
   'objDictionary.Item("comp1") = "Guild"
wscript.echo "correct"

elseif objDictionary.Exists("comp2") Then
wscript.echo "not correct"

End If

Seems to work so I will integrate it into my group script..

Thanks

James
strongm (MIS)
19 Dec 07 14:52
I think I'd have looked at the Filter function, given you already have the groups in an array

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close