Passing arguments to procedures

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



There is something fundamental that I have failed to grasp about passing
arguments to procedures.

I have a form featuring a set of unbound controls displaying dates and the
corresponding days of the week. (For some reason, the long-date format, on
my computer, does not include the latter, as the documentation suggests it
might, so it has to be separately calculated and displayed.)

A default date is displayed in each control, on Form_Open. This can then be
manually adjusted by a pair of ‘up’ and ‘down’ buttons associated with each
day/date control pair. In the case of the control ‘Start_Date’, for example,
the first two procedures are specific to the control, whilst the third Sub
and the following Function are common to the form.

Private Sub ComDateStartNext_Click() ‘Increment date by one day
IncDecDateDay Me.StartDate, Me.StartDay, 1
End Sub

Private Sub ComDateStartPrevious_Click() ‘Decrement date by one day
IncDecDateDay Me.StartDate, Me.StartDay, -1
End Sub

Private Sub IncDecDateDay(InDate, InDay, ByVal Increment As Integer)
InDate = InDate + Increment
InDay = Get_WeekDay(InDate)
End Sub

Private Function Get_WeekDay(InDate) As String
Select Case Weekday(InDate)
Case 1
Get_WeekDay = "SUN"
Case 2
Get_WeekDay = "MON"
Case 3
Get_WeekDay = "TUE"
Case 4
Etc.
End Select
End Function

Nothing happens when the ‘up’ and ‘down’ buttons are clicked but if I
replace the implicit general-purpose Sub IncDecDateDay with the explicit test
version:–

Private Sub IncDecDateDay(InDate, InDay, ByVal Increment As Integer)
Me.StartDate = InDate + Increment
Me.StartDay = Get_WeekDay(InDate)
End Sub

....it all works fine (in the case of the ‘Start_Date’ control, of course)
but my belief that changes to the parameter InDate would be reflected in the
displayed value of the original calling control are clearly wrong. It is not
that I cannot find an alternative solution – I can recast the thing using a
function to return the required values – but what worries me is that I have
obviously been labouring under a misapprehension. Perhaps I spent too long
messing about with ‘C’. Would someone be kind enough to enlighten me?

---Peter Hallett

.



Relevant Pages

  • Re: Passing arguments to procedures
    ... Private Sub IncDecDateDay(InDate, InDay, ByVal Increment As Integer) ... InDate = InDate + Increment ... Private Sub IncDecDateDay(InDate As Control, InDay As Control, ByVal ...
    (microsoft.public.access.formscoding)
  • Re: Switching from dialog based app to SDI
    ... all communication comes from the document. ... write/read register values of that device ... I'm supposed to write similar programs now to control other devices. ... displaying the received values as bin,hex,dec strings or converting the ...
    (microsoft.public.vc.mfc)
  • Re: HelpProvider
    ... > provide info regatding that control i.e what the control is meant for. ... > HelpString on helpProvider1= Drugs Entry Form ... > Again when am selecting form and pressing f1 then it is displaying the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: RichText Formatting Urls
    ... This worked which means RTF does support named links. ... as an RTF file to have a look at the rich text tags. ... However there is a RTF property against the control which gets the current ... So I'm now thinking about displaying my text with HTML in .NET 2s web ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Force Macro to Wait Until New Message Displayed and Printed
    ... In VB I´d probably use the DHTMLEdit control, ... > requirement that incoming messages be displayed prior to printing. ... > seconds after displaying, and 15 seconds after printing; ... > Private Sub olInboxItems_ItemAdd ...
    (microsoft.public.outlook.program_vba)