Link to home
Start Free TrialLog in
Avatar of donnie91910
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:
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

Open in new window

Thanks.
Avatar of donnie91910
donnie91910

ASKER

I get this error when I run my code:


Text:    Option Strict On disallows implicit conversions from 'Double' to 'Integer'.
SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it gives me the error :
'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).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.'
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
Add this line to the top of the module containing the code I posted:
Imports Microsoft.VisualBasic.CompilerServices

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.