dcsimg
Results 1 to 11 of 11

Thread: [RESOLVED] Annoying Radiobutton problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Resolved [RESOLVED] Annoying Radiobutton problem

    So i have 3 radio buttons and two text boxes.

    When radio button 1 or 2 is clicked it sets the username and password (defaults)

    When third button is clicked it's suppose to check if textbox1 (user) and textbox2 (pass) are blank or filled.

    If either is blank I want it to set back to radio button 1 and do nothing except pop a msgbox.

    If both are filled I want it to set the username and password and stay checked on radio button 3.

    Code:
        Private Sub MWSUserPass3_CheckedChanged(sender As Object, e As EventArgs) Handles MWSUserPass3.CheckedChanged
            If MWSUser.Text = "" Or MWSPass.Text = "" Then
                'MsgBox(MWSUser.Text & " " & MWSPass.Text) 'debug
                MWSUserPass1.Checked = True
            End If
            If Not MWSUser.Text = "" And Not MWSPass.Text = "" Then
                strMWSUsername = MWSUser.Text
                strMWSPassword = MWSPass.Text
            End If
        End Sub
    However the msgbox comes up twice, so I searched and it has to do with the fact that i checked mwsuserpass1... so if i remove that it only displays one msgbox.. however then it remains on selection 3. I want to revert to radio button 1.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Annoying Radiobutton problem

    You are using the "CheckedChanged"-Event. IMHO this event will fire if this RadioButton is checked or unchecked. In your case you are checking it and in the case of one of the textboxes is empty it will uncheck, in other words the event will fire a second time!

    Try another event!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,889

    Re: Annoying Radiobutton problem

    I'm ok with using the CheckedChanged event, but in this case, you want things to happen sometimes and not other times. Therefore, you could add a Boolean variable at form scope, set that variable in the RB3 selection, and in the RB1 event handler, only take action if the variable is false. If the variable is true in the RB1 event handler, then set it to False.

    In other words, set a flag in the third RB and decide what to do in the first RB based on whether or not the flag is set.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Annoying Radiobutton problem

    I've never done that before might give my newb hand a hand
    Code:
    Private Sub MWSUserPass1_CheckedChanged(sender As Object, e As EventArgs) Handles MWSUserPass1.CheckedChanged
            strMWSUsername = "Userexample"
            strMWSPassword = "Passexample"
        End Sub
    Code:
    Private Sub MWSUserPass3_CheckedChanged(sender As Object, e As EventArgs) Handles MWSUserPass3.CheckedChanged
            If MWSUser.Text = "" Or MWSPass.Text = "" Then
                MsgBox("Please type both username and password")
                MWSUserPass1.Checked = True
            End If
            If Not MWSUser.Text = "" And Not MWSPass.Text = "" Then
                strMWSUsername = MWSUser.Text
                strMWSPassword = MWSPass.Text
            End If
        End Sub

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,793

    Re: Annoying Radiobutton problem

    Right event... missing some logic... at the moment, it doesn't care if the radio button is checked or not... what you want though is for it to care...

    I threw two radio buttons on to a form and added this
    Code:
            If RadioButton1.Checked Then
                MessageBox.Show("Radio Button 1 is checked")
                Me.RadioButton2.Checked = True
            Else
                MessageBox.Show("Radio button 1 is NOT checked")
            End If
    when I select the first radiobutton, I'd get the "Checked" message, followed by the "Not Checked" one... as it changed the selection to the second option. You jsut need to do something similar around yours...

    Code:
    Private Sub MWSUserPass3_CheckedChanged(sender As Object, e As EventArgs) Handles MWSUserPass3.CheckedChanged
    
    if MWSUserPass3.Checked then
    
            If MWSUser.Text = "" Or MWSPass.Text = "" Then
                MsgBox("Please type both username and password")
                MWSUserPass1.Checked = True
            End If
            If Not MWSUser.Text = "" And Not MWSPass.Text = "" Then
                strMWSUsername = MWSUser.Text
                strMWSPassword = MWSPass.Text
            End If
    
    End IF
    
    End Sub
    That's all...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Addicted Member
    Join Date
    Oct 2013
    Posts
    212

    Re: Annoying Radiobutton problem

    What happens if radiobutton1 is checked?
    It will fill the two textboxes, right?

    When radiobutton3 is checked, what will happen?
    1. A messagebox will pop.
    2. radiobutton1 will be checked, and then the two textboxes will be filled, and this is logic, right?

    So you can't ask radiobutton3 to check radiobutton1 and stop.
    Because checking radiobutton1 means filling the two textboxes.

    If your only concern is to display once the messagebox, not more,
    this not a problem.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,793

    Re: Annoying Radiobutton problem

    Quote Originally Posted by Atenk View Post
    What happens if radiobutton1 is checked?
    It will fill the two textboxes, right?

    When radiobutton3 is checked, what will happen?
    1. A messagebox will pop.
    2. radiobutton1 will be checked, and then the two textboxes will be filled, and this is logic, right?

    So you can't ask radiobutton3 to check radiobutton1 and stop.
    Because checking radiobutton1 means filling the two textboxes.

    If your only concern is to display once the messagebox, not more,
    this not a problem.
    Actually... yes you can...

    Here's what is needed:
    RB1 CheckChanged event:
    Check the Checked value of the RB (RB1), if it is checked, then fill in the text boxes

    RB2 CheckChanged event:
    Check the Checked value of the RB (RB2), if it is checked, then fill in the text boxes

    RB3 CheckChanged event:
    Check the Checked value of the RB (RB3), if it is checked, check the textboxe, if either is blank, display them essage box, then set the RB1.Checked value to true.... this will 1) uncheck RB3 and refire that checkchanged event (which is why you check the Checked property - it will be false when it fires off the second time) and 2) cause RB1.Checked to be true and fire the RB1_CheckedChange event to fire... allowing it to go back through that logic...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Addicted Member
    Join Date
    Oct 2013
    Posts
    212

    Re: Annoying Radiobutton problem

    Code:
     If Not MWSUser.Text = "" And Not MWSPass.Text = "" Then
                strMWSUsername = MWSUser.Text
                strMWSPassword = MWSPass.Text
            End If
    tg: The OP doesn't want to fill the textboxes, but just check radiobutton1: "If either is blank I want it to set back to radio button 1
    and do nothing except pop a msgbox.

    Edit: I tried your code; and I stand corrected.
    Last edited by Atenk; Jun 11th, 2014 at 04:07 PM.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,793

    Re: Annoying Radiobutton problem

    Hmm.... I guess it's in the interpretation... OK.. either way... use a flag then... if it's set, when RB1 gets set, then do nothing... if it's not set, then do something... to be fair, the whole thing sounds a bit off... and yet wouldn't have been the craziest set of requirements I've seen.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Annoying Radiobutton problem

    I simply changed the event from checkchanged to click

    Code:
        Private Sub TWSUserPass3_CheckedChanged(sender As Object, e As EventArgs) Handles TWSUserPass3.Click
            If TWSUser.Text = "" Or TWSUser.Text = "" Then
                TWSUserPass1.Checked = True
                MsgBox("Must enter both username and password before selecting")
            End If
            If Not TWSUser.Text = "" And Not TWSUser.Text = "" Then
                strTWSUsername = TWSUser.Text
                strTWSPassword = TWSUser.Text
            End If
        End Sub
    Problem resolved.

  11. #11
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Annoying Radiobutton problem

    If you use the "Thread Tools" (just above your initial post) you could mark the thread resolved in its title!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width