Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


stumped

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> stumped
  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 >>
 stumped - 4/6/2006 4:54:55 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
how would I check for a empty variable type in a select/case? I have to check for an empty string as well and its totally messing me up.

code:
(note that I have an if/then that checks for an empty variable before the select case, that works. doing it in the select/case doesnt)

      

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site
 
 
Post #: 1
 
 RE: stumped - 4/6/2006 5:08:46 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
I think the only way to do it would be to use a Select Case True structure then evaluate in each case. My question would be why do you want to?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 2
 
 RE: stumped - 4/6/2006 5:20:23 AM   
  sorex

 

Posts: 77
Score: 0
Joined: 3/9/2006
Status: offline
what if you feed it to the sub? does it work then?

Private Sub pickInput (Input)

&

pickInput (Input)

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: stumped - 4/6/2006 6:32:14 AM   
  DiGiTAL.SkReAM


Posts: 1193
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Hmm... you might think about breaking up your case else statement?
Either that or do like ebgreen suggested, and use select case true and have one of the cases be Input = ""

Case Else
    If Len(Trim(Input)) = 0 Then
         MsgBox ("That is an incorrect entry, try again")
         getInput
    Else
          quit = MsgBox ("Are you sure?", 36, "Want To quit?")'52
              If quit = 6 Then
                    MsgBox ("Bye!!")
                    WScript.Quit
              Else
                    getInput
              End If



_____________________________

"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 sorex)
 
 
Post #: 4
 
 RE: stumped - 4/6/2006 2:18:39 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
i guess i should be more specific.
i am testing for user input, with error checking.
here is what i want to happen,
1. clicking ok with nothing in the field: error message with reload of menu
2. clicking cancel: goes to "Want to quit" msgbox
3. hitting esc or clicking to close the inputbox: goes to "Want to quit" msgbox

clicking ok with nothing in the field returns an empty string
clicking cancel returns an empty variable
hitting esc or clicking to close the inputbox returns an empty variable

select case will only check string variables, i was hoping to keep my code smaller and cleaner by keeping all my error checking in the select case.
when i test for case "" this returns true for all the above

a select cast true still wouldnt work because it would be true for both variable types.

in other words, when testing for an empty variable
if typename(input) = "Empty" then tests true only for #3
and
case "" tests true for all 3

i guess ill just use the if/then to test for an empty variable, i just wanted to be able to test for it in the select case.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 5
 
 RE: stumped - 4/6/2006 2:42:03 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
here is an example of what i DONT want:

sub getUserName()
   Username = InputBox("Enter your admin username (domain\username)", "Enter Username")
   if username = "" then
       MsgBox ("That is an incorrect entry, try again")
       getUserName()
   end if
end sub

getUserName()

there is NO WAY to break out of the loop without entering something, other than killing the process that spawned it.

this works: (watch the typename echo when you run it and youll see what im getting at)

sub getUserName()
   Username = InputBox("Enter your admin username (domain\username)", "Enter Username")
   wscript.echo typename(username)
   if typename(username) = "Empty" then
       MsgBox ("Closing the inputbox")
   wscript.quit
   elseif  username = "" then
   MsgBox ("That is an incorrect entry, try again")
       getUserName()
   end if
end sub

getUserName()

as you can see you HAVE to test for the empty variable BEFORE testing for an empty string because it returns true for an empty string AND an empty variable
my original goal was to try and do this in a select/case rather than using if/elseif

btw, im feeling very BOLD tonight lol

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 6
 
 RE: stumped - 4/6/2006 2:54:07 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
ok its done and works the way i want it to (finally)
to hell with checking for empty variables in the select case!

finished script:

      

< Message edited by kirrilian -- 4/6/2006 2:58:36 PM >


_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 7
 
 RE: stumped - 4/7/2006 12:52:54 AM   
  DiGiTAL.SkReAM


Posts: 1193
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
I was about to suggest that instead of using inputbox, you put together a very simple HTA, or ie page since that way you can assign various values to the ok, cancel buttons, etc.

_____________________________

"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 kirrilian)
 
 
Post #: 8
 
 RE: stumped - 4/7/2006 1:54:09 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
quote:

ORIGINAL: DiGiTAL.SkReAM

I was about to suggest that instead of using inputbox, you put together a very simple HTA, or ie page since that way you can assign various values to the ok, cancel buttons, etc.


That was a possiblity as well, I'd rather throw in an if/then than rewrite the whole script though.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 9
 
 
 
  

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 >> stumped 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