VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,400 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




choosing month by combo box

 

choosing month by combo box

sonusan

27 Jun, 2009 - 09:40 PM
Post #1

New D.I.C Head
*

Joined: 19 Jun, 2009
Posts: 11



Thanked: 1 times
My Contributions
Hello...I want to do a progra such that when ever i will choose month from combo box,in the frame those no. of days should enabled.I have used array of command buttons.I have attached my form .Here is my code but its not working at all.

CODE

Dim Index As Integer
Dim a As Integer

Private Sub Combo1_Change()
If Combo1.ListIndex = 0 Or 2 Or 4 Or 6 Or 7 Or 9 Or 11 Then
   For Index = 0 To 30 Step 1
      cmdd(Index).Enabled = True
End If

If Combo1.ListIndex = 3 Or 5 Or 8 Or 10 Then
    For Index = 0 To 29 Step 1
      cmdd(Index).Enabled = True
End If
a = Val(Format(Now, "yyyy"))
If Combo1.ListIndex = 1 Then
   If Combo1.ListIndex = 1 And ((aMod4 = 0 And aMod100 <> 0) Or aMod400 = 0) Then
      For Index = 0 To 28 Step 1
         cmdd(Index).Enabled = True
   End If
Else
    For Index = 0 To 27 Step 1
         cmdd(Index).Enabled = True
End If

End Sub

Private Sub Form_Load()

End Sub

Private Sub Label2_Click()

End Sub


This post has been edited by sonusan: 27 Jun, 2009 - 10:20 PM

User is offlineProfile CardPM
+Quote Post


vb5prgrmr

RE: Choosing Month By Combo Box

28 Jun, 2009 - 08:37 AM
Post #2

D.I.C Regular
***

Joined: 21 Mar, 2009
Posts: 459



Thanked: 30 times
My Contributions
Well your for loops need to end with at least a next statement...
CODE

For 1 To !0
  'do something
Next


Which makes me think you are getting some really weird errors.

So fix that and see how things work.



Good Luck


User is offlineProfile CardPM
+Quote Post

emresutisna

RE: Choosing Month By Combo Box

6 Jul, 2009 - 06:03 AM
Post #3

New D.I.C Head
*

Joined: 14 May, 2009
Posts: 4


My Contributions
QUOTE(sonusan @ 27 Jun, 2009 - 09:40 PM) *

Hello...I want to do a progra such that when ever i will choose month from combo box,in the frame those no. of days should enabled.I have used array of command buttons.I have attached my form .Here is my code but its not working at all.

CODE

Dim Index As Integer
Dim a As Integer

Private Sub Combo1_Change()
If Combo1.ListIndex = 0 Or 2 Or 4 Or 6 Or 7 Or 9 Or 11 Then
   For Index = 0 To 30 Step 1
      cmdd(Index).Enabled = True
End If

If Combo1.ListIndex = 3 Or 5 Or 8 Or 10 Then
    For Index = 0 To 29 Step 1
      cmdd(Index).Enabled = True
End If
a = Val(Format(Now, "yyyy"))
If Combo1.ListIndex = 1 Then
   If Combo1.ListIndex = 1 And ((aMod4 = 0 And aMod100 <> 0) Or aMod400 = 0) Then
      For Index = 0 To 28 Step 1
         cmdd(Index).Enabled = True
   End If
Else
    For Index = 0 To 27 Step 1
         cmdd(Index).Enabled = True
End If

End Sub

Private Sub Form_Load()

End Sub

Private Sub Label2_Click()

End Sub




[quote]
Well, I guess you make 2 mistakes in your codes.
1. Like vb5prgrmr said that your "For" loops need to end with a "Next" statement
2. Your "If statement" for Februari had a wrong statement. It's better if you use a nested if.

Perhaps this could help you:
CODE

Dim Index As Integer
Dim a As Integer

Private Sub Combo1_Click()
If Combo1.ListIndex = 0 Or 2 Or 4 Or 6 Or 7 Or 9 Or 11 Then
   For Index = 0 To 30 Step 1
      cmdd(Index).Enabled = True
   Next
End If

If Combo1.ListIndex = 3 Or 5 Or 8 Or 10 Then
    For Index = 0 To 29 Step 1
      cmdd(Index).Enabled = True
    Next
End If
a = Val(Format(Now, "yyyy"))
If Combo1.ListIndex = 1 Then
   If  ((aMod4 = 0 And aMod100 <> 0) Or aMod400 = 0) Then
      For Index = 0 To 28 Step 1
         cmdd(Index).Enabled = True
      Next
   Else
      For Index = 0 To 27 Step 1
         cmdd(Index).Enabled = True
      Next
   End if
End If

End Sub

Private Sub Form_Load()

End Sub

Private Sub Label2_Click()

End Sub


And I think it's better to use Click event than Change event for the combo box.

I hope it helps you.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:18PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month