Here is what I have. I need the check boxes to add the variables Masters(3000) and doctorate(8000) to whatever the value of the current radio box. If they are both checked then they should both be sumed along with the current radio box value. If they are unchecked it should also update. Everything is outputed to lblSalaryOutput.text. I need to use a sub/Function to calculate. Am I on the right path? What do I still need to do, and if possible can someone provide me an example. I am not looking for someone to complete this but I could use very basic examples because Im very novice. It is for a class and is due tonight so Im hoping for some help soon. I also included an image of the form.

Option Explicit On
Option Strict On
Imports System.Math



Public Class frmMain
    Dim lecturer As Integer = 50000
    Dim instructor As Integer = lecturer * 1.3
    Dim assistant As Integer = lecturer * 1.6
    Dim associate As Integer = lecturer * 1.8
    Dim professor As Integer = lecturer * 2.0
    Dim masters As Integer = 3000
    Dim doctorate As Integer = 8000



    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        End
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MsgBox("This program was written by Steven R. Robinson", MsgBoxStyle.OkOnly, "Author")
    End Sub

    Private Sub optLect_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optLect.CheckedChanged

        lblSalOutput.Text = CStr(lecturer)

    End Sub

    Private Sub optInst_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optInst.CheckedChanged

        lblSalOutput.Text = CStr(instructor)

    End Sub

    Private Sub optAssistPro_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAssistPro.CheckedChanged

        lblSalOutput.Text = CStr(assistant)

    End Sub

    Private Sub optAssocProf_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAssocProf.CheckedChanged

            lblSalOutput.Text = CStr(associate)
    End Sub

    Private Sub optProf_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optProf.CheckedChanged

        lblSalOutput.Text = CStr(professor)

    End Sub

    Private Sub chkMast_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMast.CheckedChanged




    End Sub


End Class
Attachments Capture.JPG 26.6 KB

since you have the code structured like it is you will want to place the same piece of code in a number of places, accordingly, it is probably better to put it in a function, line 40 becomes

lblSalOutput.Text = CStr(assistant + addLoading)

then your addLoading function looks like

private function addLoading
    dim Loading as long
    Loading = 0
    if chkMast then Loading = Loading + masters
    if chkDoct then Loading = Loading + doctorate
    addLoading = Loading
end function

Note also integers can only hold up to 32,767 you should use long.

Edited 4 Years Ago by ChrisPadgham: n/a

So I need to replace my line 40 with that code and then in all the other radio buttons as well. Where would the function go? I am sorry but I am so confused. I also think I may be wrong with the Cstr in front of my variables because I really need the outcome to in the label to look like a currency style. I think it has something to do with ToString? Somehow converts 50000 to $50,000.00. Thank you for the help you have already given me and Ill play with it.

So I am actually almost finished after tweaking things, down to the last half hour before I need to submit this. Last thing I need to figure out is how to weight the checkboxes like the otion buttons are weighted. If the optInst is selected at line 31 then chkMast or chkDoct needed to be weighted by 1.3. How do I do that witout some crazy amount of if statements? That would have to happen for all option buttons.

Option Explicit On
Option Strict On



Public Class frmMain
    Dim lecturer As Integer = 50000
    Dim instructor As Integer = lecturer * 1.3
    Dim assistant As Integer = lecturer * 1.6
    Dim associate As Integer = lecturer * 1.8
    Dim professor As Integer = lecturer * 2.0
    Dim masters As Integer = 3000
    Dim doctorate As Integer = 8000



    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        End
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MsgBox("This program was written by Steven R. Robinson", MsgBoxStyle.OkOnly, "Author")
    End Sub

    Private Sub optLect_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optLect.CheckedChanged

        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))

    End Sub

    Private Sub optInst_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optInst.CheckedChanged

        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))

    End Sub

    Private Sub optAssistPro_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAssistPro.CheckedChanged

        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))

    End Sub

    Private Sub optAssocProf_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAssocProf.CheckedChanged

        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))
    End Sub

    Private Sub optProf_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optProf.CheckedChanged

        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))

    End Sub

    Private Sub chkMast_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMast.CheckedChanged


        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))

    End Sub

    Private Sub chkDoct_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDoct.CheckedChanged

        lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))

    End Sub

    Private Function sumTotal() As Integer
        Dim x As Integer
        x = 0
        If optLect.Checked Then x = x + lecturer
        If optInst.Checked Then x = x + instructor
        If optAssistPro.Checked Then x = x + assistant
        If optAssocProf.Checked Then x = x + associate
        If optProf.Checked Then x = x + professor
        If chkMast.Checked Then x = x + masters
        If chkDoct.Checked Then x = x + doctorate
        sumTotal = CInt(x)

    End Function


End Class

>>If the optInst is selected at line 31 then chkMast or chkDoct needed to be weighted by 1.3.
You mean if RB Instructor is selected then checkbox master and doctor should be checked?

Private Sub optInst_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optInst.CheckedChanged
 
lblSalOutput.Text = FormatCurrency(CInt(sumTotal()))
    If optInst.Checked = True Then
        chkMast.Checked = True
        chkDoct.Checked = True
    End If
End Sub

Edited 4 Years Ago by Jx_Man: n/a

This article has been dead for over six months. Start a new discussion instead.