Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCAD > CInt in VB.net

Reply
Thread Tools

CInt in VB.net

 
 
Guest
Posts: n/a
 
      01-17-2005
Hi,

I have a question regarding the use of CInt and/or Char
member functions.

Let's say I have an input string,

Dim input As String = "7.5"

and I need to check if this string(number) is either 7 or
8 (or so on....), I use the CInt function and compare the
value using If-statement.

"7.5" is supposed to return false to me but CInt now
turns it into 8 (so it returns true now)

Any ideas to fix that?

thanks.
 
Reply With Quote
 
 
 
 
Marc M
Guest
Posts: n/a
 
      01-18-2005
CInt will convert to Interger
CDouble will help you.
C???? are leftover of old VB 6, try to get away from it

In .Net it is better to use CType like

if CType(input, double) ....

Good luck
Marc M
MCSD (6.0 & .NET)

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I have a question regarding the use of CInt and/or Char
> member functions.
>
> Let's say I have an input string,
>
> Dim input As String = "7.5"
>
> and I need to check if this string(number) is either 7 or
> 8 (or so on....), I use the CInt function and compare the
> value using If-statement.
>
> "7.5" is supposed to return false to me but CInt now
> turns it into 8 (so it returns true now)
>
> Any ideas to fix that?
>
> thanks.

 
Reply With Quote
 
 
 
 
Marc M
Guest
Posts: n/a
 
      01-18-2005
CInt will convert to Integer
Use CDouble.
All C????? are old VB 6.0 syntax

In .Net use CType to convert like

If CType(input, Double) .......

Hope this helps

Marc M
MCSD (6.0 & .NET)


(E-Mail Removed) wrote:

> Hi,
>
> I have a question regarding the use of CInt and/or Char
> member functions.
>
> Let's say I have an input string,
>
> Dim input As String = "7.5"
>
> and I need to check if this string(number) is either 7 or
> 8 (or so on....), I use the CInt function and compare the
> value using If-statement.
>
> "7.5" is supposed to return false to me but CInt now
> turns it into 8 (so it returns true now)
>
> Any ideas to fix that?
>
> thanks.

 
Reply With Quote
 
Guest
Posts: n/a
 
      01-21-2005

>-----Original Message-----
>Hi,
>
>I have a question regarding the use of CInt and/or Char
>member functions.
>
>Let's say I have an input string,
>
>Dim input As String = "7.5"
>
>and I need to check if this string(number) is either 7 or
>8 (or so on....), I use the CInt function and compare the
>value using If-statement.
>
>"7.5" is supposed to return false to me but CInt now
>turns it into 8 (so it returns true now)
>
>Any ideas to fix that?
>
>thanks.
>


Best way (I think) use .Net System.Convert.ToDouble or
System.Convert.ToDecimal with try & catch. If convert
successful then it is number else it is not.

Example

Public Function SomeFunct(ByVal s As String) As Double
Dim x As Double

' lets say s = "7.1"
Try
x = System.Convert.ToDouble(s)
Return x;
Catch ex As Exception
Return -1 'set -1 to inform you that not number!
End Try

End Function

Hope that helpful.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fail To Cast: DirectCast(dataRow(CInt(enum AlertDataGridColumns.Details)),String) pbd22 ASP .Net 0 03-12-2008 10:34 PM
what's the vbscript's cint() function in javascript amy Javascript 8 10-17-2003 05:41 PM



Advertisments