Code/Tea/Etc...

Duncan Mackenzie has too much time on his hands

Paul Vick on two new operators in VB Whidbey

In a recent post to his blog, Paul Vick discusses the new IsNot Operator (and the history/rational behind the Is operator), which allows you to write;
If myString IsNot Nothing Then
instead of
If Not myString Is Nothing Then
and then, in another post, he covers the new TryCast operator (which is like C#'s 'as' operator), which will allow you to save a bit of extra work (and produce a slight perf improvement in some situations) when checking to see if an object can be cast to a specific type .... allowing you to write;
Sub Print(ByVal o As Object)
    Dim PrintableObject As IPrintable _
= TryCast(o, IPrintable) If PrintableObject IsNot Nothing Then PrintableObject.Print() End If ... End Sub
instead of the slightly less efficient
Sub Print(ByVal o As Object)
    Dim PrintableObject As IPrintable
    If TypeOf o Is IPrintable Then
        PrintableObject = CType(o, IPrintable)
        PrintableObject.Print()
    End If
    ...
End Sub
Published Tuesday, March 02, 2004 3:36 PM by Duncanma

Comments

 

Kent Sharkey said:

First one should have been Aint. This way, we could get into childish arguments:

If myThing Is IsNot Is IsNot Nothing then...
'Says you...
End If

The TryCast will be cool, though. It's been one of the very few items (As) I've really started to like in C# and miss in VB.

TTFN- Kent
March 2, 2004 4:32 PM
 

AddressOf.com said:

March 2, 2004 8:58 PM
 

Chris Sells said:

Both of those look cool to me.
March 2, 2004 7:45 PM
 

shivnil said:

Hi,

I am doing a project on forex. my client's requirement is that the currency values should be update daily by the system itself.
I am developing the system in VB/Access.
There is website of Thomas Cook which contains the table of all currency values. The link as below :
http://www.thomascook.co.in/tc/user/forex/forexcurrencyrates.jsp?jsessionid=2580261077697883828

So, my problem I want the currency values, in the above link to update my 'Currency_Master' Table in MS-Access when click a command button.

Please help or provide some code for it on
shivnil2@rediffmail.com.

thank you,
with regards,
shivnil
March 2, 2004 10:37 PM
 

.NET Brain Droppings said:

March 4, 2004 10:48 PM
 

Darren Neimke said:


Great, now we can finally start to write some "proper" code:

If Not something IsNot somethingElse Then
...
End If

:)
March 5, 2004 1:24 AM
 

Ant said:

The IsNot operator seems a bit pointless but the TryCast is quite a nice touch, even though I can't imagine that the performance improvement will be that significant.
March 5, 2004 3:41 AM
 

Joey said:

IsNot is equivalent to using <> instead of not(x=y), so to my mind it fills a little gap.

TryCast is extra sweet if you have to check for nothing anyway.
March 5, 2004 5:49 AM
 

james said:

how do i move an image around the page like it is moving?
March 5, 2004 10:53 PM
 

rami emam said:

i make project by bv5 with data base
this db i well make password for he
how 2 open this data base in my proeject
when press f5 i c msg
inviled password
please f u can send 2 my this code
thank 4 help
March 8, 2004 4:56 AM
 

parviz said:

teaching VB6
March 8, 2004 9:42 AM
 

Joku said:

Why it has to be such horribe looking mess? For example:

If myString IsNot Nothing Then

Could be:
if (myString) { }

and

If myString Is Nothing Then

could be:
if (!myString) { }

Much more clean and simpler.
March 9, 2004 8:17 AM
Anonymous comments are disabled

This Blog

Syndication

News

This blog has moved to my own VB site

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker