469,579 Members | 1,899 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Difference between Cint and Convert.ToInt32 ?

Hello

txtID.Text contains a 6 digit Integer number with no decimals, no chars...

Dim j As Integer = Cint(txtID.Text)

or

Dim j As Integer = Convert.ToInt32(txtID.Text)

Is there any difference between these 2 statements? Is one statement more
correct than the other?

Thanks,
Rich
Jul 21 '06 #1
4 13742

Rich wrote:
<snip>
txtID.Text contains a 6 digit Integer number with no decimals, no chars...

Dim j As Integer = Cint(txtID.Text)

or

Dim j As Integer = Convert.ToInt32(txtID.Text)

Is there any difference between these 2 statements? Is one statement more
correct than the other?
<snip>

Well, there *is* a difference:

any the following literals would raise an exception if Convert.ToInt32
was used instead of CInt:

? CInt("123.456")
? CInt("123,456")
? CInt("&h123")

In other words, CInt (when passed a string) performs more work than
Convert.ToInt32.

Regards,

Branco

Jul 21 '06 #2
Thanks. I guess I will stay with Convert.ToInt32.

Rich
"Branco Medeiros" wrote:
>
Rich wrote:
<snip>
txtID.Text contains a 6 digit Integer number with no decimals, no chars...

Dim j As Integer = Cint(txtID.Text)

or

Dim j As Integer = Convert.ToInt32(txtID.Text)

Is there any difference between these 2 statements? Is one statement more
correct than the other?
<snip>

Well, there *is* a difference:

any the following literals would raise an exception if Convert.ToInt32
was used instead of CInt:

? CInt("123.456")
? CInt("123,456")
? CInt("&h123")

In other words, CInt (when passed a string) performs more work than
Convert.ToInt32.

Regards,

Branco

Jul 21 '06 #3
"Rich" <Ri**@discussions.microsoft.comschrieb:
txtID.Text contains a 6 digit Integer number with no decimals, no chars...

Dim j As Integer = Cint(txtID.Text)

or

Dim j As Integer = Convert.ToInt32(txtID.Text)

Is there any difference between these 2 statements? Is one statement more
correct than the other?
Not really. I'd try to avoid 'Convert.ToInt32' and use 'CInt' or
'Integer.Parse' instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 22 '06 #4
Rich,

Yes there are,
Convert.ToInt32 is longer and it converts to Int32
CInt converts to Integer what should be represent the best internal format
to use by the computer. Unlucky enough has a big lobby changed the last for
the 64bit version and are there extra instructions needed now (they are fast
but still take time).

Cor

"Rich" <Ri**@discussions.microsoft.comschreef in bericht
news:8B**********************************@microsof t.com...
Hello

txtID.Text contains a 6 digit Integer number with no decimals, no chars...

Dim j As Integer = Cint(txtID.Text)

or

Dim j As Integer = Convert.ToInt32(txtID.Text)

Is there any difference between these 2 statements? Is one statement more
correct than the other?

Thanks,
Rich

Jul 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Convert TextBox.Text to Int32 Problem | last post: by
8 posts views Thread by Jarod | last post: by
5 posts views Thread by chenedor | last post: by
15 posts views Thread by Brian Henry | last post: by
16 posts views Thread by Jim in Arizona | last post: by
4 posts views Thread by tshad | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.