0

Good Morning SO,

I have a question and I know this is probably programming 101, but I am having trouble declaring a variable and then capturing its value to display in a label for further use in the application. I created an numeric up/down to limit the number of entries by the user. Now I just need to declare the variable and be able to display it on label16... I can't get it to work, I think its my syntax but I am not quite sure. In any case here is my code. I would really appreciate your help.

`'This textbox requests input from user in the form of numbers representing Hours of Operation Used'
Private Sub HoursOfOperation_ValueChanged(sender As Object, e As EventArgs) Handles HoursOfOperation.ValueChanged, HoursOfOperation.Click
    Dim hoursSelected As Object = Nothing
    Dim InthoursSelected = hoursSelected
    label16.Text = hoursSelected.ToString
End Sub` 
Victor
  • 9
  • 8
  • Your code makes no sense. You set `hoursSelected = Nothing`, and then assign that `Nothing` value to `InthoursSelected`, and then try to convert that `Nothing` in `hoursSelected` to a string and assign it to a label's `Text`. Does that sound logical to you? Try `Dim InthoursSelected = myNumericUpDown.Value`, and then `label16.Text = InthoursSelected.ToString()` instead. – Ken White Oct 07 '16 at 16:31
  • Thank you for your help, albeit seems a bit reluctant. Nevertheless, I thank you. I am a student and my exposure to programming has been very limited. The syntax was actually suggested by the software itself Visual Studio, and while it didn't make much sense to me, I figured the system more than likely knows a lot more than what I do, so I tried that. In any case, I will give your suggestion a try and hopefully I can accomplish what this program is designed to do. Thanks again. – Victor Oct 07 '16 at 17:41
  • It's not reluctant. My help is freely offered. My point was to try to get you to actually think about the code you're writing instead of just hammering out letters on the keyboard. Consider what your code is actually doing, just as I explained it, and see if what you're writing is logical behavior. Visual Studio didn't suggest that you write that code; it offered code that was possibly relevant. It's your job as a coder to use the appropriate choice from those possibilities, not just randomly select something and hope it works without understanding what it does. – Ken White Oct 07 '16 at 17:43
  • Thank you Ken, I appreciate your help. You're right, the software suggested a whole host of options, and the one I picked seemed like the best option from what was available. My point is I am not at the place where I can match my logic ( what I am trying to accomplish) with what the syntax should be or would be required in order for me to code successfully. It is nice to be able to ask for help from more experienced coders such as yourself that are willing to kindly provide assistance to us beginners. Thanks again btw Label16.Text = InthoursSelected.ToString() did work! – Victor Oct 09 '16 at 16:44
  • I have a follow up question, if you are up for it. There are 6 appliances each appliance holds 2 values intHoursSelected, CostOfOperation. I need to create a display area that will hold those two values and add them up to provide a total for each appliance individually and also a total cost for all appliances added together. I created buttons for each appliance that allows the user to enter the values for each. I also added a reset and exit button for the application. – Victor Oct 09 '16 at 17:08
  • I believe I have to create a conditional statement that would check the condition of each button (if it is selected or not) then hold the value of that specific appliance for hours and cost. I am not quite sure how to write that, would you like to see my application? and provide some assistance? – Victor Oct 09 '16 at 17:10

0 Answers0