12 Replies - 1907 Views - Last Post: 13 September 2012 - 10:29 PM Rate Topic: -----

#1 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 01:34 PM

I want to introduce myself to the board, my name is jacob and i am a computer geek!

No onto my question!

Need help with Visual Basic Code for windows application?
This is my code so far and it is designed to have a place to enter a number and another place for the modified number to appear. It is to calculate car sales commissions.

It does not work but i don't get any errors either so i am stumped, i have modified it quite a bit but no go...

Can anyone tell me why please????

I am bad at programming and i barely understand it, thanks for reading!

I have removed the boolean markers and that did not work.
I tried putting in a .tryParse line but it kept saying .text is not a member of decimal

I am in the process of going through my Pseudocode again to check for errors...

Dim txtsales As Decimal
Dim lblcommission As Decimal
Dim decRate As Decimal



If (txtsales >= 0 & txtsales <= 19999.99) Then
decRate = 0.04
ElseIf (txtsales >= 20000.0 & txtsales <= 29999.99) Then
decRate = 0.05
ElseIf (txtsales >= 30000.0 & txtsales <= 39999.99) Then
decRate = 0.06
ElseIf (txtsales >= 40000.0 & txtsales <= 49999.99) Then
decRate = 0.07
ElseIf (txtsales >= 50000.0) Then
decRate = 0.09
ElseIf (txtsales < 0) Then
decRate = 0
End If

lblcommission = txtsales * decRate




Is This A Good Question/Topic? 0
  • +

Replies To: Visual Basic Code for windows application, no errors but won't wor

#2 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 02:33 PM

I'm going to assume you have textboxes and labels with the same name that you declared as decimals.

If so, you need to change that

Then you can use TryParse against those declarations and process the calculation

Dim sales as Decimal
If not Decimal.TryParse(txtSales.Text, sales) Then
  'Show message for invalid entry
End If


Upon success of the parse, sales will contain the value you entered into the textbox.

Repeat this but keep in mind you're confusing the compiler naming your variables the same name as your controls.

EDIT:
Also in your comparison you need to replace the & with AND

This post has been edited by CharlieMay: 13 September 2012 - 02:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24   User is offline

  • D.I.C Lover
  • member icon


Reputation: 451
  • View blog
  • Posts: 2,188
  • Joined: 07-April 08

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 02:49 PM

Also, you don't set the Label Object itself equal to the commission you will want to set the .Text property instead.

lblcommission.Text = ....



You will also pull values out of Textboxes and labels the same way by calling the .Text property.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 02:54 PM

A better Logical Comparison to use is AndAlso as it only evaluates the second argument if the first argument parameter is true. Rather than evaluating both sides then deciding.

The other short-circuiting Logical Comparison is OrElse which doesn't evaluate the second argument parameter if the first ones is true.
Was This Post Helpful? 1
  • +
  • -

#5 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 04:18 PM

Ok so i made some changes but the code will not work and even gives an error if i try to use a .text for the lblcommission...

Dim txtsales As Decimal
        Dim lblcommission As Decimal
        Dim decRate As Decimal

        If txtsales >= 0 AndAlso txtsales <= 19999.99 Then
            decRate = 0.04
        ElseIf txtsales >= 20000.0 AndAlso txtsales <= 29999.99 Then
            decRate = 0.05
        ElseIf txtsales >= 30000.0 AndAlso txtsales <= 39999.99 Then
            decRate = 0.06
        ElseIf txtsales >= 40000.0 AndAlso txtsales <= 49999.99 Then
            decRate = 0.07
        ElseIf txtsales >= 50000.0 Then
            decRate = 0.09
        ElseIf txtsales < 0 Then
            decRate = 0
        End If

        lblcommission = decRate * txtsales

    End Sub



Was This Post Helpful? 0
  • +
  • -

#6 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 04:28 PM

The thing is i am very confused on how the pc is going to get confused when i understand it just fine, i understand if you made 20000 then to find the commission you multiply that by .04 percent!

View Postjheckman1986, on 13 September 2012 - 04:18 PM, said:

Ok so i made some changes but the code will not work and even gives an error if i try to use a .text for the lblcommission...

Dim txtsales As Decimal
        Dim lblcommission As Decimal
        Dim decRate As Decimal

        If txtsales >= 0 AndAlso txtsales <= 19999.99 Then
            decRate = 0.04
        ElseIf txtsales >= 20000.0 AndAlso txtsales <= 29999.99 Then
            decRate = 0.05
        ElseIf txtsales >= 30000.0 AndAlso txtsales <= 39999.99 Then
            decRate = 0.06
        ElseIf txtsales >= 40000.0 AndAlso txtsales <= 49999.99 Then
            decRate = 0.07
        ElseIf txtsales >= 50000.0 Then
            decRate = 0.09
        ElseIf txtsales < 0 Then
            decRate = 0
        End If

        lblcommission = decRate * txtsales

    End Sub



