Text: Option Strict On disallows implicit conversions from 'Double' to 'Integer'.
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.
Public Function MyFunction(ByVal A As String, ByVal B as String) As String
If Conversions.ToInteger(A) > Conversions.ToInteger(B) Then
Return A & " is larger than " & B
Else
Return B & " is larger than " & A
End if
End Function
Public Function MyFunction(ByVal A As String, ByVal B as String) As String
'' You need two versions of intNumber one for A and the other for B
'' Otherwise B will overwrite A
Dim intNumberA As Double
Dim intNumberB As Double
If Double.TryParse(A, intNumberA) > Double.TryParse(B, intNumberB)
Return A + " is larger than B"
Else
Return B + " is larger than A"
End if
End Function
Public Function MyFunction(ByVal A As String, ByVal B as String) As String
'' You need two versions of intNumber one for A and the other for B
'' Otherwise B will overwrite A
Dim intNumberA As Double
Dim intNumberB As Double
'' Convert values from the string
Double.TryParse(A, intNumberA)
Double.TryParse(B, intNumberB)
'' Use the Math.Max Library function to find the larger of the two
Dim maxValue = Math.Max(intNumberA, intNumberb)
'' See which was the larger and return the correct message
If maxValue = intNumberA
Return A + " is larger than B"
Else
Return B + " is larger than A"
End If
End Function
Imports Microsoft.VisualBasic.CompilerServices
Public Function MyFunction(ByVal A As String, ByVal B As String) As String
' Parse / validate input.
'
Dim numberA As Double
Dim numberB As Double
If Not Double.TryParse(A, numberA) Then
Return A & " is not a valid number."
End If
If Not Double.TryParse(B, numberB) Then
Return B & " is not a valid number."
End If
' Compare values.
'
If numberA > numberB Then
Return A & " is larger than " & B
ElseIf numberB > numberA Then
Return B & " is larger than " & A
Else
Return A & " is equal to " & B
End If
End Function
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
16 Experts available now in Live!