Results 1 to 15 of 15

Thread: [2005] Radio Buttons and Check Boxes

  1. #1

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Resolved [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.

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    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?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Radio Buttons and Check Boxes

    try this. it cuts out most of your code

    vb Code:
    1. DirectCast(me.controls("cbx" & Now.DayOfWeek.ToString), CheckBox).enabled = true
    2. DirectCast(me.controls("cbx" & Now.DayOfWeek.ToString), CheckBox).Checked = True

    vb.net Code:
    1. Private Sub rbtnYes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnYes.CheckedChanged
    2.         If rbtnYes.Checked = True Then
    3.             DirectCast(Me.Controls("cbx" & Now.DayOfWeek.ToString), CheckBox).Checked = True
    4.         Else
    5.             DirectCast(Me.Controls("cbx" & Now.DayOfWeek.ToString), CheckBox).Checked = False
    6.         End If
    7. End Sub

  4. #4

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Radio Buttons and Check Boxes

    i re-edited my last post

  6. #6

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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

  7. #7
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    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

  8. #8
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    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.

  9. #9
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    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...

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Radio Buttons and Check Boxes

    what about 2 days time when tomorrows yesterday???

  11. #11

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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

  12. #12
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2005] Radio Buttons and Check Boxes

    Then my code, or .paul.'s works...

  13. #13
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Radio Buttons and Check Boxes

    I'd forget!!!

  14. #14

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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

  15. #15
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    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
  •  



Click Here to Expand Forum to Full Width