Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Select Case wont read variables

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Select Case wont read variables
  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 >>
 Select Case wont read variables - 9/24/2005 11:39:28 AM   
  icode4u

 

Posts: 7
Score: 0
Joined: 9/24/2005
Status: offline
For some reason the Select is not recieving the results of the function. If you do a response.write GetDates("3/21" , "4/20") It will print out the values. between the 2 dates. So why wont the select use the string?


This is the function that make a string of dates for the select to choose from

Function GetDates( DateStart, DateEnd )
DateStart = cdate( DateStart )-1
DateEnd = cdate( DateEnd )
Do until DateStart = DateEnd DateStart = DateStart + 1
Datestr = Datestr &(chr(34)&datepart("m",DateStart)&"/"&datepart("d",DateStart)&chr(34)&" , ")
Loop GetDates = cstr(mid(Datestr,1,len(Datestr)-3))
End Function

This is part of the case the result of the function is passed to

Select Case month(date)&"/"&day(date)
Case GetDates("3/21" , "4/20")
sign = "aries"
aries = " SELECTED "
Case GetDates("4/21" , "5/20")
sign = "taurus"
Case GetDates("5/21" , "7/21")
sign = "gemini" 
Case GetDates("5/22" , "6/22")
sign = "cancer"
Case GetDates("6/23" , "7/23")
sign = "leo"
Case GetDates("7/24" , "8/22")
sign = "virgo"
Case GetDates("8/23" , "9/22")
sign = "libra"
Case GetDates("9/23" , "10/22")
sign = "scorpio"
Case GetDates("10/23" , "11/21")
sign = "sagittarius" 
Case GetDates("11/22" , "12/20")
sign = "capricorn"
Case GetDates("1/21" , "2/19")
sign = "aquarius"
Case GetDates("2/20" , "3/20")
sign = "pisces"
End Select


response.write sign
 
 
Post #: 1
 
 RE: Select Case wont read variables - 12/2/2005 2:07:48 AM   
  jkemper

 

Posts: 4
Score: 0
Joined: 11/30/2005
Status: offline
The reason I believe that you are not getting the results from the function is because when you call the function the results returned have to saved in a variable.

For Example:

Function DoSomething(someitem)
   DoSomething = do.work(someitem)
End Function

something = DoSomething(someitem)

In order to pass a value back from the fuction the function name has to assigned a value in the function
ex. DoSomething = do.work(someitem)

Then when you call the function the return value is assigned to a variable where it can be used. 
ex. something = DoSomething(someitem)

One thing I would recommend if your going to be doing a lot scripting with vbscript is to pickup the O'Reilly guide "VBscript In A Nutshell" (ISBN 0-596-00488-5) it is a great reference guide. 

(in reply to icode4u)
 
 
Post #: 2
 
 RE: Select Case wont read variables - 12/2/2005 3:38:19 AM   
  icode4u

 

Posts: 7
Score: 0
Joined: 9/24/2005
Status: offline
If you look at my example you can see that I do have a function call in the case itself even if I put the return values into a variable the result would be the same. I see no difference in calling the function and directly returning the value and setting it to a var. Isn't that just adding another step to process.

How is your function resolving the issue?

Function DoSomething(someitem)
  DoSomething = do.work(someitem)
End Function

This function works just not in the case even is I set the return values to a var.
Function GetDates( DateStart, DateEnd )
DateStart = cdate( DateStart )-1
DateEnd = cdate( DateEnd )
Do until DateStart = DateEnd DateStart = DateStart + 1
Datestr = Datestr &(chr(34)&datepart("m",DateStart)&"/"&datepart("d",DateStart)&chr(34)&" , ")
Loop GetDates = cstr(mid(Datestr,1,len(Datestr)-3))
DoSomething  = GetDates( DateStart, DateEnd )

End Function

(in reply to jkemper)
 
 
Post #: 3
 
 RE: Select Case wont read variables - 12/2/2005 9:12:51 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I don't believe it is valid to use a function to populate the expression string of a case statement.

_____________________________

"... 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 icode4u)
 
 
Post #: 4
 
 RE: Select Case wont read variables - 12/2/2005 9:21:48 AM   
  icode4u

 

Posts: 7
Score: 0
Joined: 9/24/2005
Status: offline
I'm glad we cleared that up

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Select Case wont read variables - 12/2/2005 9:34:22 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I believe this is one way to do what you want:

      

_____________________________

"... 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 icode4u)
 
 
Post #: 6
 
 RE: Select Case wont read variables - 12/2/2005 10:21:19 AM   
  icode4u

 

Posts: 7
Score: 0
Joined: 9/24/2005
Status: offline
Thank you thats a very interesting work around however the reason I have the case is becuase there are other variables under each case. I mean there are many ways to deal with it if only one option was being returened I could do the same with an array without the dic. But the effort is worth a hoowa.

(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Select Case wont read variables 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