Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date verification

Status
Not open for further replies.

Sagit

Technical User
Dec 19, 2007
6
GB
Hi All,

I have a code in Visual Basic to verify if a copy is valid or expired. In VBA works fine, however I cannot put it straight as it is into Attachmate Basic (it does not work).
Does anybody know what is wrong and how to rewrite it, please?

Sub Ver()

Dim exp As Date 'variable to holds expiration date

exp = #1/30/2008#

If exp < Date Then 'check expiration date vs today's date

Debug.Print "Expired" 'sample action if condition is true

Else

Debug.Print "OK" ' sample action if condition is false

End If

End Sub

regards,
Sagit
 


Hi,

Try this
Code:
exp = #2008/01/30#
Your original TEXT format is ambiguous. use a yyyy/mm/dd TEXT format to CONVERT.

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Date is not a variable type in my version of EXTRA so you just declare the variable without a type.

Code:
Option Explicit

Sub Main()
    Dim exp 'variable to holds expiration date

    exp = #1/30/2008#

    If exp < Date Then     'check expiration date vs today's date
        msgbox "Expired"      'sample action if condition is true
    Else
        msgbox "OK"     ' sample action if condition is false
    End If

End Sub

For some reason my Macro Editor kept messing up with this. I finally changed the Sub name to "Main" and closed everything out.
 
will try, thanks a lot, rgds Dom
 




My version of Attachmate!Extra...
HELP said:
This example displays the date for one week from the today's date (the current date on the computer).
Code:
Sub main
	Dim nextweek
	nextweek=CVar(Date)+7
	MsgBox "One week from today is: " & Format(nextweek,"ddddd")
End Sub
Copyright 1996 - 1999, Attachmate Corporation. All Rights Reserved.

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Hi Lads,

It does not work.

I tried many times many options but it does not work at all.
If I try to declare variable 'exp' as date I receive a 'syntax error' bug message.
I set up watch window for variable 'exp' to compare it to current date, but 'date' cannot be evaluate. Why is like that?
So, which command is to obtain current system date and time?
How to put in into code?

regards, sagit
 



What does your Attachmate HELP indicate?

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Code:
Sub Main()
  Dim dExp
  dExp = DateValue("1/30/2008")
  If dExp < Date Then 'May require DateValue(Date)
    MsgBox "Expired"
  Else
    MsgBox "OK"
  End If
End Sub
 



Yes, it could have been the TEXT to DATE conversion, where VB uses #.

I would strongly recommend, however, that you use the UNAMBIGUOUS yyyy/mm/dd text format, rather than a mm/dd... or dd/mm... text format that is AMBIGUOUS and can yield unexpected results under certain conditions.

Or
Code:
  dExp = DateSerial(2008,1,30)

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top