"Göran Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> rowe_newsgroups wrote:
>> On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.com> wrote:
>>> Is there a way to determine if a numeric value contains a decimal? how
>>> to do
>>> this?
>>>
>>> If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a
>>> numeric
>>> value. How can I tell if it is a plain integer or decimal?
>>>
>>> Thanks,
>>> Rich
>>
>> Parse the string for a period using IndexOf.
>>
>> <pseudocode>
>>
>> if IsNumeric(txt1.Text) then
>> if txt1.IndexOf(".") <> -1 then
>> ' Decimal
>> else
>> ' Integer
>> end if
>> end if
>>
>> </pseudocode>
>>
>> Thanks,
>>
>> Seth Rowe
>>
>>
>>
>
> That's assuming that the decimal separator is a period, which it isn't
> everywhere.
>
> The decimal separator for any given culture can be found in the
> NumberFormat.NumberDecimalSeparator property.
>
> --
> Göran Andersson
> _____
> http://www.guffa.com
Couldn't you also do something along the lines of:
If IsNumeric(txt1.Text) Then
If CLng(txt1.Text) / 1 = CLng(txt1.Text) \ 1 Then
'Integer
Else
'Decimal
End If
End If
Or, if you're doing this a lot and making a decision based on it...
Public Function IsReal (ByVal Number As Object) As Integer
Dim i As Integer
i = -1 'Fail
If IsNumeric(Number) Then
If CLng(Number) / 1 = CLng(Number) \ 1 Then
i = 0 'Integer
Else
i = 1 'Real
End If
End If
Return i
End Function
If IsReal(txt1.Text) < 1 Then MessageBox.Show("I want a real!!!")
If IsReal(txt2.Text) <> 0 Then MessageBox.Show("I want an integerl!!!")
I've just realised that this wouldn't work for "4.000000", but I'll let you
have it anyway. :\