|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
"If" statement asking for integerHi,
I'm pretty new to Visual Basic and programming in general. I want to know if it's possible to create an If statement that asks if a value is an integer. If it's an integer it does one thing, if it's a decimal value it does something else. Something like the following... If i = integer Then ..... a.... Else ...... b ..... EndIf Seems like it should be fairly simple to me. Any help would be appreciated, thanks. Hi,
If is integer or decimal? I don't know... but you can use If IsNumeric(value) If NOT IsNumeric(value) code in VB.NET of kors Mrozu Jacob.Bru***@ec.gc.ca napisal(a): Show quoteHide quote > Hi, > I'm pretty new to Visual Basic and programming in general. I want to > know if it's possible to create an If statement that asks if a value is > an integer. If it's an integer it does one thing, if it's a decimal > value it does something else. Something like the following... > > If i = integer Then > .... a.... > Else > ..... b ..... > EndIf > > Seems like it should be fairly simple to me. Any help would be > appreciated, thanks. I don't know if there is a more elegant way, but this will work:
if cdbl(cint(i)) = i then ' i is an integer else ' i is not an integer endif If i = 5.2, say, then cint(i) gives 5, cdbl(cint(i)) gives 5.0 and the test fails. I hope this helps, -- Show quoteHide quoteHelen "Jacob.Bru***@ec.gc.ca" wrote: > Hi, > I'm pretty new to Visual Basic and programming in general. I want to > know if it's possible to create an If statement that asks if a value is > an integer. If it's an integer it does one thing, if it's a decimal > value it does something else. Something like the following... > > If i = integer Then > ..... a.... > Else > ...... b ..... > EndIf > > Seems like it should be fairly simple to me. Any help would be > appreciated, thanks. > >
Show quote
Hide quote
> Hi, If TypeOf i is Integer then> I'm pretty new to Visual Basic and programming in general. I want to > know if it's possible to create an If statement that asks if a value > is > an integer. If it's an integer it does one thing, if it's a decimal > value it does something else. Something like the following... > If i = integer Then > .... a.... > Else > ..... b ..... > EndIf > Seems like it should be fairly simple to me. Any help would be > appreciated, thanks. > ' do something ElseIf TypeOf i is Decimal then ' do something Else Throw New ArgumentException() End If Jim Wooley http://devauthority.com/blogs/jwooley/default.aspx <Jacob.Bru***@ec.gc.ca> schrieb:
> I'm pretty new to Visual Basic and programming in general. I want to 'If d = CInt(d) Then...'> know if it's possible to create an If statement that asks if a value is > an integer. If it's an integer it does one thing, if it's a decimal > value it does something else. Something like the following... > > If i = integer Then > .... a.... > Else > ..... b ..... > EndIf -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Hi
If you're using .Net 2 then you could try using Int32.TryParse(yourvalue) Cheers Martin Herfried K. Wagner [MVP] wrote: Show quoteHide quote > <Jacob.Bru***@ec.gc.ca> schrieb: > > I'm pretty new to Visual Basic and programming in general. I want to > > know if it's possible to create an If statement that asks if a value is > > an integer. If it's an integer it does one thing, if it's a decimal > > value it does something else. Something like the following... > > > > If i = integer Then > > .... a.... > > Else > > ..... b ..... > > EndIf > > 'If d = CInt(d) Then...' > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Jacob.Bru***@ec.gc.ca wrote:
> I'm pretty new to Visual Basic and programming in general. I want to Do you mean> know if it's possible to create an If statement that asks if a value is > an integer. (a) The /value/ in a variable is an integer? If i = Int( i ) Then ... (b) The /Type/ of the variable holding the value is an Integer? If TypeOf i Is Integer Then ... The latter test extends to all data types, including you own classes, as in If TypeOf sender Is CustomListView Then With DirectCast(sender, CustomListView) ... End With ... HTH, Phill W.
For Next Loop - Manual Might Be Wrong
API FindFirstFile\FindNextFile vs GetFiles How to Type cast ArrayList items to class objects Best practices for creating a "wizard" VB 2005 with Active Directory Application quit after button click Strange Datagrid Behavior use varible value in include file How to use Resource files in VS 2005? EventType clr20r3 system.io.filenotfoundexception |
|||||||||||||||||||||||