|
-
Oct 17th, 2003, 04:07 AM
#1
Thread Starter
Hyperactive Member
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:
Dim szPage as String = Request.QueryString("ID")
If szPage = "12345" Then
'Do This
Else
'Do Summat Else
End If
If ID is not passed this produces an error ... Now I can sort this by doing;
VB Code:
If Not (Request.QueryString("ID") Is Nothing) Then
Dim szPage as String = Request.QueryString("ID")
If szPage = "12345" Then
'Do This
Else
'Do Summat Else
End If
Else
'Error
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
-
Oct 17th, 2003, 08:02 AM
#2
PowerPoster
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).
-
Oct 17th, 2003, 08:12 AM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|