Friday, March 16, 2012

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 ?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).
Session("FirstName") & " " & Session("LastName")

Should be:

CType(Session("FirstName"), String) & " " & CType(Session("LastName"), String)
'or
Session("FirstName").ToString & " " & Session("LastName").ToSTring

and

If Session("Admin") = True Then

Should be:

If CType(Session("Admin"), Boolean) = True Then

and

If FormatDateTime(Now(), 4) > "12:00" Then

should be

If FormatDateTime(Now(), DateFormat.ShortTime) > "12:00" Then

Woka
Too late...I got it :-p...

Is this option strict really worth it ?
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++ :rolleyes:
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#.
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!
It is worth it. You have not wasted your time.

Woka
It is worth it. You have not wasted your time.

Woka

I know i am just giving you a hard time :p
Just a tip.
Instead of using CType, use DirectCast instead. it works twice as fast.

DirectCast(Session("FirstName"), String) & " " & DirectCast(Session("LastName"), String)
OK.
Why are there so many ways to do the same thing though?
Why have a CType function?

Woka
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
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.
What .Net needs is that annoying paperclip to popup whenever you use some backwards compatible function and say

http://jinexile.1337geek.com/imgs/vbassistant.gif
Backwards compatibility? CType is not in VB6 :confused:

CType, .Convert, DirectCast...

*sigh*
What .Net needs is that annoying paperclip to popup whenever you use some backwards compatible function and say

http://jinexile.1337geek.com/imgs/vbassistant.gif

HAHAHAHAHAHHAAHHAAH I have never seen that you liar :lol: :lol: :lol: :lol: :lol:

0 comments:

Post a Comment