inputbox函数格式如下:
a = InputBox("内容", "标题", "默认值")
比如下面代码:
Private Sub Form_click()
a = InputBox("内容", "标题", "默认值")
Print a
End Sub
单击窗体,则d出输入框,输入值之后,点确定,则在窗体上输出你所输入的值。
Dim str1 As String
i = InputBox("请输入一个数字", "请输入一个人数字")
If IsNumeric(i) Then
If Sgn(i) = -1 Then
str1 = "您输入的" & i & ":" & "负数"
Else
str1 = "您输入的" & i & ":" & "非负数"
End If
If Round(i) = i Then
If i Mod 2 = 0 Then
str1 = str1 + ",双数"
Else
str1 = str1 + ",单数"
End If
Else
str1 = str1 + ",小数"
End If
MsgBox str1
Else
MsgBox "你输入的不是一个数字", 32, "提示"
End If
dim i as integer
private sub command1_click() 'select case 方法
text1text =int(val(text1text))
if text1text >0 and text1text <8 then
i = text1text
select case i
case 1
debugprint "Monday"
case 2
debugprint "Tuseday"
……
end select
end if
end sub
private sub command2_click() 'choose方法
text1text =int(val(text1text))
if text1text >0 and text1text <8 then
i = text1text
debugprint choose(i,"Monday","Tuseday",……,"Sunday")
end if
end sub
Dim a(9) As Long
Private Sub Command1_Click()
Dim i As Long, b As String, c As Long'b as long 改为 string
For i = 0 To 9
N:
b = InputBox("请输入10个数字,这是第" & i + 1 & "个")
If IsNumeric(b) Then
a(i) = Val(b)'===============
Text1Text = Text1Text & a(i) & " "
Else
MsgBox "输入错误,请重新输入", vbOKOnly, "错误"
GoTo N
End If
Next i
End Sub
'示例代码如下: Private Sub Form_Click() Dim a() As Integer Do x = Val(InputBox("请输入整数:")) If x <> -1 Then b = b + 1 ReDim Preserve a(b) a(b) = x If x > 0 Then z = z + 1 If x < 0 Then f = f + 1 Print a(b); " "; End If Loop Until x = -1 Print For i = 1 To UBound(a) If a(i) > 0 Then zh = zh + a(i) If a(i) < 0 Then fh = fh + a(i) Next i Print "正数一共有:" & z & "个" Print "负数一共有:" & f & "个" Print "正数和是:" & zh Print "负数和是:" & fh End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)