Re: Get Data Type

Tech-Archive recommends: Fix windows errors by optimizing your registry



"IanOxon via AccessMonster.com" <u18965@uwe> wrote in message
news:5d9649cada55d@xxxxxx
Hi Brian,

Thanks for your reply. I take your point about VBScript, but what I had
in
mind was an uber string/data handling (or similar) class/function in any
of
the three languages, (or reference files based on them). If there was,
then
adding a reference to the appropriate type library or ocx should expose
the
methods and properties of the object.

If I've got to do it the hard way I've been thinking along the lines of:

1. Ignoring empty strings (no information about possible data type)
2. Using IsNumeric(Value) to filter for numeric and text values.
3. Filtering numeric values with IsDate(Value).
4. Using Length(Value) for IsNumeric(Value) = False values to distinguish
bewteen dbText and dbGUID & dbMemo.

And so on... But this will be a long selection process and I'm just
trying
to avoid re-invent the wheel!

Cheers


Ian



Hi Ian
I hope I made the following clear:
The easiest and most technically correct way to do what you wish to do is to
use variables of different types.

If you were asked to design a database for contacts which had a uniqueID, a
first name, a last name, a date of birth and a height in metres then it
would be pretty unusual to have each field in the table as text and then try
and work out what sort of text it is. Normally, the ID would be a long
integer, the names would be text, the dob a date and the height perhaps a
single.
When I read the values from the table, I read them into appropriate
variables:

e.g.
strFirstName=MyRecordset.Fields("FirstName")
lngContactID=MyRecordset.Fields("ContactID")

If I then needed to find out what datatype these variables were I could use:
?TypeName(strFirstName) which returns "String"
?TypeName(lngContactID) which returns "Long"

Alternatively
?VarType(strFirstName) which returns the constant vbString=8
?VarType(lngContactID) which returns the constant vbLong=3


THIS REALLY IS THE WAY TO GO. However, imagine you have no choice and for
some reason you are passed a series of strings and have to work out what
datatype they are, then what could you do? Well I would not use any of the
built-in functions because they accept too wide a range of values. If I
wanted to know if a string represented a positive long integer then I would
want to know that each character in the string was 0-9 so I might ask
If strValue Like String$(Len(strValue), "#")

or for a date in international format, I could look for:
If strValue Like "####-##-## ##:##:##" Then

Finally, as a double check explicitly convert to the datatype to force an
error if it can't be converted.
THE PROBLEM YOU STILL HAVE is how do you know if 562 is supposed to be text,
an integer, a long integer - or how can you distinguish between the literal
text value of "True" and the boolean datatype. The truth is you cannot.


.



Relevant Pages

  • Help!! Oracle 9.2.0.5.0 wont properly read the *.rsp
    ... #Datatype: String ... #Datatype: Boolean ... #This page shows the current status in the installation. ...
    (comp.databases.oracle.server)
  • Re: GOSUB, the larger picture (was Worldwide known Excellence of GOSUB)
    ... > does not mean that was not a hack. ... Yep, a Byte datatype was indeed needed, and welcome! ... No need to break String, ... It aint bigger Karl, ...
    (microsoft.public.vb.general.discussion)
  • Re: Access Query Right Align
    ... Gary - The DataType is text for all fields. ... Dim hFile As Long ... Dim strPath As String ... Dim strTextLine As String ...
    (microsoft.public.access.queries)
  • Re: Get Data Type
    ... the data types of the resultant columns - similiar to the decisions made by ... If I then needed to find out what datatype these variables were I could use: ... wanted to know if a string represented a positive long integer then I would ...
    (microsoft.public.access.modulesdaovba)
  • Re: converting data to null using DBNull problem
    ... the DBNull Object can only be set to a String type so ... setting the datatype here to other than string type would cause an error. ... It is possible to set the datatype here though and use thte Parse function ...
    (microsoft.public.sqlserver.dts)