Re: Get Data Type

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

Brian Wilson wrote:
Hi All,

[quoted text clipped - 9 lines]

Are there are existing functions/methods that handle this?

None of the languages you mention have anything to do with Microsoft Access.
If you are using Access, then the language is written in VBA which ,like VB
and VB.Net, is a strongly-typed language as opposed to VBScript which is
not. You say you are not fussed which, but it matters a great deal since
using VBScript you cannot write:
Dim MyString As String
Since no variable is of any particular type - they are all variants.

But back to Access and VBA. Assuming you really have a string, then it is a
string - not a date nor a number. But, could it be converted to a date or a
number? Well, possibly... and you could use the CDate or Clng functions to
check. These will raise a runtine error if it cannot be done. For example,
writing Clng("egg") will cause an error.
However, just because it might be able to be changed into a long, it doesn't
mean it should be. So if you string had a value of 42.5 you would not say
this was a long integer. But Clng(42.5) does not fail because it converts
it to 42. In other words, it is easy to tell that "egg" cannot be converted
to a number, but could "24" be converted to a date. Yes it could, but it
could also be converted to text, long, integer,boolean.

So if you are working with strings, then you might be better to write you
own function that compares the string to a pattern. However, I have no idea
how you would distinguish the text value "True" from the boolean value true.

The short answer is, if you neeed to work with different types, then use
different types together with the variant type then you have available the
built in functions TypeName and VarType.

E.g.
Dim dteDate as Date
dteDate=DateSerial(1965,01,01)
MsgBox TypeName(dteDate)

However, if you only use strings this can't work
Dim strDate as String
strDate="1965-01-01"
MsgBox TypeName(strDate)

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/200603/1
.



Relevant Pages

  • Re: "Type Mismatch" calling GetExecutionErrorInfo Method from VBscript
    ... I have experienced this type of problem before in vbscript and also in the sp_OA% SQL Server Object Automation procedures. ... Public Function GetExecutionErrorInfoAs String ... Dim strSource As String ... Dim strDescr As String ...
    (microsoft.public.sqlserver.dts)
  • Re: VBScript errors with Date?
    ... >I was playing with date functions in VBScript, ... One should *never* use a string representing a date in D M Y order, ... When converting "in detail" to a date string, ...
    (microsoft.public.scripting.vbscript)
  • Re: Regex bug in library
    ... However, when there are accents in the name, the VBScript library falls ... Dim sVBScript As String ... target spec for the VBScript implementation) word characters are limited to ...
    (microsoft.public.scripting.vbscript)
  • Re: Dir
    ... i wrote the following script to automatically crop ... >> Dim strFile As String ... > First, this is not vbscript. ...
    (microsoft.public.scripting.vbscript)
  • Re: Dir
    ... i wrote the following script to automatically crop ... > Dim strFile As String ... First, this is not vbscript. ...
    (microsoft.public.scripting.vbscript)