Help!
-
I am trying really hard, but I'm just not getting this... This is what I need to do... Set prompt = “Enter sides of the square” Show Input Box Convert string input to length Area = length * length Set output = “Square of side length “ + length + = “: “ + area This is where I am at... Dim prompt, sideLength As String Dim area, length As Double prompt = InputBox("Enter sides of the square.") sideLength = Convert.ToDouble(length) area = length * length Me.lblOutput.Text = "Square of side length " & length & ": " & area
-
I am trying really hard, but I'm just not getting this... This is what I need to do... Set prompt = “Enter sides of the square” Show Input Box Convert string input to length Area = length * length Set output = “Square of side length “ + length + = “: “ + area This is where I am at... Dim prompt, sideLength As String Dim area, length As Double prompt = InputBox("Enter sides of the square.") sideLength = Convert.ToDouble(length) area = length * length Me.lblOutput.Text = "Square of side length " & length & ": " & area
-
Member 10728667 wrote:
sideLength = Convert.ToDouble(length)
Where are you magically setting the value of "length"? Then you take the trouble of converting "length" to Double but then never use it. Learning to use the debugger is a very valuable skill.
Excuse me. I don't understand. I'm just learning this all, and it's very confusing. :(
-
Excuse me. I don't understand. I'm just learning this all, and it's very confusing. :(
Edited. Misread the code. length is actual declared as a double. We can't possibly know what is confusing you unless you tell us. You are trying to convert a string to a double right? The string you are trying to convert is named "length" right? Look at your code and see if you can find anywhere in your code where you are setting "length" to be something other than an empty string.... Your code as it stands right now is you are trying to convert length (which is a double) to a double. Then put that result in a string named "sideLength". Why would you convert a double to a double? Does it make more sense to you to convert the user input to a double? Then you take the result of your convert operation and put that into a variable named "sideLength", then you don't use it anywhere. Learn to use the debugger and you can follow the code and see what it is doing.
-
I am trying really hard, but I'm just not getting this... This is what I need to do... Set prompt = “Enter sides of the square” Show Input Box Convert string input to length Area = length * length Set output = “Square of side length “ + length + = “: “ + area This is where I am at... Dim prompt, sideLength As String Dim area, length As Double prompt = InputBox("Enter sides of the square.") sideLength = Convert.ToDouble(length) area = length * length Me.lblOutput.Text = "Square of side length " & length & ": " & area
Dim prompt, sideLength As String
Dim area, length As Doubleprompt = InputBox("Enter sides of the square.")
' On return from this method, "prompt" will contain the value typed by the user
' so that is the string that needs to be converted to a number.sideLength = Convert.ToDouble(length)
' You are trying to convert the variable "length" to a number,
' but you have not done anything to get a value into it.
' You have also declared "sideLength" as a string, but now
' you are trying to store a Double value into it.area = length * length
Me.lblOutput.Text = "Square of side length " & length & ": " & areaTake a look at http://msdn.microsoft.com/en-GB/library/6z0ak68w(v=vs.90).aspx[^] for an example of how to use the
InputBox
method.