Was This Post Helpful? 0
  • +
  • -

#7 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 04:43 PM

This is my entire program!!!



Public Class frmMain

    Private Property BindingDirection As Object

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

    Private Sub btnCalc_Click(sender As System.Object, e As System.EventArgs) Handles btnCalc.Click


        Dim txtsales As Decimal
        Dim lblcommission As Decimal
        Dim decRate As Decimal

        If (txtsales >= 0 AndAlso txtsales <= 19999.99) Then
            decRate = 0.04
        ElseIf (txtsales >= 20000.0 AndAlso txtsales <= 29999.99) Then
            decRate = 0.05
        ElseIf (txtsales >= 30000.0 AndAlso txtsales <= 39999.99) Then
            decRate = 0.06
        ElseIf (txtsales >= 40000.0 AndAlso txtsales <= 49999.99) Then
            decRate = 0.07
        ElseIf (txtsales >= 50000.0) Then
            decRate = 0.09
        ElseIf (txtsales < 0) Then
            decRate = 0
            lblcommission = decRate * txtsales
        End If

    End Sub

    Private Sub txtSales_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSales.TextChanged
        
    End Sub

    Private Sub lblCommission_Click(sender As System.Object, e As System.EventArgs) Handles lblCommission.Click

    End Sub
End Class




Was This Post Helpful? 0
  • +
  • -

#8 rgfirefly24   User is offline

  • D.I.C Lover
  • member icon


Reputation: 451
  • View blog
  • Posts: 2,188
  • Joined: 07-April 08

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 04:49 PM

ok, the reason why the computer is getting confused is because it can not distinquish between a variable called txtsales and a textbox named txtsales. You need to rename all of your variables like so:

Dim sales As Decimal
Dim commission As Decimal
Dim decRate As Decimal



Also you need to call .Text property when dealing with textbox and label controls. If you don't the only thing you will get is {object} and not the text contained within the control like you expect.

This post has been edited by rgfirefly24: 13 September 2012 - 05:10 PM

Was This Post Helpful? 0
  • +
  • -

#9 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 05:44 PM

Ok i changed what you told me to and now the .text tag is sticking and not producing any errors but the program still does not work and all other suggestions have not worked, did i put the tryparse command in the wrong section of the code?

Public Class frmMain

    Private Property BindingDirection As Object

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

    Private Sub btnCalc_Click(sender As System.Object, e As System.EventArgs) Handles btnCalc.Click


        Dim sales As Decimal
        Dim commission As Decimal
        Dim decRate As Decimal

        If Not Decimal.TryParse(txtSales.Text, sales) Then
            'Show message for invalid entry
        End If

        If (sales >= 0 AndAlso sales <= 19999.99) Then
            decRate = 0.04
        ElseIf (sales >= 20000.0 AndAlso sales <= 29999.99) Then
            decRate = 0.05
        ElseIf (sales >= 30000.0 AndAlso sales <= 39999.99) Then
            decRate = 0.06
        ElseIf (sales >= 40000.0 AndAlso sales <= 49999.99) Then
            decRate = 0.07
        ElseIf (sales >= 50000.0) Then
            decRate = 0.09
        ElseIf (sales < 0) Then
            decRate = 0
            commission = decRate * sales
        End If

    End Sub

    Private Sub txtSales_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSales.TextChanged
        
    End Sub

    Private Sub lblCommission_Click(sender As System.Object, e As System.EventArgs) Handles lblCommission.Click

    End Sub
End Class




View Postrgfirefly24, on 13 September 2012 - 04:49 PM, said:

ok, the reason why the computer is getting confused is because it can not distinquish between a variable called txtsales and a textbox named txtsales. You need to rename all of your variables like so:

Dim sales As Decimal
Dim commission As Decimal
Dim decRate As Decimal



Also you need to call .Text property when dealing with textbox and label controls. If you don't the only thing you will get is {object} and not the text contained within the control like you expect.

Was This Post Helpful? 0
  • +
  • -

#10 rgfirefly24   User is offline

  • D.I.C Lover
  • member icon


Reputation: 451
  • View blog
  • Posts: 2,188
  • Joined: 07-April 08

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 06:42 PM

What do you mean the program doesn't work? We are unfortunately not mind readers so you will have to fill us in.

I did see that you never assign the gross pay to any controls on your form. Have you tried setting breakpoints to check what is happening in your program?

This post has been edited by rgfirefly24: 13 September 2012 - 07:00 PM

