0

I'm a bit of a noob. When I try to build my solution I get this single error and I don't know what to do to fix it.

 'Calculate and display cost estimate
                decCostEstimate = decFeet * decCostPerFoot
                **lblCostEstimate = decCostEstimate.ToString("C")**

I'm not sure what to do. Please help me.

Til
  • 5,150
  • 13
  • 26
  • 34
Jazz
  • 11
  • 1
  • 1
  • 5
    If you use [`Option Strict On`](https://stackoverflow.com/a/29985039/1115360) then Visual Studio will tell you that something is wrong even before you get to the stage of trying to build the solution. – Andrew Morton Feb 03 '19 at 16:42
  • 1
    You can find this setting in Tools Menu -> Options -> Projects and Solutions -> VB Defaults. This will save you from bugs at runtime. – Mary Feb 03 '19 at 20:08

2 Answers2

1

You want to set the Text property of the label, not the label itself

lblCostEstimate.Text = decCostEstimate.ToString("C")

Your code tries to assign a string value to an object of type Label, thus causing the error.

kennyzx
  • 12,845
  • 6
  • 39
  • 83
1

The label is an object from the type Label. It is not possible to write an object from Type int or string, etc. into an label-object.

To make the label show your result just put the result into the text-property of the label:

lblCostEstimate.Text = decCostEstimate.ToString("C")

Jens G
  • 63
  • 7