By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Difference between Cint and Convert.ToInt32 ?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a

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

P: n/a
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

P: n/a
"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

P: n/a
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.