?
Solved

I have 3 combo listboxes to input date a transaction took place.  How do I write an array for years with array of 97 items

Posted on 2003-03-30
9
Medium Priority
?
151 Views
Last Modified: 2012-05-04
I am working on a an ATM program, but I am really struggling.  Any help would be appreciated.

Problem:
Need to know how to fill the date information in 3 combo listbox that are designed for Month, Day, and Years.  The years will run from 2002 to 2099.  Also, if I use the list property to show the days in the months, how do I show that February cannot use the 30th and 31st day repectively, and also it can use the 29th day only if the year is a leapyear?

Thank you all kindly
0
Comment
Question by:zee07836
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 620 total points
ID: 8234735
'Hi zee07836,

'Put 3 combo's on your form and paste the following code...

Private Sub Combo2_Click()
    Combo3.Clear
For i = 1 To 31
    If IsDate(i & "/" & Combo2.ListIndex + 1 & "/" & Combo1) Then Combo3.AddItem i
Next
    End Sub
Private Sub Combo1_Click()
    Combo3.Clear
For i = 1 To 31
    If IsDate(i & "/" & Combo2.ListIndex + 1 & "/" & Combo1) Then Combo3.AddItem i
Next
End Sub

Private Sub Form_Load()
For y = 2000 To 2099
    Combo1.AddItem y
    Next y
Combo1.ListIndex = 0
For m = 1 To 12
    Combo2.AddItem MonthName(m)
Next m
    Combo2.ListIndex = 0
End Sub
0
 
LVL 2

Expert Comment

by:Jzaltheral
ID: 8234842
Will the user be selecting the year first or the month?  Or do you want it to matter?  That determines how best to code to form to do exactly what you need.

I can at least get you started with loading the date information -

For the months combo box, set the names in the list property - Just click the drop down arrow on the list property and type them in, hitting CTRL-ENTER after each one to move to a new line.  Since these don't change, there's no need to load them at run time - we can do it at design time.

To load the years you can put the following code in your form's Load event

'Load the values into the years combo box.
Dim Year As Long
Year = 2002

For Year = Year To 2099
    cmbYears.AddItem CStr(Year)
Next Year
   
End Sub

Once I get the answers to the questions I asked earlier, I should be able to help you out with the rest.

Jzal
0
 
LVL 2

Expert Comment

by:Jzaltheral
ID: 8234848
Oops.  Sorry aleatik - I was busy writing my own answer, and missed you posting yours.

Jzal
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:avya2k
ID: 8236570
Why don't you use Date picker control instead
To insert DatePicker control
open Project\Components
and select "Microsoft windows common controls-2.6.0(MSCOMCT2.ocx)

and insert DTPicker control
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8237425
I would agree with avya2k that you should use the Date picker control. However, if for some reason, you're reluctant to use that one, then you can have the 3 combo-boxes (say, 'dt', 'mn' and 'yr', with 'dt' holding 1 through 31 in string-form, 'mn' holding "January", "February", ...., "December", and 'yr' holding 2002 through 2009 in string-form), then you ca apply the following validation:

Dim tempDate As String
Dim myDate As Date

tempDate = mn & " " & dt & ", " & yr

If Not IsDate(tempDate) Then
  MsgBox "Invalid date. Please re-enter. "
Else
  myDate = CDate (tempDate) ' convert the string to date-type
  .. ' do your thing
End If


Hope that helps!

Mayank.
0
 
LVL 1

Expert Comment

by:hazgod
ID: 8242022
dim index as integer
dim leapYear as boolean

select case comboMonth.text

'months with 30 days
  case "September":
  case "April":
  case "June":
  case "November":
    comboDay.clear
    for index = 1 to 30
      comboDay.additem index
    next

  case "February":
    'need code in here to detect leap year
    'if year is a leap year, leapYear = true
    'else leapYear = false
    comboDay.clear
    if leapYear = true then
      for index = 1 to 29
        comboDay.additem index
      next
    else
      for index = 1 to 28
        comboDay.additem index
      next
    end if

  case else:
    comboDay.clear
    for index = 1 to 31
      comboDay.additem index
    next

end select
0
 

Author Comment

by:zee07836
ID: 8267050
Thank you to all of you who so graciously answered my question.

Much Thanks
Zee
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8267219
So accept one of the answers and rate it :-)
0
 

Author Comment

by:zee07836
ID: 8275278
Aelatik et All, I built projects with the respective codes that each of you posted; although they all were intellectually stimulating :), I found the one from Alelatik was the easiest to apply.

Aelatik, as shown below, I slightly modified the code you sent me (changed the control names)  and placed the codes on the form and in 3 combo boxes as shown and it worked perfectly.  

Private Sub Form_Load()

Dim y As Integer
Dim m As Integer


For y = 2000 To 2099
   CboYear.AddItem y  
   Next y
   CboYear.ListIndex = 0


For m = 1 To 12
   CboMonth.AddItem MonthName(m)
Next m
  CboMonth.ListIndex = 0

End Sub
'__________________________________________________________
Private Sub CboMonth_Click()
   CboDay.Clear
Dim i As Integer
For i = 1 To 31
   If IsDate(i & "/" & CboMonth.ListIndex + 1 & "/" & CboYear) Then CboDay.AddItem i
Next
   End Sub
'__________________________________________________________

Private Sub CboYear_Click()
Dim i As Integer
   CboDay.Clear
For i = 1 To 31
   If IsDate(i & "/" & CboMonth.ListIndex + 1 & "/" & CboYear) Then CboDay.AddItem i
Next
End Sub
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question