Select Case Statement 
Author Message
 Select Case Statement

    I guess I don't understand the "select case" statements.  Here is what I
have, but it isn't returning anything.  What isn't right here?

objOU = "AD"

'Function for determining Home Directory Drive Mapping
Function GetHomeDriveMap()
 Select Case objOU
  Case "AD"
  sHomeDrive = "H:"
  Case "AH"
  sHomeDrive = "H:"
  Case "AP"
  sHomeDrive = "H:"
  Case "AR"
  sHomeDrive = "F:"
  Case "BD"
  sHomeDrive = "F:"
  Case "BS"
  sHomeDrive = "F:"
  Case "BT"
  sHomeDrive = "H:"
  Case "BU"
  sHomeDrive = "H:"
  Case "CS"
  sHomeDrive = "H:"
  Case "DI"
  sHomeDrive = "F:"
  Case "FM"
  sHomeDrive = "H:"
  Case "GO"
  sHomeDrive = "H:"
  Case "LG"
  sHomeDrive = "H:"
  Case "OB"
  sHomeDrive = "H:"
  Case "PE"
  sHomeDrive = "F:"
  Case "PU"
  sHomeDrive = "H:"
 End Select
End Function

GetHomeDriveMap

wscript.echo sHomeDrive



Tue, 14 Dec 2004 21:47:13 GMT  
 Select Case Statement
Your Select Case is fine; you're just not using the functions as well as you
might.

First, the intent of a function is to return a value - something like:

y = someFunction(x)

You may or may not have values to pass to it; in your case, you should be
passing it one.  You then set the function equal to something and return that.

Here's one possible alternate way of doing this:

x = HomeDrive("AD")

wscript.echo x

'Function for determining Home Directory Drive Mapping
Function HomeDrive(objOU)
 Select Case objOU
  Case "AD"
  HomeDrive = "H:"
  Case "AH"
  HomeDrive = "H:"
  Case "AP"
  HomeDrive = "H:"
  Case "AR"
  HomeDrive = "F:"
  Case "BD"
  HomeDrive = "F:"
  Case "BS"
  HomeDrive = "F:"
  Case "BT"
  HomeDrive = "H:"
  Case "BU"
  HomeDrive = "H:"
  Case "CS"
  HomeDrive = "H:"
  Case "DI"
  HomeDrive = "F:"
  Case "FM"
  HomeDrive = "H:"
  Case "GO"
  HomeDrive = "H:"
  Case "LG"
  HomeDrive = "H:"
  Case "OB"
  HomeDrive = "H:"
  Case "PE"
  HomeDrive = "F:"
  Case "PU"
  HomeDrive = "H:"
 End Select
End Function


Quote:
>     I guess I don't understand the "select case" statements.  Here is what I
> have, but it isn't returning anything.  What isn't right here?

> objOU = "AD"

> 'Function for determining Home Directory Drive Mapping
> Function GetHomeDriveMap()
>  Select Case objOU
>   Case "AD"
>   sHomeDrive = "H:"
>   Case "AH"
>   sHomeDrive = "H:"
>   Case "AP"
>   sHomeDrive = "H:"
>   Case "AR"
>   sHomeDrive = "F:"
>   Case "BD"
>   sHomeDrive = "F:"
>   Case "BS"
>   sHomeDrive = "F:"
>   Case "BT"
>   sHomeDrive = "H:"
>   Case "BU"
>   sHomeDrive = "H:"
>   Case "CS"
>   sHomeDrive = "H:"
>   Case "DI"
>   sHomeDrive = "F:"
>   Case "FM"
>   sHomeDrive = "H:"
>   Case "GO"
>   sHomeDrive = "H:"
>   Case "LG"
>   sHomeDrive = "H:"
>   Case "OB"
>   sHomeDrive = "H:"
>   Case "PE"
>   sHomeDrive = "F:"
>   Case "PU"
>   sHomeDrive = "H:"
>  End Select
> End Function

> GetHomeDriveMap

> wscript.echo sHomeDrive



Tue, 14 Dec 2004 22:23:06 GMT  
 Select Case Statement

Quote:

>     I guess I don't understand the "select case" statements.  Here is
> what I have, but it isn't returning anything.  What isn't right here?

What "isn't right" is you understanding of variable scope.  

You would be better off *not* trying to manipulate global variables.  The best way to write your GetHomeDriveMap function (or any function for that matter ;-) is to explicitly pass the argument(s) and explicitly return a value...

Dim myHomeDrive
Dim myOU
myOU = "AD"
myHomeDrive = GetHomeDriveMap(myOU)
wscript.echo myHomeDrive

'Function for determining Home Directory Drive Mapping
Function GetHomeDriveMap(argOU)
 Dim sHomeDrive
 Select Case argOU
  Case "AD"
  sHomeDrive = "H:"
  Case "AH"
  sHomeDrive = "H:"
  Case "AP"
  sHomeDrive = "H:"
  Case "AR"
  sHomeDrive = "F:"
  Case "BD"
  sHomeDrive = "F:"
  Case "BS"
  sHomeDrive = "F:"
  Case "BT"
  sHomeDrive = "H:"
  Case "BU"
  sHomeDrive = "H:"
  Case "CS"
  sHomeDrive = "H:"
  Case "DI"
  sHomeDrive = "F:"
  Case "FM"
  sHomeDrive = "H:"
  Case "GO"
  sHomeDrive = "H:"
  Case "LG"
  sHomeDrive = "H:"
  Case "OB"
  sHomeDrive = "H:"
  Case "PE"
  sHomeDrive = "F:"
  Case "PU"
  sHomeDrive = "H:"
 End Select
 GetHomeDriveMap = sHomeDrive
End Function

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Tue, 14 Dec 2004 22:24:30 GMT  
 Select Case Statement
    Thanks Guys, I have been pretty close on most of my endeavors, it is
kinda hard to understand this scripting stuff.  I appreciate your help.
Maybe someday I won't have to post 90,000 questions for you...  ;)

Thanks again,

Ryan


Quote:
>     I guess I don't understand the "select case" statements.  Here is what
I
> have, but it isn't returning anything.  What isn't right here?

> objOU = "AD"

> 'Function for determining Home Directory Drive Mapping
> Function GetHomeDriveMap()
>  Select Case objOU
>   Case "AD"
>   sHomeDrive = "H:"
>   Case "AH"
>   sHomeDrive = "H:"
>   Case "AP"
>   sHomeDrive = "H:"
>   Case "AR"
>   sHomeDrive = "F:"
>   Case "BD"
>   sHomeDrive = "F:"
>   Case "BS"
>   sHomeDrive = "F:"
>   Case "BT"
>   sHomeDrive = "H:"
>   Case "BU"
>   sHomeDrive = "H:"
>   Case "CS"
>   sHomeDrive = "H:"
>   Case "DI"
>   sHomeDrive = "F:"
>   Case "FM"
>   sHomeDrive = "H:"
>   Case "GO"
>   sHomeDrive = "H:"
>   Case "LG"
>   sHomeDrive = "H:"
>   Case "OB"
>   sHomeDrive = "H:"
>   Case "PE"
>   sHomeDrive = "F:"
>   Case "PU"
>   sHomeDrive = "H:"
>  End Select
> End Function

> GetHomeDriveMap

> wscript.echo sHomeDrive



Tue, 14 Dec 2004 22:47:20 GMT  
 Select Case Statement
It'll be your turn to answer all of them, then... :-)


Quote:
>     Thanks Guys, I have been pretty close on most of my endeavors, it is
> kinda hard to understand this scripting stuff.  I appreciate your help.
> Maybe someday I won't have to post 90,000 questions for you...  ;)

> Thanks again,

> Ryan



> >     I guess I don't understand the "select case" statements.  Here is what
> I
> > have, but it isn't returning anything.  What isn't right here?

> > objOU = "AD"

> > 'Function for determining Home Directory Drive Mapping
> > Function GetHomeDriveMap()
> >  Select Case objOU
> >   Case "AD"
> >   sHomeDrive = "H:"
> >   Case "AH"
> >   sHomeDrive = "H:"
> >   Case "AP"
> >   sHomeDrive = "H:"
> >   Case "AR"
> >   sHomeDrive = "F:"
> >   Case "BD"
> >   sHomeDrive = "F:"
> >   Case "BS"
> >   sHomeDrive = "F:"
> >   Case "BT"
> >   sHomeDrive = "H:"
> >   Case "BU"
> >   sHomeDrive = "H:"
> >   Case "CS"
> >   sHomeDrive = "H:"
> >   Case "DI"
> >   sHomeDrive = "F:"
> >   Case "FM"
> >   sHomeDrive = "H:"
> >   Case "GO"
> >   sHomeDrive = "H:"
> >   Case "LG"
> >   sHomeDrive = "H:"
> >   Case "OB"
> >   sHomeDrive = "H:"
> >   Case "PE"
> >   sHomeDrive = "F:"
> >   Case "PU"
> >   sHomeDrive = "H:"
> >  End Select
> > End Function

> > GetHomeDriveMap

> > wscript.echo sHomeDrive



Tue, 14 Dec 2004 23:07:15 GMT  
 Select Case Statement
If I was knowledgeable, then I wouldn't mind it at all ;)



Quote:
> It'll be your turn to answer all of them, then... :-)



> >     Thanks Guys, I have been pretty close on most of my endeavors, it is
> > kinda hard to understand this scripting stuff.  I appreciate your help.
> > Maybe someday I won't have to post 90,000 questions for you...  ;)

> > Thanks again,

> > Ryan



> > >     I guess I don't understand the "select case" statements.  Here is
what
> > I
> > > have, but it isn't returning anything.  What isn't right here?

> > > objOU = "AD"

> > > 'Function for determining Home Directory Drive Mapping
> > > Function GetHomeDriveMap()
> > >  Select Case objOU
> > >   Case "AD"
> > >   sHomeDrive = "H:"
> > >   Case "AH"
> > >   sHomeDrive = "H:"
> > >   Case "AP"
> > >   sHomeDrive = "H:"
> > >   Case "AR"
> > >   sHomeDrive = "F:"
> > >   Case "BD"
> > >   sHomeDrive = "F:"
> > >   Case "BS"
> > >   sHomeDrive = "F:"
> > >   Case "BT"
> > >   sHomeDrive = "H:"
> > >   Case "BU"
> > >   sHomeDrive = "H:"
> > >   Case "CS"
> > >   sHomeDrive = "H:"
> > >   Case "DI"
> > >   sHomeDrive = "F:"
> > >   Case "FM"
> > >   sHomeDrive = "H:"
> > >   Case "GO"
> > >   sHomeDrive = "H:"
> > >   Case "LG"
> > >   sHomeDrive = "H:"
> > >   Case "OB"
> > >   sHomeDrive = "H:"
> > >   Case "PE"
> > >   sHomeDrive = "F:"
> > >   Case "PU"
> > >   sHomeDrive = "H:"
> > >  End Select
> > > End Function

> > > GetHomeDriveMap

> > > wscript.echo sHomeDrive



Wed, 15 Dec 2004 00:51:57 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Select Case statement in VBScript

2. Select Case Statement

3. Select Case Statement

4. Is the Select Case Statement crippled in VBScript?

5. Problem with Expression in a Select Case Statement

6. Select Case Statements

7. Select Case Statement

8. SELECT CASE STATEMENT

9. Select Case Statement Help

10. Select Case Statement

11. Criteria for select case statements

12. Embedded or nested Select Case statements

 

 
Powered by phpBB® Forum Software