|
-
Jan 17th, 2005, 07:26 AM
#1
Thread Starter
Banned
option strict on...
Just started using it...
But as soon as I did that I get errors for the following:
Session("FirstName") & " " & Session("LastName")
Says I cant use Operator & with option strict on ...
I also get an error when I do this:
If Session("Admin") = True Then
Finally I get an error for this:
If FormatDateTime(Now(), 4) > "12:00" Then
Says option strict on disallows conversion from int to date.
How do I fix these ?
-
Jan 17th, 2005, 07:37 AM
#2
Re: option strict on...
Session("key") returns an Object, so you'll need to cast accordingly to whatever datatype you are looking for. Or call the ToString() method for Strings.
In FormatDateTime, you need to specify the correct enum member (DateFormat.ShortTime), not its value (4).
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jan 17th, 2005, 07:55 AM
#3
Re: option strict on...
Code:
Session("FirstName") & " " & Session("LastName")
Should be:
Code:
CType(Session("FirstName"), String) & " " & CType(Session("LastName"), String)
'or
Session("FirstName").ToString & " " & Session("LastName").ToSTring
and
Code:
If Session("Admin") = True Then
Should be:
Code:
If CType(Session("Admin"), Boolean) = True Then
and
Code:
If FormatDateTime(Now(), 4) > "12:00" Then
should be
Code:
If FormatDateTime(Now(), DateFormat.ShortTime) > "12:00" Then
Woka
-
Jan 17th, 2005, 08:09 AM
#4
Thread Starter
Banned
Re: option strict on...
Too late...I got it :-p...
Is this option strict really worth it ???
-
Jan 17th, 2005, 08:14 AM
#5
Thread Starter
Banned
Re: option strict on...
What if a function returns nothing and you have option strict on, must it return at least a boolean ?
God I sure do miss void() in C++
-
Jan 17th, 2005, 08:25 AM
#6
Re: option strict on...
A function that returns nothing is a Sub 
And no, I don't think Option Strict is worth anything. If I want to write strictly, I will do it in C#.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jan 17th, 2005, 10:18 AM
#7
Thread Starter
Banned
Re: option strict on...
 Originally Posted by crptcblade
A function that returns nothing is a Sub
And no, I don't think Option Strict is worth anything. If I want to write strictly, I will do it in C#.
Argh duh...........
Woka IM gonna kill you...you made me change all this code...for NOTHING!
-
Jan 17th, 2005, 10:34 AM
#8
Re: option strict on...
It is worth it. You have not wasted your time.
Woka
-
Jan 17th, 2005, 10:35 AM
#9
Thread Starter
Banned
Re: option strict on...
 Originally Posted by Wokawidget
It is worth it. You have not wasted your time.
Woka
I know i am just giving you a hard time
-
Jan 17th, 2005, 01:41 PM
#10
Frenzied Member
Re: option strict on...
Just a tip.
Instead of using CType, use DirectCast instead. it works twice as fast.
VB Code:
DirectCast(Session("FirstName"), String) & " " & DirectCast(Session("LastName"), String)
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 17th, 2005, 01:46 PM
#11
Re: option strict on...
OK.
Why are there so many ways to do the same thing though?
Why have a CType function?
Woka
-
Jan 17th, 2005, 02:17 PM
#12
Thread Starter
Banned
Re: option strict on...
 Originally Posted by Wokawidget
OK.
Why are there so many ways to do the same thing though?
Why have a CType function?
Woka
.net sucks...way too many ways to skin the cats.
i like it and i dont like it...
thanks for pointing out that its faster hours later after i changed my entire project...boy do i feel great
-
Jan 17th, 2005, 03:16 PM
#13
Frenzied Member
Re: option strict on...
CType is for backward compatiblity, similar to the fact that you can still use CStr and CInt...but .ToString and Integer.Parse are faster (.NET) ways of doing the same thing.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 18th, 2005, 12:51 AM
#14
Fanatic Member
Re: option strict on...
What .Net needs is that annoying paperclip to popup whenever you use some backwards compatible function and say
If wishes were fishes we'd all cast nets.
-
Jan 18th, 2005, 04:10 AM
#15
Re: option strict on...
Backwards compatibility??? CType is not in VB6 
CType, .Convert, DirectCast...
*sigh*
-
Jan 18th, 2005, 08:19 AM
#16
Thread Starter
Banned
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|