View Single Post
 
Old 01-07-2021, 02:16 PM
gmaxey gmaxey is online now Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

They are called parameters and in that code, they are optional. See if this helps:

Code:
Sub SubSimple()
  'You can run this sub directly.
  MsgBox "Hello Stephen"
End Sub
Sub WithParameters(strGreeting As String, strName As String)
  'This sub has required parameters it can only be called by another sub passing arguments.
  MsgBox strGreeting & " " & strName
End Sub
Sub WithOptionalParameters(Optional strGreeting As String = "Hello", Optional strName As String = "Stephen")
  'This sub has optional parameters it can only be called by another sub with or with passing arguments.
  MsgBox strGreeting & " " & strName
End Sub
Function fcnOffsetDate(Optional StartDate, Optional lngOffset As Long = 7) As Date
'Functions return a value to the the calling procedure.
'This functions have optional parameters. The optional parameters define the defaults.
Dim dateTmp As Date
  dateTmp = Date
  If IsDate(StartDate) Then dateTmp = StartDate
  fcnOffsetDate = DateAdd("d", lngOffset, dateTmp)
End Function

Sub CallingSub()
  'Call each of the examples. Step through this procedure using the F8 key.
  SubSimple
  WithParameters "Hello", "Steven Ray" 'the arguments must be passed.
  WithOptionalParameters 'The parameters are optional so no arguments have to be passed.
  MsgBox fcnOffsetDate 'The parameters are optional so no arguments have to be passed.
  MsgBox fcnOffsetDate("12/31/2021", 25) 'We are passing optional arguments.
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote