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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable + 1 question

Status
Not open for further replies.

Person51

Programmer
Mar 3, 2006
16
0
0
US
I almost have the macro completed, but in an effort to get one less user input box, i'm trying something different. In this macro, I get a variable (labeled ddate) for a calendar date. It then runs into two if/then statements, and if the second if/then option is chosen, it needs to write the variable ddate in a mm-dd-yy format +1 on the dd part. so basically if the user entered 03-03-06 and chose my second if/then, how would get it to add one day to mm to have it display 03-04-06? Many thanks, B.P.
 
How are you building your date variable?

Code:
Sub Main

Dim SomeInput
Dim RealDate
Dim DisplayDate As String

SomeInput = "03/03/06"'mm/dd/yyyy or m-d-yy
SomeInput = Datevalue(SomeInput)+1

If IsDate(SomeInput)=-1 then
    RealDate=SomeInput
    DisplayDate = Cstr(Month(RealDate))+"-"+Cstr(Day(RealDate))+"-"+cstr(Year(RealDate))
    Msgbox DisplayDate
End If

End Sub
 
Hey thanks Mg!
I'll try to fit that into what I'm doing.
Here's what I have, hope that answers your question.


CODE
Dim tdate as String (today's date)

Dim var1 as String (running variable)

Dim ddate as String (due date)

The tdate is grabbed off main screen before it enters a second one. I looked for a way to grab the date as a constant, but this worked first.
(Sess0.Screen.Select 1, 4, 1, 11, tdate)

the ddate is taken from the first input box
(INPUT "Enter due date in MM-DD-YY format", ddate)

The next bit of code asks for the user to enter a 1 or 2, and if 2 is entered, it has an additional line opposed to entering '1' and must have the ddate +1 on DD of the MM-DD-YY format.

It would've probably been easier to once again write the macro with another INPUT box and then write the variable, but it just seemed since the date was being entered, it should be able to add one to it.




 
Just curious in the instance you described
(INPUT "Enter due date in MM-DD-YY format", ddate)

It's best practice to use the error checking
If IsDate(SomeInput)=-1 then

But it may not be nessesary for example if you were getting the date in a valid format through the system some how
TDate = Date

The above line would set Tdate with the date value from the system

 
Add one to the month. Verify it's in a date format. Make it a date. Pull the day, month, and year form the date. Add one to the month. Combine into month/day/year format. Make it a date.

Add one to the day. Verify it's in a date format. Make it a date. Add 1 to the date.

Code:
Sub Main
SomeDate = "01/01/2006"
SomeVar = 1
If IsDate(SomeDate) then
    SomeDate = DateValue(SomeDate)
Else
    MsgBox "Not a date.  Code something here."
End If

If SomeVar = 1 then
    SomeMonth = Month(SomeDate) + 1
    SomeDay = Day(SomeDate)
    SomeYear = Year(SomeDate)
    SomeDate = DateValue(SomeMonth & "/" & SomeDay & "/" & SomeYear)
Else
    SomeDate = SomeDate + 1
End If
MsgBox SomeDate
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top