Results 1 to 16 of 16

Thread: option strict on...

  1. #1

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    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 ?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    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

  4. #4

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: option strict on...

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

    Is this option strict really worth it ???

  5. #5

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

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

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  7. #7

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: option strict on...

    Quote 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!

  8. #8

  9. #9

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: option strict on...

    Quote 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

  10. #10
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    Re: option strict on...

    Just a tip.
    Instead of using CType, use DirectCast instead. it works twice as fast.
    VB Code:
    1. DirectCast(Session("FirstName"), String) & " " & DirectCast(Session("LastName"), String)
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  11. #11

  12. #12

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: option strict on...

    Quote 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

  13. #13
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    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

  14. #14
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    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.

  15. #15

  16. #16

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: option strict on...

    Quote Originally Posted by Graff
    What .Net needs is that annoying paperclip to popup whenever you use some backwards compatible function and say

    HAHAHAHAHAHHAAHHAAH I have never seen that you liar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width