- Home
·
- Math/Dates
·
- A simple way to demonstrate how to use functions and simple math in VBA.
A simple way to demonstrate how to use functions and simple math in VBA.
A simple way to demonstrate how to use functions and simple math in VBA.
Rate A simple way to demonstrate how to use functions and simple math in VBA.
(2(2 Vote))
Option Explicit
Dim daysold, bday As Date, dysuntl, wks As Integer
Dim cur, yr As String
Private Sub bdays()
Dim today As Date
Dim tit, rtrn As String
tit = "Birth Day Sub"
rtrn = Chr(13) & Chr(10)
yr = InputBox("Plese enter the year of next b-day." & rtrn & "In xxxx format.", "year")
If yr = "" Then
MsgBox "GoodBye", vbCritical, "GoodBye"
Exit Sub
Else
bday = InputBox("Please enter your birthday." & rtrn & "In xx/xx/xxxx format.", tit)
today = Date
Call yrsold
Call untl
wks = (dysuntl / 7)
MsgBox "You are " & daysold & " yrs. old!"
daysold = daysold + 1
MsgBox dysuntl & " DAYS" & rtrn & "OR" & rtrn & wks & " Weeks left.", , "Days Until You Are! " & daysold
End If
End Sub
Private Function yrsold()
daysold = Date - CDate(bday): daysold = (daysold / 365)
daysold = Mid(daysold, 1, 2)
End Function
Private Function untl()
bday = CStr(bday)
cur = Mid(CStr(bday), 1, 2) & "/" & Mid(bday, 4, 2) & "/" & yr
dysuntl = CDate(cur) - Date
End Function
A simple way to demonstrate how to use functions and simple math in VBA. Comments
No comments yet — be the first to post one!
Post a Comment