Hi all,

I am extremely new to vb.net. I've been mucking around with the below project. I have also attached the original instructions to give you a better idea of what I'm supposed to be doing :) Anywho, here is my code. given that I don't get the results I want, I know my code is messed up somewhere:

Public Class mainForm
    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'add raise amounts to combo boxes
        For raise As Integer = 1 To 10 Step 1
            ComboBox1.Items.Add(raise.ToString)
        Next
        For raise As Integer = 1 To 10 Step 1
            ComboBox2.Items.Add(raise.ToString)
        Next
        For raise As Integer = 1 To 10 Step 1
            ComboBox3.Items.Add(raise.ToString)
        Next

        'display current salaries
        Call ShowCurrentSalary()

    End Sub
    Private Function ShowProjection(ByVal salary As Decimal, _
                               ByVal raise As Decimal)

        salary = salary * (1 + (raise * 0.01))
        Return salary

    End Function
    Private Function GrantRaise(ByRef salary As Decimal, _
                        ByRef raise As Decimal)

        salary = salary * (1 + (raise * 0.01))
        Return salary
    End Function
    Private Sub ShowCurrentSalary()
        Dim currentsalary1 As Decimal = 10000
        Dim currentsalary2 As Decimal = 11500
        Dim currentsalary3 As Decimal = 12300

        current1Label.Text = currentsalary1.ToString("C2")
        current2Label.Text = currentsalary2.ToString("C2")
        current3Label.Text = currentsalary3.ToString("C2")

    End Sub

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
        projected1Label.Text = String.Empty
        projected2Label.Text = String.Empty
        projected3Label.Text = String.Empty
    End Sub

    Private Sub projectedButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles projectedButton.Click
        Dim salary As Decimal
        Dim raise As Integer

        Call ShowProjection(salary, raise)

        projected1Label.Text = raise.ToString("C2")
        projected2Label.Text = raise.ToString("C2")
        projected3Label.Text = raise.ToString("C2")

        Call ShowCurrentSalary()

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projected1Label.Text, raise)


    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Integer.TryParse(projected2Label.Text, raise)
    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projected3Label.Text, raise)
    End Sub

    Private Sub grantButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grantButton.Click
        Dim salary As Decimal
        Dim raise As Integer

        Call GrantRaise(salary, raise)

        current1Label.Text = salary.ToString("C2")
        current2Label.Text = salary.ToString("C2")
        current3Label.Text = salary.ToString("C2")

        Call ShowCurrentSalary()
    End Sub
End Class

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hi all,

I am extremely new to vb.net. I've been mucking around with the below project. I have also attached the original instructions to give you a better idea of what I'm supposed to be doing :) Anywho, here is my code. given that I don't get the results I want, I know my code is messed up somewhere:

Public Class mainForm
    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'add raise amounts to combo boxes
        For raise As Integer = 1 To 10 Step 1
            ComboBox1.Items.Add(raise.ToString)
        Next
        For raise As Integer = 1 To 10 Step 1
            ComboBox2.Items.Add(raise.ToString)
        Next
        For raise As Integer = 1 To 10 Step 1
            ComboBox3.Items.Add(raise.ToString)
        Next

        'display current salaries
        Call ShowCurrentSalary()

    End Sub
    Private Function ShowProjection(ByVal salary As Decimal, _
                               ByVal raise As Decimal)

        salary = salary * (1 + (raise * 0.01))
        Return salary

    End Function
    Private Function GrantRaise(ByRef salary As Decimal, _
                        ByRef raise As Decimal)

        salary = salary * (1 + (raise * 0.01))
        Return salary
    End Function
    Private Sub ShowCurrentSalary()
        Dim currentsalary1 As Decimal = 10000
        Dim currentsalary2 As Decimal = 11500
        Dim currentsalary3 As Decimal = 12300

        current1Label.Text = currentsalary1.ToString("C2")
        current2Label.Text = currentsalary2.ToString("C2")
        current3Label.Text = currentsalary3.ToString("C2")

    End Sub

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
        projected1Label.Text = String.Empty
        projected2Label.Text = String.Empty
        projected3Label.Text = String.Empty
    End Sub

    Private Sub projectedButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles projectedButton.Click
        Dim salary As Decimal
        Dim raise As Integer

        Call ShowProjection(salary, raise)

        projected1Label.Text = raise.ToString("C2")
        projected2Label.Text = raise.ToString("C2")
        projected3Label.Text = raise.ToString("C2")

        Call ShowCurrentSalary()

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projected1Label.Text, raise)


    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Integer.TryParse(projected2Label.Text, raise)
    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projected3Label.Text, raise)
    End Sub

    Private Sub grantButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grantButton.Click
        Dim salary As Decimal
        Dim raise As Integer

        Call GrantRaise(salary, raise)

        current1Label.Text = salary.ToString("C2")
        current2Label.Text = salary.ToString("C2")
        current3Label.Text = salary.ToString("C2")

        Call ShowCurrentSalary()
    End Sub
