Advice requested 
Author Message
 Advice requested

I am confused about the following statement in the Help
file:

The Visual Basic .NET runtime evaluates Nothing as an
empty string; that is, "". The .NET Framework, however,
does not, and will throw an exception whenever an attempt
is made to perform a string operation on Nothing.

So, should I always check whether a String is Nothing
before I try to execute a method (such as myString.Length)?

Thanks.

Venkat



Tue, 28 Dec 2004 21:04:11 GMT  
 Advice requested
A code sample would probably help make this a little clearer.  Notice that
"x" hasn't been intialized, but when passed to the messagebox, it simply
displays a blank message box.  But once you really try to do something with
that variable, a null reference exception is thrown.

        Dim x As String
        Try
            MessageBox.Show(x)
            MessageBox.Show(x.Length.ToString)
        Catch err As System.Exception
            MessageBox.Show(err.Message)
        End Try

 Thank You,
 Dale Roberson
 Microsoft Developer Support

 This posting is provided "AS IS" with no warranties, and confers no rights.
 You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.



Tue, 28 Dec 2004 22:12:26 GMT  
 Advice requested
Well, that seems kind of stupid. Shouldn't the VB Runtime and the .NET
Framework be congruent? I guess in some cases, compatibility with VB6 was
kept to lower the learning curve (and to keep all those VB6,
anti-.NET/anit-change people from exploding). I personally feel that with
VB.NET, MS should have run roughshod over the old code and broke
compatibility entirly, because if an upgrade is going to break your code
anyway, why not just clean house? That is just my uninformed, and bias
opinion.

Jeremy



Quote:
> A code sample would probably help make this a little clearer.  Notice that
> "x" hasn't been intialized, but when passed to the messagebox, it simply
> displays a blank message box.  But once you really try to do something
with
> that variable, a null reference exception is thrown.

>         Dim x As String
>         Try
>             MessageBox.Show(x)
>             MessageBox.Show(x.Length.ToString)
>         Catch err As System.Exception
>             MessageBox.Show(err.Message)
>         End Try

>  Thank You,
>  Dale Roberson
>  Microsoft Developer Support

>  This posting is provided "AS IS" with no warranties, and confers no
rights.
>  You assume all risk for your use. ? 2001 Microsoft Corporation. All
rights
> reserved.



Wed, 29 Dec 2004 00:47:08 GMT  
 Advice requested
One thing to do that helps is to make sure to turn on Option Strict
for every project. That way ambiguous code breaks sooner rather than
later.

-- Mary
MCW Technologies
http://www.mcwtech.com

On Fri, 12 Jul 2002 16:47:08 GMT, "VisualCore.com"

Quote:

>Well, that seems kind of stupid. Shouldn't the VB Runtime and the .NET
>Framework be congruent? I guess in some cases, compatibility with VB6 was
>kept to lower the learning curve (and to keep all those VB6,
>anti-.NET/anit-change people from exploding). I personally feel that with
>VB.NET, MS should have run roughshod over the old code and broke
>compatibility entirly, because if an upgrade is going to break your code
>anyway, why not just clean house? That is just my uninformed, and bias
>opinion.

>Jeremy



>> A code sample would probably help make this a little clearer.  Notice that
>> "x" hasn't been intialized, but when passed to the messagebox, it simply
>> displays a blank message box.  But once you really try to do something
>with
>> that variable, a null reference exception is thrown.

>>         Dim x As String
>>         Try
>>             MessageBox.Show(x)
>>             MessageBox.Show(x.Length.ToString)
>>         Catch err As System.Exception
>>             MessageBox.Show(err.Message)
>>         End Try

>>  Thank You,
>>  Dale Roberson
>>  Microsoft Developer Support

>>  This posting is provided "AS IS" with no warranties, and confers no
>rights.
>>  You assume all risk for your use. ? 2001 Microsoft Corporation. All
>rights
>> reserved.



Wed, 29 Dec 2004 06:35:55 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Expert Advice Requested: Automation / GetObject Question

2. Multiple forms - datatable advice request

3. Data Entry Advice Requested

4. Advice requested on ocx licencing issue

5. File, Record, Field Help/Advice requested

6. Advice requested: Rich Text Box

7. Advice Requested

8. Advice Requested

9. DCOM problem - Advice requested

10. Requesting advice from the Senior VB Programmers...

11. A request for advice re: vb4

12. Request Advice on VB3&VB4 code.

 

 
Powered by phpBB® Forum Software