Solved

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

Posted on 2003-10-27
2
151 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now