Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
ACCEPT ONLY VALID YEAR FROM USER THROUGH A LISTBOX...
Author:
SHOWNAK SIRCAR
E-mail:
Click to e-mail author
Submitted:
9/5/2001
Version:
VB5
Compatibility:
VB5, VB6
Category:
Date/Time
Views:
14995
ACCEPT ONLY VALID YEAR FROM USER THROUGH A LISTBOX/COMBOBOX. COMMENTS: In order to use this subroutine you have to have a combo box or a list box in a form (as you know there is hardly any difference between the two as far as coding is concerned) and you have to call the subroutine from inside the "GotFocus" event for the same. You can store the subroutine definition in the "General" area of the form or in a "Module" of your project depending upon requirement. PARAMETER INFO: >>ListYr may be a listbox or a combobox. >>StYr should represent the earliest year to be considered for display. For Examlpe suppose you started your business on 15th August 1990. Obviously, you have nothing to do with years earlier than 1990 , so that no one can select an invalid year, as far is your business is concerned. As far as latest years are concerned, the program will automatically take care that the latest year is valid under any circumstances. >>MinAge is an optional Integer variable which should repersent the minimum age to be considered for a particular purpose e.g. while accepting application forms for admission to a course. >>FillMode is an optional String variable whose permissible values are : >> (none) : When you are not using the combo/listbox for any of the purposes listed below. >> "SPECIAL" : When you want the latest year to be 1 more than the current year. >> "AGE" : When you are using the combo/list box for accepting Date of Birth. >> "FINANCIAL" : When you are using the combo/list box for accepting dates regerding a Financial Year e.g. when you want your program to show Annual Report(s) of the financial year 1990-1991. >>PLEASE NOTE that there are separate subroutines for accepting Months and Days pertaining to a particular Year. You should be concerned only about the Year part of the date at this moment.
Declarations:
Dim StartYr, EndYr As Integer
Code:
Public Sub FillYearInList(ByRef ListYr As ComboBox, ByVal StYr As Integer, _ Optional ByVal MinAge As Integer, ByVal FillMode As String) Dim StartYr, EndYr As Integer Select Case UCase(FillMode) Case "SPECIAL" StartYr = StYr EndYr = Year(Date) + 1 Case "AGE" StartYr = Year(Date) - MinAge EndYr = 1900 Case "FINANCIAL" StartYr = StYr If Month(Date) > 3 Then EndYr = Year(Date) - 1 Else EndYr = Year(Date) - 2 End If Case Else StartYr = StYr EndYr = Year(Date) End Select ListYr.Clear If UCase(FillMode) = "FINANCIAL" Then For ctr = StartYr To EndYr With ListYr .AddItem " " + (CStr(ctr)) + Chr(45) + (CStr(ctr + 1)) End With Next ctr Else If UCase(FillMode) = "AGE" Then For ctr = StartYr To EndYr Step -1 With ListYr .AddItem " " + (CStr(ctr)) End With Next ctr Else For ctr = StartYr To EndYr With ListYr .AddItem " " + (CStr(ctr)) End With Next ctr End If End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement