Results 1 to 15 of 15

Thread: [2005] Radio Buttons and Check Boxes

Threaded View

  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.

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