9 Replies - 1305 Views - Last Post: 29 March 2013 - 02:15 PM Rate Topic: -----

#1 Iammartine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-March 13

Problems with a Case Statement and Calculation

Posted 29 March 2013 - 12:06 PM

I am having problems with my code. When I try to calculate the commission the program automatically ends. I am very new to visual basic and am struggling to understand how to fix this. I have tried everything I can think of. Any help would be much appreciated.

My Code
'*******************************
'Program:       Commission Calculator
'Author:        Martine West
'Student ID:    3047710
'Course ID:     CMIS 214
'Assessment:    Assignment2A    Program 1
'Date:          March 23, 2013
'Purpose:       Create an application to calculate a salesperson's commission. 
'               This program takes the user input of salesperson's level and weekly sales and displays 
'               the calculation in a text field.
'             . The Clear button clears the textboxes and labels and the Exit button exits the application.


Public Class CommissionCalculator

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'clear all textboxes and labels
        txtSalesPersonLevel.Text = ""
        txtWeeklySales.Text = ""
        txtCommission.Text = ""
        txtSalesPersonLevel.Focus()

    End Sub
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'closes the application
        End

    End Sub

    Private Sub btnCommission_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommission.Click

        'declare variables for each category
        Dim dblSalesPersonLevel As Integer
        Dim dblWeeklySales As Double
        Dim dblCommission As Double

        txtCommission.Text = Format(dblCommission, "C")


        Select Case dblCommission

            Case 1
                dblSalesPersonLevel = dblWeeklySales * 0.02 + 500
            Case 2
                dblSalesPersonLevel = dblWeeklySales * 0.03 + 750
            Case 3
                dblSalesPersonLevel = dblWeeklySales * 0.04 + 1000
            Case 4
                dblSalesPersonLevel = dblWeeklySales * 0.05 + 1250

        End Select
        
        End

        'check to see if sales level entered is less than 1 or greater than 4
        If Val(txtSalesPersonLevel.Text) < 1 Or Val(txtSalesPersonLevel.Text) > 4 Then
            MessageBox.Show("Sales level can only be between 1 and 4")
            txtSalesPersonLevel.Select()
            'breaks out of procedure
        Else
            'get the sales person level
            dblSalesPersonLevel = Val(txtSalesPersonLevel.Text)
        End If

        'check to see if sales amount entered is between 1 and 100,000
        If (txtWeeklySales.Text) < 1 Or Val(txtSalesPersonLevel.Text) > 100000 Then
            MessageBox.Show("Sales can only be between $1 and $100,000")
        Else
            'get the sales level
            dblWeeklySales = Val(txtWeeklySales.Text)


        End If




    End Sub

This post has been edited by modi123_1: 29 March 2013 - 12:21 PM
Reason for edit:: highlight the text and just click the 'code' button in the text editor


Is This A Good Question/Topic? 0
  • +

Replies To: Problems with a Case Statement and Calculation

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 12:20 PM

VB questions go into the VB section.. not 'networking and wireless'. Moving.
Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 12:48 PM

Your program ends because you told it to end. Right after the Select Case block (which is between the Select Case and the End Select statements, you have an End statement, which ends the program.
Was This Post Helpful? 1
  • +
  • -

#4 Iammartine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-March 13

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 12:55 PM

Thank you. I moved the End and now my application no longer quits when I select the Commission button. However it is returning a $0.00 and not calculating the commission from the case statement.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 12:59 PM

You don't seem to be assigning any value to your weeklysales variable.
or commission for that matter.

Step through your code with the debugger and look at what value the variables have on initialization and then as you move down watch what is happening in the select case area to those variables.

This post has been edited by CharlieMay: 29 March 2013 - 01:01 PM

Was This Post Helpful? 0
  • +
  • -

#6 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 55
  • Posts: 285
  • Joined: 22-August 11

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 01:22 PM

View PostIammartine, on 29 March 2013 - 02:06 PM, said:

       'check to see if sales amount entered is between 1 and 100,000
        If (txtWeeklySales.Text) < 1 Or Val(txtSalesPersonLevel.Text) > 100000 Then
        ' one of these things is not like the other.


Was This Post Helpful? 1
  • +
  • -

#7 Iammartine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-March 13

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 02:01 PM

View PostCharlieMay, on 29 March 2013 - 12:59 PM, said:

You don't seem to be assigning any value to your weeklysales variable.
or commission for that matter.

Step through your code with the debugger and look at what value the variables have on initialization and then as you move down watch what is happening in the select case area to those variables.


Thank you. But like I said I am really new to visual basic and to be honest I am not certain how to do this.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 02:06 PM

Thank god we have a tutorial on that.. debugging
Was This Post Helpful? 0
  • +
  • -

#9 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 221
  • View blog
  • Posts: 738
  • Joined: 01-February 13

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 02:08 PM

Here is a tutorial here on DIC for debugging. Link :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,418
  • Joined: 29-May 08

Re: Problems with a Case Statement and Calculation

Posted 29 March 2013 - 02:15 PM

You should know (or if you don't should learn) to do basic research, check the available documentation (like MSDN, intellisense). Try doing some experiments, doesn't matter if these are not pretty or fail. Learn from the mistakes. It doesn't take that long to know up a simple console app, to try stuff out.

Pencil and Paper (or whiteboard) helps also, as it allows you to plan and architect the project. Think about the flow and transform of data (not guis first).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1