End Class

salary was never assigned a value
If I figure this out I'll post the solution.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Public Class MainForm
    Dim crntslry101 As Decimal = 10000
    Dim crntslry102 As Decimal = 11500
    Dim crntslry103 As Decimal = 12300
    Dim raise101 As Decimal
    Dim raise102 As Decimal
    Dim raise103 As Decimal


    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'add raise amounts to combo boxes
        
        For raise As Integer = 1 To 10 Step 1
            prcntRazComboBox101.Items.Add(raise.ToString)
        Next
        For raise As Integer = 1 To 10 Step 1
            prcntRazComboBox102.Items.Add(raise.ToString)
        Next
        For raise As Integer = 1 To 10 Step 1
            prcntRazComboBox103.Items.Add(raise.ToString)
        Next

        'display current salaries
        ShowCurrentSalary()

    End Sub
    Private Sub shProjSlryBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles shProjSlryBtn.Click
        Dim salary As Decimal
        Dim raise As Integer
        If (String.Compare(prcntRazComboBox101.Text, "")) Then
            raise = Convert.ToInt32(prcntRazComboBox101.Text)
            projslryLbl101.Text = ShowProjection(crntslry101, raise)
        End If
        If (String.Compare(prcntRazComboBox102.Text, "")) Then
            raise = Convert.ToInt32(prcntRazComboBox102.Text)
            projslryLbl102.Text = ShowProjection(crntslry102, raise)
        End If
        If (String.Compare(prcntRazComboBox103.Text, "")) Then
            raise = Convert.ToInt32(prcntRazComboBox103.Text)
            projslryLbl103.Text = ShowProjection(crntslry103, raise)
        End If


        'projslryLbl101.Text = raise.ToString("C2")
        'projslryLbl102.Text = raise.ToString("C2")
        'projslryLbl103.Text = raise.ToString("C2")

        ShowCurrentSalary()

    End Sub
    Private Sub ShowCurrentSalary()
        slryLbl101.Text = crntslry101.ToString("C2")
        slryLbl102.Text = crntslry102.ToString("C2")
        slryLbl103.Text = crntslry103.ToString("C2")

    End Sub
    Private Function ShowProjection(ByVal salary As Decimal, _
        ByVal raise As Decimal)

        salary = salary * (1 + (raise * 0.01))
        Return salary.ToString("C2")

    End Function
    Private Function GrantRaise(ByRef salary As Decimal, _
        ByRef raise As Decimal)

        salary = salary * (1 + (raise * 0.01))
        Return salary
    End Function

    Private Sub prcntRazComboBox101_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles prcntRazComboBox101.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projslryLbl101.Text, raise)

    End Sub
    Private Sub prcntRazComboBox102_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles prcntRazComboBox102.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projslryLbl102.Text, raise)

    End Sub
    Private Sub prcntRazComboBox103_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles prcntRazComboBox103.SelectedIndexChanged
        Dim raise As Integer
        Dim assign As Boolean

        'assign value of selected raise
        assign = Decimal.TryParse(projslryLbl103.Text, raise)

    End Sub

    Private Sub GrntRasBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles GrntRasBtn.Click
        Dim raise As Integer
        If (String.Compare(prcntRazComboBox101.Text, "")) Then
            raise = Convert.ToInt32(prcntRazComboBox101.Text)
            slryLbl101.Text = ShowProjection(crntslry101, raise)
        End If
        If (String.Compare(prcntRazComboBox102.Text, "")) Then
            raise = Convert.ToInt32(prcntRazComboBox102.Text)
            slryLbl102.Text = ShowProjection(crntslry102, raise)
        End If
        If (String.Compare(prcntRazComboBox103.Text, "")) Then
            raise = Convert.ToInt32(prcntRazComboBox103.Text)
            slryLbl103.Text = ShowProjection(crntslry103, raise)
        End If
    End Sub


    Private Sub clrProjBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles clrProjBtn.Click
        projslryLbl101.Text = ""
        projslryLbl102.Text = ""
        projslryLbl103.Text = ""
    End Sub

    Private Sub exitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitBtn.Click
        Me.Close()
    End Sub

    
End Class

Edited 7 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

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