|
-
Dec 4th, 2007, 07:49 PM
#1
Thread Starter
Frenzied Member
[2005] Radio Buttons and Check Boxes
I will try to make this short. Again I have the form for Exercise Logs.
Attachment 60950
When the form loads the check box for the day of the week is enabled and checked. I do that like this;
Code:
' check the day of the week so that is the only check box available to the user
' declare a variable to get the day of the week
Dim DayOfWeek = Now.ToLongDateString
' declare a variable to get today
' break apart the string and get only the day
Dim todaysDate As String = DayOfWeek
Dim ThisDay As String = String.Empty
ThisDay = todaysDate.Substring(0, todaysDate.IndexOf(" "c)).Replace(",", String.Empty).Trim
Dim thisDayNow As String = ThisDay
' call the function WhatDay passing in the day of the week to
' set the check box of the weekday to enabled
WhatDay(thisDayNow)
This is the function that sets the day of the week;
Code:
Private Function WhatDay(ByVal TheDay As String) As String
If TheDay = "Sunday" Then
Me.cbxSunday.Enabled = True
ElseIf TheDay = "Monday" Then
Me.cbxMonday.Enabled = True
ElseIf TheDay = "Tuesday" Then
Me.cbxTuesday.Enabled = True
ElseIf TheDay = "Wednesday" Then
Me.cbxWednesday.Enabled = True
ElseIf TheDay = "Thursday" Then
Me.cbxThursday.Enabled = True
ElseIf TheDay = "Friday" Then
Me.cbxFriday.Enabled = True
ElseIf TheDay = "Saturday" Then
Me.cbxSaturday.Enabled = True
End If
Return TheDay
End Function
Then to enable the appropriate day I do this;
Code:
Sub checkCheckBox()
Dim ctrl As Control = Me.GetNextControl(Me, True)
While ctrl IsNot Nothing
If TypeOf ctrl Is CheckBox And ctrl.Enabled = True Then
DirectCast(ctrl, CheckBox).Checked = True
End If
ctrl = Me.GetNextControl(ctrl, True)
End While
End Sub
I check the radio button Yes or No after asking if the user has exercised today.
What I would like to do is if Yes is checked, then the day of the week is checked, if No is checked then nothing happens.
Is this not valid?
Code:
Sub checkCheckBox()
Dim ctrl As Control = Me.GetNextControl(Me, True)
While ctrl IsNot Nothing
If TypeOf ctrl Is CheckBox And ctrl.Enabled = True And Me.rbtnYes.Checked = True Then
DirectCast(ctrl, CheckBox).Checked = True
Else
DirectCast(ctrl, CheckBox).Checked = False
End If
ctrl = Me.GetNextControl(ctrl, True)
End While
End Sub
If not is there a way to correct it?
Thanks
CoachBarker
Last edited by CoachBarker; Apr 15th, 2009 at 09:29 AM.
-
Dec 4th, 2007, 08:08 PM
#2
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
Basically when the user clicks the radio button 'no' hide all your checkboxes that say the days, and when they click 'yes' show them all, and when they click a checkbox, then simply use WhatDay("Day") to determine what day it is.. or whatever your doing..
Is that what you mean?
-
Dec 4th, 2007, 08:19 PM
#3
Re: [2005] Radio Buttons and Check Boxes
try this. it cuts out most of your code
vb Code:
DirectCast(me.controls("cbx" & Now.DayOfWeek.ToString), CheckBox).enabled = true
DirectCast(me.controls("cbx" & Now.DayOfWeek.ToString), CheckBox).Checked = True
vb.net Code:
Private Sub rbtnYes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnYes.CheckedChanged
If rbtnYes.Checked = True Then
DirectCast(Me.Controls("cbx" & Now.DayOfWeek.ToString), CheckBox).Checked = True
Else
DirectCast(Me.Controls("cbx" & Now.DayOfWeek.ToString), CheckBox).Checked = False
End If
End Sub
-
Dec 4th, 2007, 08:20 PM
#4
Thread Starter
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
The check boxes for the days are visual aid so the user knows what days they have exercised. I also have to count the number of days exercised and if in a week it is less than four, display a message stating it is less than the required amount and some other information. All of that works fine.
I thought that there might be a way to have the checkbox checked if the Yes radio button was checked. One less step for the user.
Thanks
CoachBarker
-
Dec 4th, 2007, 08:24 PM
#5
Re: [2005] Radio Buttons and Check Boxes
-
Dec 4th, 2007, 08:28 PM
#6
Thread Starter
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
Thanks I will give it a try. Seems like every time I get the hang of doing something and work through it the long way, someone comes along and shows a shorter more precise way of doing it.
CoachBarker
-
Dec 4th, 2007, 08:30 PM
#7
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
Oh yes, I understand what you mean now!
Code:
Public CheckBoxDayList() As CheckBox = {SundayCheckBox, MondayCheckBox, TuesdayCheckBox, WednesdayCheckBox, ThursdayCheckBox, SaturdayCheckBox}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
For Each ExerciseCheckBox As CheckBox In CheckBoxDayList
ExerciseCheckBox.Checked = False
ExerciseCheckBox.Enabled = False
Next ExerciseCheckBox
End Sub
Private Sub ExerciseRadioBYes_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExerciseRadioBYes.Click
Dim CurrentDay As String = Now.DayOfWeek 'This returns an integer I think
CheckBoxDayList(CurrentDay).Checked = True
CheckBoxDayList(CurrentDay).Enabled = True
End Sub
Private Sub ExerciseRadioBNo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExerciseRadioBNo.Click
For Each ExerciseCheckBox As CheckBox In CheckBoxDayList
ExerciseCheckBox.Checked = False
ExerciseCheckBox.Enabled = False
Next ExerciseCheckBox
End Sub
-
Dec 4th, 2007, 08:32 PM
#8
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
What if they log in tomorrow to fill out info for today? They won't be able to check today's box (tomorrow) if today's box is disabled tomorrow.
Wow! I think I just confused myself.
-
Dec 4th, 2007, 08:34 PM
#9
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
That's true FourBlades, but then it's their fault for missing that day, and they will have to suffer the loss lol...
-
Dec 4th, 2007, 08:34 PM
#10
Re: [2005] Radio Buttons and Check Boxes
what about 2 days time when tomorrows yesterday???
-
Dec 4th, 2007, 08:35 PM
#11
Thread Starter
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
The requirements are that they log in every day, they can check their Glucose Levels multiple times in a day, but only fill in the exercise log once, they can do it anytime in that day if they choose.
COachBarker
-
Dec 4th, 2007, 08:36 PM
#12
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
Then my code, or .paul.'s works...
-
Dec 4th, 2007, 08:37 PM
#13
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
-
Dec 4th, 2007, 08:38 PM
#14
Thread Starter
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
Yep I added Pauls, keep trying to get back in and marked this one resolved, but I keep getting replies. Thanks for all the help.
CoachBarker
-
Dec 4th, 2007, 08:40 PM
#15
Frenzied Member
Re: [2005] Radio Buttons and Check Boxes
You can mark it resolved anytime and we can still reply.
So...what are you waiting for???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|