Results 1 to 2 of 2

Thread: question

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    1

    question

    im doing a project for school and i cant figure this out...
    Private Sub btnCalculate_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnCalculate.Click

    Dim txtTotalSales As Single
    Dim txtCommissionPer As Single
    txtTotalSales = CSng(txtTotalSales)
    txtCommissionPer = CSng(txtCommissionPer)

    'Calculate Commission
    txtTotal = txtTotalSales * txtCommissionPer
    'Display Commission
    txtTotal.Text = FormatCurrency(txtTotal)
    End Sub
    that txtTotalSales * txtCommissionPer is coming up with an error that says value of 'single' cannot be converted to 'system.windows.form.textbox'
    any help would be Greatly apreciated

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: question

    Welome to the Forums

    You've used txtTotal on its own in that line, as though it was a variable, but which I guess (from a later line) refers to another textbox. If you want to refer to a property of an object, then refer to it. So don't name variables to be the same as objects and don't take the lazy option and let VB work out what property you want to use. Best to get into good habits sooner rather than later, otherwise unpredictable errors might result (as you have discovered).



    zaza
    Last edited by zaza; Oct 15th, 2006 at 03:32 PM.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width