Was This Post Helpful? 0
  • +
  • -

#11 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 08:22 PM

I am sorry for not being more clear, the program turns on and responds but when i click the button after entering in a test number it does not show anything in the commission box, the program works but does not do anything.

There are two buttons, one that closes the program and the other that makes the magic happen.

Along with a text box that has a field where data can be entered into and another that is greyed out to receive the modified amounts.

So putting in a set gross pay is not possible for what the intended purpose is, which is to decide based on an amount what the commission should be by percentage and to then be told what the commission is, but the program does not do anything even if i click it many times and change the amounts. i am convinced i have to all wrong but i am new to this so i am unsure...

How do i insert breaks?


View Postrgfirefly24, on 13 September 2012 - 06:42 PM, said:

What do you mean the program doesn't work? We are unfortunately not mind readers so you will have to fill us in.

I did see that you never assign the gross pay to any controls on your form. Have you tried setting breakpoints to check what is happening in your program?

Was This Post Helpful? 0
  • +
  • -

#12 lucky3   User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 233
  • View blog
  • Posts: 770
  • Joined: 19-October 11

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 09:57 PM

jheckman1986 you will need to understand what your code is actually doing in each line when it gets executed. You will get better understanding, if you try this with your last posted version of code:
  • click into code line 12, where you have Dim sales As Decimal, and press F9. This will put a red dot, called breakpoint, at the start of that row;
  • run your program with F5;
  • put some values in your textboxes, and click btnCalc button;
  • program will break on the line, where you have set the breakpoint. Now press F8 once, so only this line of code gets executed, and sales becomes "alive";
  • hover your mouse pointer over sales, and see if it has some numerical value;
  • step further through your code with F8, and after each key press, hover over black "words" in one line above yellow marked row. Yellow marked row is the one, that will be executed on next F8 key press, and the line above it, has just been executed, so now the values of each row member (variables, object properties,...) just got their values, and you are able to observe them.


After doing this, you will probably know why your commission isn't calculated, and even if it was, you would still need to display it somewhere.

This post has been edited by lucky3: 13 September 2012 - 09:59 PM

Was This Post Helpful? 0
  • +
  • -

#13 jheckman1986   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-September 12

Re: Visual Basic Code for windows application, no errors but won't wor

Posted 13 September 2012 - 10:29 PM

I wanted to thank you for helping me but after twenty minutes i did manage to get it working but ti took a full rewrite to make it work.... I will be printing off all of the tips you and others have given me.... Here is the complete code so others may be able to learn from it if it's possible.

I look forward to learning more from this forum and thanks again!!!

' Purpose: Display a salesperson's commission
Public Class frmMain
    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click



        Me.Close()



    End Sub




    Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click



        Dim decMonthlySales As Decimal



        Dim decTotalCommission As Decimal




        Decimal.TryParse(txtSales.Text, decMonthlySales)



        Decimal.TryParse(lblCommission.Text, decTotalCommission)




        If decMonthlySales >= 0 And decMonthlySales < 20000 Then



            decTotalCommission = decMonthlySales * 0.04



        ElseIf decMonthlySales >= 20000 And decMonthlySales < 30000 Then



            decTotalCommission = decMonthlySales * 0.05



        ElseIf decMonthlySales >= 30000 And decMonthlySales < 40000 Then



            decTotalCommission = decMonthlySales * 0.06



        ElseIf decMonthlySales >= 40000 And decMonthlySales < 50000 Then



            decTotalCommission = decMonthlySales * 0.07



        ElseIf decMonthlySales >= 50000 Then



            decTotalCommission = decMonthlySales * 0.09



        Else



            decTotalCommission = 0



        End If




        lblCommission.Text = decTotalCommission.ToString("C2")



    End Sub

    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class





View Postlucky3, on 13 September 2012 - 09:57 PM, said:

jheckman1986 you will need to understand what your code is actually doing in each line when it gets executed. You will get better understanding, if you try this with your last posted version of code:
  • click into code line 12, where you have Dim sales As Decimal, and press F9. This will put a red dot, called breakpoint, at the start of that row;
  • run your program with F5;
  • put some values in your textboxes, and click btnCalc button;
  • program will break on the line, where you have set the breakpoint. Now press F8 once, so only this line of code gets executed, and sales becomes "alive";
  • hover your mouse pointer over sales, and see if it has some numerical value;
  • step further through your code with F8, and after each key press, hover over black "words" in one line above yellow marked row. Yellow marked row is the one, that will be executed on next F8 key press, and the line above it, has just been executed, so now the values of each row member (variables, object properties,...) just got their values, and you are able to observe them.


After doing this, you will probably know why your commission isn't calculated, and even if it was, you would still need to display it somewhere.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1