VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A simple way to demonstrate how to use functions and simple math in VBA.

by cneovyper (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 17th October 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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.



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

Download this snippet    Add to My Saved Code

A simple way to demonstrate how to use functions and simple math in VBA. Comments

No comments have been posted about A simple way to demonstrate how to use functions and simple math in VBA.. Why not be the first to post a comment about A simple way to demonstrate how to use functions and simple math in VBA..

Post your comment

Subject:
Message:
0/1000 characters