Jump to content

getting what radiobutton is checked in vb

NanoVengeance

Hi just new to this website

 

i'm currently a student and I'm doing an assignment and i'm trying to figure out how I can get what radiobutton has been checked

 

i'm trying to make this in a module so I can use it over again without having to write raw code all the time

 

the assignment is for young children to create a programme that has 9 questions and they all have radio buttons, some forms have more than 2 radio buttons

but when they check the correct radio button and continue I want there score to go up by one

 

i'm just having trouble making a function that checks which radiobutton is checked and to check if it's the correct answer and then to increment the score by 1

 

if someone could help me on this it would be great thanks :-)

Link to comment
Share on other sites

Link to post
Share on other sites

thanks :)

 

ummm how would I do that?

 

where all still learning and im trying to stay a head of everyone haha

 

just trying to figure out how I can write a public function of public sub to check which radio button has been checked on the form and then make it be able to tell which is the correct answer and update the score

 

but first of all I need to figure out how I can get which radio button has been checked

Link to comment
Share on other sites

Link to post
Share on other sites

nope that doesn't work

 

at the minute I've got

 

Public Function RadioButtonChecked(RdbMathQ1True, RdbMathQ1False)

 

End Function

 

think this is true because I need it to return a value to show what radio button has been checked

 

Link to comment
Share on other sites

Link to post
Share on other sites

if you're using visual studio then you can double click the radio button then you should see the code, after that at the top right corner (I believe, haven't used vb for like 5 years or so) there should be a drop down and from there choose radiobuttonchecked. You should then be redirected to the code which gets executed when the radio button is checked.

 

I haven't used for vb since 2009 easily probably even longer so visual studio might of changed by then.

Link to comment
Share on other sites

Link to post
Share on other sites

@NanoVengeance

 

Why not set up a click procedure?

Public Sub <Radio button name>_click()End Sub

You can also check if the button has been pressed by checking if

<name>.value = true

If it's true, that means the user has pressed that button.

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to comment
Share on other sites

Link to post
Share on other sites

sorry for the late reply 

been busy with assignments and have gotten pretty far now and have it mostly working just need to test it and check all the different options to see if there is any bugs 

 

i've made everything into a module and then just calling it when they press the finish button

was struggling for ages and then when i actually got it to work i looked at it n thought that is so easy how did i not even figure this out ages ago lol

 

just thought i would show my code and let people have a look, and in case there is something that is wrong or could be changed 

Module Module1    Public TotalScore As Integer = 0    Public TotalAttempts As Integer = 0    Public Response As Integer    Public Sub OpenForm(QForm As Form)        'PURPOSE: Opens a VB form        'INPUT: VB form passed as an argument        'PROCESS: Does not process any data        'OUTPUT: Does not return any output        QForm.Show() 'Opens Form    End Sub    Public Sub RadioButtonCheck(RadioButtonTrue As Integer, RadioButtonFalse As Integer)        If PopUpBox(MessageBoxButtons.OKCancel) Then            FrmMain.LblAttempts.Text = TotalAttempts  'displays the attempts in Label attempts on FrmMain        End If        If RadioButtonTrue = True Then            FrmMain.LblScore.Text = TotalScore        End If        If RadioButtonFalse = True Then            'Do Nothing        End If    End Sub    Public Sub RadioButtonSelect(RadioButtonTrue1 As Integer, RadioButtonTrue2 As Integer, RadioButtonFalse1 As Integer, RadioButtonFalse2 As Integer)        If RadioButtonTrue1 = True And            RadioButtonTrue2 = True Then            SetScore()            FrmMain.LblScore.Text = TotalScore        End If        If RadioButtonFalse1 = True And            RadioButtonFalse2 = True Then            'Do Nothing        End If        If PopUpBox(MessageBoxButtons.OKCancel) Then            SetAttempts()                             'if button ok then do following code            FrmMain.LblAttempts.Text = TotalAttempts  'displays the attempts in Label attempts on FrmMain        End If    End Sub    Public Function PopUpBox(MessageBoxButtons As MessageBoxButtons)        Response = MessageBox.Show("Are you sure you want to continue?",                     "WARNING",                     MessageBoxButtons.OKCancel,                     MessageBoxIcon.Warning)        If Response = 2 Then        End If        If Response = 1 Then            SetScore()            SetAttempts()        End If        'MsgBox(Response) used to test to return what vbOK and vbCancel value is        Return Response    End Function    Public Sub ToolStripVisible(TStrip As ToolStripMenuItem)        TStrip.Visible = False    End Sub    Public Sub SetScore()        TotalScore += 1   'Updates score on FrmMain in the label    End Sub    Public Sub SetAttempts()        TotalAttempts += 1  'Updates TotalAttempts on FrmMain in the label     End Sub    Public Sub CloseForm(CForm As Form)        'System.Threading.Thread.Sleep(500)  'System.Threading.Thread.Sleep(1000) makes the form sleep for half Sec before the form will close        CForm.Close() 'Closes the Form that has focus    End SubEnd Module 
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×