donnie91910
asked on
strings compare (numeric).
I have started a function, what I need for the function to do is to is to compare two numeric strings and determine which is larger. the strings also need to be declared as double .
Here is what I have so far:
Here is what I have so far:
Public Function MyFunction(ByVal A As String, ByVal B as String) As String
' Dim A as double
Dim intNumber as double
If Integer.TryParse(A, intNumber) > Integer.TryParse(B, intNumber)
Return A + "is larger than B"
Else
Return B + "is larger than A"
End if
End Function
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it gives me the error :
'Conversions' is not declared. It may be inaccessible due to its protection level.
'Conversions' is not declared. It may be inaccessible due to its protection level.
It should be convert.tointeger, however that is .net code not classic VB
In classic VB you would use Val(A) > val(B).
In classic VB you would use Val(A) > val(B).
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I received the message:
Your code returned '-3 is larger than A'
Given parameters: 39, -3, expected a value of 'A is larger than B.'
Your code returned '-3 is larger than A'
Given parameters: 39, -3, expected a value of 'A is larger than B.'
ASKER
so basically this is what I am trying to do:
Create a function that compares two numeric strings and determines which is larger. then i need to make sure that my code includes input validation.
Create a function that compares two numeric strings and determines which is larger. then i need to make sure that my code includes input validation.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get the following errors:
Line: 29
Text: Option Strict On requires all variable declarations to have an 'As' clause.
Line: 29
Text: 'Math' is not declared. It may be inaccessible due to its protection level.
Line: 32
Text: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.
Line: 29
Text: Option Strict On requires all variable declarations to have an 'As' clause.
Line: 29
Text: 'Math' is not declared. It may be inaccessible due to its protection level.
Line: 32
Text: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.
Change this line of code by add As Double
Dim maxValue = Math.Max(intNumberA, intNumberb)
To this, which is caused by having Option Strict On. The Math functions is located in the System namespace and should already have an reference to it so I added it to the line below in case you do not have it set in the file.
Dim maxValue As Double = System.Math.Max(intNumberA , intNumberb)
There is no line 32 in the code I posted Please post the relevant code.
Dim maxValue = Math.Max(intNumberA, intNumberb)
To this, which is caused by having Option Strict On. The Math functions is located in the System namespace and should already have an reference to it so I added it to the line below in case you do not have it set in the file.
Dim maxValue As Double = System.Math.Max(intNumberA
There is no line 32 in the code I posted Please post the relevant code.
Add this line to the top of the module containing the code I posted:
Imports Microsoft.VisualBasic.CompilerServices
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
ASKER
Text: Option Strict On disallows implicit conversions from 'Double' to 'Integer'.