Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2008, 01:10 AM
Authorized User
 
Join Date: Mar 2008
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default CInt versus Integer.Parse - what's the difference?

1) What's the difference between CInt and Integer.Parse?
2) Which of two is preferable?

 
Old June 4th, 2008, 08:53 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If I understand it correctly, CInt is only for conversion of compatible (and thus convertible) types.

You can convert a numeric type that is not an System.Integer32 (i.e. float, decimal, byte, single, etc.) into an System.Integer32 if the value is really an integer. If you tried to convert 1.1 to a System.Integer32 it would throw an exception.

You can not convert a System.String to a System.Integer32 even if the string's value is a numeric value (ex. "1"). You must parse the string. In the same vain, you basically can't convert a string to anything (perhaps aside from System.Object). It must be parsed (read) into the appropriate type (numeric, datetime, etc).

-Peter
compiledthoughts.com
 
Old June 5th, 2008, 04:23 AM
Authorized User
 
Join Date: Mar 2008
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default

Thanks a lot!
So, when a user enters something in TextBox, then I gotta parse it instead of converting it to some data type. It's all clear now!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference bet Convert.Toint32 and Int.Parse anujrathi General .NET 3 September 8th, 2007 02:31 AM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
cdbl or cint crmpicco Classic ASP Basics 2 November 9th, 2005 11:49 AM
whats up with round() and cint() returning even lcsgeek Classic ASP Basics 7 August 20th, 2003 03:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.