Need help finding if a value is a particular data type.

  • Thread starter Thread starter dave m
  • Start date Start date
D

dave m

I'm trying to create a function that , when passed a value from a cell in a
data grid, will return that value if it is an integer, otherwise it returns
a 0 (like if the value were from a empty cell or containing a string). Is
there a function that will tell me if a certain value is of a particular
datatype?

Thanks in advance!

Dave M.
 
Dave,

The most simple thing is to get the datasource datatable part
Column.DataType

I hope this helps,

Cor
 
If you always convert the cell to a string before evaluating the
string, you could use the follwing function to convert a string to an
integer, or pull just the integer part from a string. It's useful for
getting addresses or telephone numbers from differently formatted
strings.

'---------- Get the numbers from a string ----------
Public Function AtoI(ByVal s As String, ByVal bNumbersOnly As Boolean)
As Integer
Dim nLen As Integer
Dim i As Integer
Dim nDigit As Integer
Dim nTot As Integer

nTot = 0
nLen = s.Length
For i = 0 To nLen - 1
nDigit = Asc(s.Substring(i, 1)) - 48
If nDigit >= 0 And nDigit <= 9 Then
nTot = nTot * 10 + nDigit
Else
If bNumbersOnly Then
nTot = -1
Exit For
End If
End If
Next i
Return (nTot)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top