Solved

Data type questio :How to use a data type other than a variant

Posted on 2003-10-27
2
154 Views
Last Modified: 2012-05-04
Hi,
In my application, I deal with dates which I pull from a database. For some of the records, the date field is blank in the database. When I pull the dates from the database and assign it to a variable (say x), i assign x the value -1 if the date field is blank. In order to do this I need to declare x as a variant(since it has to store a dae variabl or -1). I do not want to store it as a variant. Please let me know of a better way. I am assigning -1 to do some basic error checking. For eg i might do a simple check like this:
if x <> -1 then
     'Do nothing or report date is empty
else
    'use the date fields
end if

hope i have made myself clear.
thanks.
Yegnaram Iyer
0
Comment
Question by:YegnaramIyer
2 Comments
 
LVL 8

Accepted Solution

by:
fozylet earned 65 total points
ID: 9629672
If checking for an empty string or a date available is the only intention,
i would rather use IsDate(x), rather than complicating things.

If IsDate(x) Then
'use the date
Else
'do nothing
End If

If your requirement is not that simple, and you don't want to use Variant, you can use String or Long
Since you can't store -1 in a string ("-1" you can store), you could go for Long.

myLong = CInt(Year(myDate))*10000 + CInt(Month(myDate))*100 + CInt(Day(myDate))

this will give you myLong = yyyymmdd

Then you may extract the date back from it with a reverse process, or by assigning it to a string and doing string manipulation.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 60 total points
ID: 9629710
I use 1/1/1900 as an empty date, and translate the blank date to this.  This way you can use a Date data type, instead of a variant.

Dim CurrentDate As Date

If IsNull(DateField) Then
   CurrentDate = CDate("1/1/1900")
Else
   CurrentDate = DateField
EndIf
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question