Access Programming Pocket Primer (The Pocket Primer Series) by Julitta Korol

Access Programming Pocket Primer (The Pocket Primer Series) by Julitta Korol

Author:Julitta Korol [Korol, Julitta]
Language: eng
Format: epub
ISBN: 9781942270027
Publisher: Mercury Learning and Information
Published: 2015-05-10T21:00:00+00:00


Hands-On 5.4. Using the If…Then…Else Statement

1. Insert a new module and enter the following WhatTypeOf Day procedure in the module’s Code window:

Sub WhatTypeOfDay() Dim response As String Dim question As String Dim strMsg1 As String, strMsg2 As String Dim myDate As Date question = "Enter any date in the format mm/dd/yyyy:" _ & Chr(13) & " (e.g., 07/06/2011)" strMsg1 = "weekday" strMsg2 = "weekend" response = InputBox(question) myDate = Weekday(CDate(response)) If myDate >= 2 And myDate <= 6 Then MsgBox strMsg1 Else MsgBox strMsg2 End If End Sub

2. Run the WhatTypeOfDay procedure.

This procedure asks the user to enter any date. The user-supplied string is then converted to the Date data type with the built-in CDate function. Finally, the Weekday function converts the date into an integer that indicates the day of the week (see Table 5.3). The integer is stored in the variable myDate. The conditional test is performed to check whether the value of the variable myDate is greater than or equal to 2 (>=2) and less than or equal to 6 (<=6). If the result of the test is true, the user is told that the supplied date is a weekday; otherwise, the program announces that it’s a weekend.

3. Run the procedure a few more times, each time supplying a different date. Check the Visual Basic answers against your desktop or wall calendar.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.