Results 1 to 3 of 3

Thread: syntax

  1. #1

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    syntax

    Simple question, regarding .net syntax more than anything.
    I'm a vb6 coder, new to .net and its way of working... anyway, I'm using the follow bit of code. If the Querystring item "ID" is not passed then szPage will be 'Nothing'.

    VB Code:
    1. Dim szPage as String = Request.QueryString("ID")
    2. If szPage = "12345" Then
    3.   'Do This
    4. Else
    5.   'Do Summat Else
    6. End If

    If ID is not passed this produces an error ... Now I can sort this by doing;

    VB Code:
    1. If Not (Request.QueryString("ID") Is Nothing) Then
    2.   Dim szPage as String = Request.QueryString("ID")
    3.   If szPage = "12345" Then
    4.     'Do This
    5.   Else
    6.     'Do Summat Else
    7.   End If
    8. Else
    9.   'Error
    10. End If

    I know .NET has some much better ways of working with objects and I am very tuned into vb6 which I find can be a prob when using .net. This code just seems a bit long winded for something thats going to be very common... is there a BETTER/shorter way of writing this code?

    Cheers for any replys,

    GaZ

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Well, you could create a function called 'ParseQueryString' that will do all the validation checks and have it return to you an empty string if the query string was not passed. You must remember that a string is a reference type, with its default value being null (not an empty string).

  3. #3

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    ye I realise that, I was more 'worried' about not writing code the 'correct' way.

    I'll just create the function :P

    thanks :]

    GaZ

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