Help !!Searching through an array with conditions
Hi
I have a question on serching through an array and passing a value for certain conditions.
I am searching the User Rights array which has specific User rights for a user. Say a user has following rights.
1) Excel Admin
2) Excel Non-Admin
3) Word Admin
4) Word Non-Admin
5) PowerPoint Admin
6) PowerPoint Non-Admin
I am trying to write two seperate functions(1 for Excel and 1 for Word) so it passes 2 if the user has admin, 1 if user has Non-Admin, or 0 if user no rights to use that particular module. Then if user has say Word Admin rights then he automatically has Word user rights. So when I'm seraching the array I have to 1st see if he has admin and if not then non-admin and so forth.
But I'm not sure how I can do this ? I don't know when I should be assigning the exit value in a For or Do loop? Essentially I have to 1st search for Word admin rights in User Rights array then if it can't find Admin then look for Word Non-Admin and so on.
I know this is quite complex to explain but hope someone can help me
Thanks
Viji
Re: Help !!Searching through an array with conditions
To determine whether a String array contains a given item it seems that you can't avoid writing a loop.
However, you can do it with just one line of code, using the new VB6 Join function:
' ARR is an array of string, SEARCH is the value to be searched
Found = InStr(1, vbNullChar & Join(arr, vbNullChar) & vbNullChar, _
vbNullChar & search & vbNullChar) > 0
Note that the above code assumes that no item in the array contains the Chr$(0) character.
There are several variations of the theme. For example you can check whether any item in the String array
begins with the searched substring using this code:
Found = InStr(1, vbNullChar & Join(arr, vbNullChar) , vbNullChar & search) > 0
And you can check whether the searched substring appears anywhere in any element of the String array:
Found = InStr(1, Join(arr, vbNullChar) , search) > 0
If it won't help use the good old loop
Iouri Boutchkine
[email protected]
Re: Help !!Searching through an array with conditions
It would be helpful to know how the array looks like. Then we can help on how to return the appropriate value.
-Cool Bizs