-1

I am trying to display the results of this case and format the total amount in currency. However, It's not working and I am not quite sure why? Could someone please take a look at my code and tell me if you see what my eyes cannot. I just need a second pair of eyes on this one. Thank you!

Select Case ApplianceButton
        Case "Refrigerator"
            Label17.Text = FormatCurrency(kwVal).ToString
        Case "TV"
            Label19.Text = FormatCurrency(kwVal).ToString
        Case "Fan"
            Label21.Text = FormatCurrency(kwVal).ToString
        Case "Space Heater"
            Label23.Text = FormatCurrency(kwVal).ToString
        Case "Oven"
            Label25.Text = FormatCurrency(kwVal).ToString
        Case "Dryer"
            Label27.Text = FormatCurrency(kwVal).ToString
        Case "Laundry Washer"
            Label29.Text = FormatCurrency(kwVal).ToString

Label30.Text = Int((kwVal(Label17.Text) + kwVal(Label19.Text) 
    + kwVal(Label21.Text) + kwVal(Label23.Text) + kwVal(Label25.Text) 
    + kwVal(Label27.Text) + kwVal(Label29.Text)))
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Victor
  • 9
  • 8
  • Are you trying to use a switch statement? http://stackoverflow.com/questions/15046553/example-of-switch-statements – Eric G Oct 10 '16 at 20:44
  • It is a select case statement, each case is an appliance and each appliance inherits a currency variable from the user input. I need to be able to add those values and provide a grand total – Victor Oct 10 '16 at 21:00
  • Currently I am getting an error BC30690 "Structure Decimal cannot be indexed because it has no default property – Victor Oct 10 '16 at 21:02
  • What are you trying to do with `kwVal(Label17.Text)`? – Blorgbeard Oct 10 '16 at 21:03
  • According to MSDN this is the answer on how to fix this issue, "An attempt was made to use default property syntax with a structure that has no default property. Error ID: BC30690 To correct this error Use standard property syntax to access the structure's properties." I have no idea what that means! – Victor Oct 10 '16 at 21:03
  • kwVal is the variable name, it stands for kilowatts value (Energy Costs) – Victor Oct 10 '16 at 21:09
  • I apologize I forgot to show the entire code that shows the declaration. Dim kwVal As Decimal = TotalCostofOperation.Text TotalCostofOperation.Text = FormatCurrency(kwVal) – Victor Oct 10 '16 at 21:11
  • 1) Have you tried putting in a break point to see which line is giving you issues? 2) Can you post the entire method(Sub)? It may make it a bit easier to understand. If I am understanding correctly, ApplianceButton is a string, and you are trying to update a different label depending on what that string is? – Gavin Perkins Oct 10 '16 at 21:37
  • Ok I will repost this with the entire code segment. – Victor Oct 10 '16 at 21:49
  • I know `kwVal` is a variable: What do you think `kwVal(Label17.Text)` means? That's what the error is complaining about. It doesn't make sense. If you explain what you are trying to do with that line, we can tell you how to do it correctly. – Blorgbeard Oct 11 '16 at 00:49

1 Answers1

-1

The Appliancebutton should be the value that should display or provide the name of your appliances, then than makes Dim Appliancebutton as string ?

then if you say that your Appliance button was clicked or in any kind of event that happened, then the value of Appliancebutton= should be either "Refrigerator" or "TV" or "Fan" etc...

to use Formatcurrency function, then kwVal should be an integer or double etc... right?

and then on the grand total, the kwVal(Label17.Text), seems like you are trying to multiply kwVal and the Label17.Text...

your symbol should be an asterisk * and you can't possibly multiply a string and an integer, then if it would help, use Convert.toint32(label17.text), to complete the equation, though it may be long, I prefer kwVal*(Convert.toint32(label17.text) ?

Just making a guess... I don't know if this is right or helpful to you.

Joan
  • 54
  • 8