我如何在visual basic中编写这行c#。我试图获得用户的输入并提供结果,因为输入介于数字范围之间。
if int(>65 || <=73)
{
}
这是我到目前为止的代码。
Dim Hb As String = txtInput1.Text
If IsNumeric(Hb) Then
Dim HbInt As Integer = Integer.Parse(Hb)
Else
Output("The Hb value needs to be numeric")
End If
答案 0 :(得分:2)
vba中不允许使用Dim Hb As String = txtInput1.Text
,我认为txtInput1
是对单元格范围的命名引用。
你必须写如下
Dim Hb As String: Hb = txtInput1.Text
此Dim HbInt As Integer = Integer.Parse(Hb)
也不正确
正确的方法是:
Dim HbInt As Integer: HbInt = CInt(Hb)
所以您需要的代码是:
Sub NumRange()
Dim Hb As String: Hb = txtInput1.Text
if IsNumeric(Hb) then
Dim HbInt As Integer: HbInt = CInt(Hb)
if HbInt > 65 And HbInt <=73 then
Do things......
Else
Msgbox "Number Entered is out of Range"
End if
Else
Msgbox "Invalid Input."
End if
End Sub
答案 1 :(得分:1)
只需扩展@NewGuy提供的答案,我宁愿使用Option Explicit
Sub tmpTest()
Dim strHB As String
strHB = InputBox("Give me a number between 1 and 100", "Your choice...")
If IsNumeric(strHB) Then
Select Case CLng(strHB)
Case 66 To 73
MsgBox "You picked my range!"
Case 1 To 9
MsgBox "One digit only? Really?"
Case 99
MsgBox "Almost..."
Case Else
MsgBox "You selected the number " & strHB
End Select
Else
MsgBox "I need a number and not this:" & Chr(10) & Chr(10) & " " & strHB & Chr(10) & Chr(10) & "Aborting!"
End If
End Sub
语句来评估提供的数字。这将允许更多选择:
scoreDateTime
答案 2 :(得分:0)
像这样:
FunctionDeclaration