Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 01-07-2021, 02:16 PM
gmaxey gmaxey is offline Need a Function with Select Case for the Holidays Windows 10 Need a Function with Select Case for the Holidays Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a Function with Select Case for the Holidays Can Select Case be used to defined the Value of an item in a drop down list? mbews Word VBA 10 10-08-2020 05:04 AM
Need a Function with Select Case for the Holidays Toggle between upper case, lower case, etc... by one single macro on a Mac, to emulate Shift + F3 on gloub Word VBA 2 01-30-2019 12:40 PM
Need a Function with Select Case for the Holidays SENDKEYS with vbYesNoCancel and Select Case kiwimtnbkr Word VBA 31 06-11-2018 04:56 AM
Need a Function with Select Case for the Holidays Use function to select another worksheet eugeneradial Excel 2 04-27-2017 04:53 AM
Help with Case and Select case brent chadwick Word VBA 34 10-18-2015 02:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft