hello i am stuck writing a code in visual basics. i keep getting an error messag
ID: 3865266 • Letter: H
Question
hello i am stuck writing a code in visual basics. i keep getting an error message and i dont know how to fix it. the error message reads " structure 'double' cannot be indexed because it has no default propert" im not sure what that means.
Option Strict On
Public Class InchesToMetric
Private Sub MillimetersButton_Click(sender As Object, e As EventArgs) Handles MillimetersButton.Click
Dim Inches As Double ' To hold the inches
Dim Millimeters As Double ' To hold the millimeters
Try
' Get the inches.
Inches = CDbl(InchesText.Text)
' Convert inches to millimeters.
Millimeters = INCHESTOMM(Inches)
' Display the result.
MessageBox.Show(Inches.ToString() & " inches equals " &
Millimeters.ToString() & " millimeters.")
Catch
' Display an error message for invalid input.
MessageBox.Show("Error: Enter a numeric value.")
End Try
End Sub
this is the module that i want it to get the information from
Option Strict On
Module MathModule
' Constants for the meters to English conversion factors
Public Const METERSTOINCHES As Double = 39.37
Public Const METERSTOFEET As Double = 3.28
Public Const METERSTOYARDS As Double = 1.09
' Constants for the inches to metric conversion factors
Public Const INCHESTOMM As Double = 25.4
Public Const INCHESTOCM As Double = 2.54
Public Const INCHESTOMETERS As Double = 0.0254
' The MetersToInches function accepts a number of meters as
' an argument and returns the equivalent number of inches.
Public Function MetersToInchesReturn(ByVal Meters As Double) As Double
Return Meters * METERSTOINCHES
End Function
' The MetersToFeet function accepts a number of meters as
' an argument and returns the equivalent number of feet.
Public Function MetersToFeetReturn(ByVal Meters As Double) As Double
Return Meters * METERSTOFEET
End Function
' The MetersToYards function accepts a number of meters as
' an argument and returns the equivalent number of yards.
Public Function MetersToYardsReturn(ByVal Meters As Double) As Double
Return Meters * METERSTOYARDS
End Function
' The InchesToMM function accepts a number of inches as
' an argument and returns the equivalent number of millimeters.
Public Function InchesToMMReturn(ByVal Inches As Double) As Double
Return Inches * INCHESTOMM
End Function
' The InchesToCM function accepts a number of inches as
' an argument and returns the equivalent number of centimeters.
Public Function InchesToCMReturn(ByVal Inches As Double) As Double
Return Inches * INCHESTOCM
End Function
' The InchesToMeters function accepts a number of inches as
' an argument and returns the equivalent number of meters.
Public Function InchesToMetersReturn(ByVal Inches As Double) As Double
Return Inches * INCHESTOMETERS
End Function
End Module
Explanation / Answer
I've gone through the code and the error message both.
The error is coming because of the name here in the following line in your code..
Millimeters = INCHESTOMM(Inches)
See, in your module MathModule, you are defining few constants that are useful for conversions right. One of them is INCHESTOMM which you've defined as type double.
The function which returns the value from inches to mm is named here as InchesToMMReturn() and its return type is also double. This function is using the constant you defined above.
So, in order to get this conversion, you should write
Millimeters = INCHESTOMMReturn(Inches)
This is the function which does the specified task.
In your code, you're passing the argument to the constant, it is not a function. And as it is of type double, you're getting this error.
So, simply change the constant name to function name in that line and the code is good to go. This may have happened due to name similarity. The code is right.
Do comment if there is any query. Thank you. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.