Flylib.com

Books Software

 
 
 

Month Function

   
Month Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

Month(


datevalue


)
datevalue (required; date)

Date variable or literal date

Return Value

An Integer between 1 and 12

Description

Returns an integer representing the month of the year of a given date expression

Rules at a Glance

If datevalue contains Nothing , Month returns Nothing .

Programming Tips and Gotchas

  • The validity of the date expression, as well as the position of the month element within the date expression, is initially determined by the locale settings of the current Windows system. However, some intelligence has been built into the Month function that surpasses the usual comparison of a date expression to the current locale settings. For example, on a Windows machine set to US date format ( mm/dd/yyyy ), the date "13/12/1998" would technically be illegal. However, the Month function returns 12 when passed this date. The basic rule for the Month function is that if the system-defined month element is outside legal bounds (i.e., greater than 12), the system-defined day element is assumed to be the month and is returned by the function.

  • Since the IsDate function adheres to the same rules and assumptions as Month , it can be used to determine whether a date is valid before passing it to the Month function.

  • Visual Basic also has a new MonthName function for returning the name of the month.

  • You can also use the DatePart function.

See Also

Day Function, Year Function

   
   
MonthName Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

MonthName(


month


[,


abbreviate


])
month (required; Integer)

The ordinal number of the month, from 1 to 12

abbreviate (optional; Boolean)

A flag to indicate if an abbreviated month name should be returned

Return Value

String containing the name of the specified month

Description

Returns the month name of a given month. For example, a month of 1 returns January or (if abbreviate is True ) Jan.

Rules at a Glance

The default value for abbreviate is False .

Example

Public Function GetMonthName(dat As Date) As String



Dim iMonth As Integer = Month(dat)

GetMonthName = MonthName(iMonth)



End Function

Programming Tips and Gotchas

  • month must be an integer; it cannot be a date. Use DatePart("m", dateval ) to obtain a month number from a date.

  • If month has a fractional portion, it is rounded before calling the MonthName function.

  • MonthName with abbreviate set to False is the equivalent of Format(dateval, "mmmm") .

  • MonthName with abbreviate set to True is the equivalent of Format(dateval, "mmm") .

See Also

WeekdayName Function

   
   
MsgBox Function

Class

Microsoft.VisualBasic.Interaction

Syntax

MsgBox(


prompt


[,


buttons


][,


title


])
prompt (required; String)

The text of the message to display in the message box dialog box

buttons (optional; MsgBoxStyle enumeration)

The sum of the Button , Icon , Default Button , and Modality constant values

title (optional; String)

The title displayed in the title bar of the message box dialog box

Return Value

A MsgBoxResult enumeration constant indicating the button clicked by the user to close the message box

Description

Displays a dialog box containing a message, buttons, and optional icon to the user. The action taken by the user is returned by the function in the form of an enumerated constant.

Rules at a Glance

  • prompt can contain approximately 1,000 characters , including carriage return characters such as the built-in vbCrLf constant.

  • If the title parameter is omitted, the name of the current application or project is displayed in the title bar.

  • If you omit the buttons argument, the default value is 0; that is, VB opens an application modal dialog box containing only an OK button.

  • The constants of the MsgBoxStyle enumeration can be added together to form a complete buttons argument. The constants can be divided into the following groups:

    Button Display Constants
    Icon Display Constants
    Default Button Constants
    Modality Constants

    Only one constant from each group can be used to make up the overall buttons value.

Button Display Constants

Constant

Value

Buttons to display

MsgBoxStyle.OKOnly

OK only

MsgBoxStyle.OKCancel

1

OK and Cancel

MsgBoxStyle.AbortRetryIgnore

2

Abort, Retry, and Ignore

MsgBoxStyle.YesNoCancel

3

Yes, No, and Cancel

MsgBoxStyle.YesNo

4

Yes and No

MsgBoxStyle.RetryCancel

5

Retry and Cancel

Icon Display Constants

Constant

Value

Icon to display

MsgBoxStyle.Critical

16

Critical Message

MsgBoxStyle.Question

32

Warning Query

MsgBoxStyle.Exclamation

48

Warning Message

MsgBoxStyle.Information

64

Information Message

Default Button Constants

Constant

Value

Default button

MsgBoxStyle.DefaultButton1

First button

MsgBoxStyle.DefaultButton2

256

Second button

MsgBoxStyle.DefaultButton3

512

Third button

MsgBoxStyle.DefaultButton4

768

Fourth button

Modality Constants

Constant

Value

Modality

MsgBoxStyle.ApplicationModal

Application

MsgBoxStyle.SystemModal

4096

System

Return Values

The following intrinsic constants can be used to determine the action taken by the user and represent the value returned by the MsgBox function:

Constant

Value

Button clicked

MsgBoxResult.OK

1

OK

MsgBoxResult.Cancel

2

Cancel (or Esc key pressed)

MsgBoxResult.Abort

3

Abort

MsgBoxResult.Retry

4

Retry

MsgBoxResult.Ignore

5

Ignore

MsgBoxResult.Yes

6

Yes

MsgBoxResult.No

7

No

If the MsgBox contains a Cancel button, the user can press the Esc key and the function's return value will be that of the Cancel button.

Programming Tips and Gotchas

  • Application modality means that the user cannot access other parts of the application until a response to the message box has been given. In other words, the appearance of the message box prevents the application from performing other tasks or from interacting with the user other than through the message box.

  • System modality used to mean that all applications were suspended until the message box was closed. However, with multitasking operating systems, such as Windows 95 and Windows NT, this is not the case. Basically, the message box is defined to be a "Topmost" window that is set to "Stay on Top," which means that the user can switch to another application and use it without responding to the message box. But because the message box is the topmost window, it will be positioned on top of all other running applications.

  • Unlike its InputBox counterpart , MsgBox cannot be positioned on the screen. It is always displayed in the center of the screen.

  • If your application is to run out-of-process on a remote machine, you should remove all MsgBox functions since they will not be displayed to the user, but instead will appear on the monitor of the remote server!

  • MsgBox should never be used in ASP.NET applications.

VB.NET/VB 6 Differences

In VB 6, the MsgBox function has five parameters. The last two, helpfile (which specified the path to a help file containing information about the error message) and context (which specified the help context ID within helpfile ), are optional. In VB.NET, these two parameters are not supported.

See Also

InputBox Function