Re: Quick Ctype Question
- From: "Miro" <miro@xxxxxxxxx>
- Date: Sun, 10 Feb 2008 10:47:32 -0500
Thank You,
Miro
"Jack Jackson" <jjackson@xxxxxxxxxxxxxxxx> wrote in message news:3e7sq3hope1tku1fvlpduti2agrm3gh5i2@xxxxxxxxxx
On Sat, 9 Feb 2008 14:35:56 -0500, "Miro" <miro@xxxxxxxxx> wrote:
Hi,
During one of my books chapters there is an event created in the form load
with:
AddHandler tbName.DataBindings("Text").Format, AddressOf FormatName
and then the sub underneith it is as follows:
Private Sub FormatName(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If tbName.Tag <> "PARSE" Then
e.Value = CType(e.Value, String).ToUpper() 'My Question is with
this line right here
End If
tbName.Tag = "FORMAT"
End Sub
===
Basically its showing how to use the format of the binding to upper the name
of the database.
I was looking at the e.value = ctype line and replaced it with this:
e.Value = e.Value.ToString.ToUpper
I'm just wondering if there really is a difference between my line of code
vs using the CType function.
I'm assuming both lines would always give out the same results and they
really are identical.
In general ToString() and CType() are not the same, although in some
cases like this one they will return the same value.
Every object has a ToString() method. For a String object, ToString
will just return the string value of the object. For numerical
objects like Integer, Decimal, etc., ToString will convert the numeric
value to a string. For objects that have no intrisic value that can
be represented by a string (like a DataTable), ToString might return
the name of the object, or the class of the object, or whatever the
designer of the class chooses.
CType(obj, String) will try to convert the value to a String. This
will fail (raise an exception) for any object that does not have a
known conversion to string.
In this case, since you know that e.Value is a string, either will
work. It would be faster to use DirectCast() instead of CType(), but
I don't know about the performance of that relative to ToString().
.
- References:
- Quick Ctype Question
- From: Miro
- Re: Quick Ctype Question
- From: Jack Jackson
- Quick Ctype Question
- Prev by Date: Re: Compiling VB application with MySQL DB
- Next by Date: Need help with DataBinder.Eval(Container.DataItem, "mycolumn")
- Previous by thread: Re: Quick Ctype Question
- Next by thread: NetMassDownloader Download .Net Framework Source Code At Once, Enables Offline Debug In VS 2008,2005 And CodeGear Rad Studio
- Index(es):
Relevant Pages
|
Loading