PDA

Click to See Complete Forum and Search --> : option strict on...


jhermiz
Jan 17th, 2005, 06:26 AM
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 ?

crptcblade
Jan 17th, 2005, 06:37 AM
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).

Wokawidget
Jan 17th, 2005, 06:55 AM
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

jhermiz
Jan 17th, 2005, 07:09 AM
Too late...I got it :-p...

Is this option strict really worth it ???

jhermiz
Jan 17th, 2005, 07:14 AM
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:

crptcblade
Jan 17th, 2005, 07:25 AM
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#.

jhermiz
Jan 17th, 2005, 09:18 AM
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!

Wokawidget
Jan 17th, 2005, 09:34 AM
It is worth it. You have not wasted your time.

Woka

jhermiz
Jan 17th, 2005, 09:35 AM
It is worth it. You have not wasted your time.

Woka

I know i am just giving you a hard time :p

Memnoch1207
Jan 17th, 2005, 12:41 PM
Just a tip.
Instead of using CType, use DirectCast instead. it works twice as fast.

DirectCast(Session("FirstName"), String) & " " & DirectCast(Session("LastName"), String)

Wokawidget
Jan 17th, 2005, 12:46 PM
OK.
Why are there so many ways to do the same thing though?
Why have a CType function?

Woka

jhermiz
Jan 17th, 2005, 01:17 PM
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

Memnoch1207
Jan 17th, 2005, 02:16 PM
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.

Graff
Jan 17th, 2005, 11:51 PM
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

Wokawidget
Jan 18th, 2005, 03:10 AM
Backwards compatibility??? CType is not in VB6 :confused:

CType, .Convert, DirectCast...

*sigh*

jhermiz
Jan 18th, 2005, 07:19 AM
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: