16,554
社区成员
发帖
与我相关
我的任务
分享
我是会这样写
[code=VB.NET]
Module Module1
Sub Main()
Do
Dim a = Console.ReadLine
Try
Console.WriteLine(IsMyNumber(a))
Catch ex As ArgumentException
Console.WriteLine(ex.Message)
End Try
Loop While True
End Sub
Function IsMyNumber(ByVal text As String) As Double
Dim num As Double
If Double.TryParse(text, num) Then
If num = 0.0R Or (num >= -32.0R And num <= -10.0R) Then
Return num
Else
Throw New ArgumentException("参数不在范围内")
End If
Else
Throw New ArgumentException("不能转换为Double")
End If
End Function
End Module
Function IsTextNumber(ByVal strText As String) As Double
Dim dText As Double = 0.0
Try
dText = Convert.ToDouble(strText)
Catch ex As Exception
Return -1.0
End Try
Return dText
End Function