vb 求3位数的中间数

来源:百度知道 编辑:UC知道 时间:2024/05/25 14:24:28
求3位数的中间数的代码如何写

'建一个文本框,在里面输入数字,回车即得到中间数
'代码如下:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim result As Single
Dim a As Integer
If KeyAscii = 13 Then
a = Len(Text1.Text)
If a Mod 2 = 0 Then
result = (Val(Mid(Text1.Text, a / 2, 1)) + Val(Mid(Text1.Text, (a / 2 + 1), 1))) / 2
Else
result = Val(Mid(Text1.Text, Int(a / 2) + 1, 1))
End If
MsgBox "中间数为:" & result
End If
End Sub

代码如下。建一个Command1.
=========
Private Sub Command1_Click()
Dim a As String
a = InputBox("请输入三位数")
If Len(a) = 3 And IsNumeric(a) Then MsgBox Mid(a, 2, 1)
End Sub

MsgBox Mid(321, 2, 1)

sub midstr()
dim str as string
dim m as string
str=inputbox("输入一个3位数")
m=mid(str,2,1)
msgbox m,vbOkOnly,"结果"
end sub

Private Sub Command1_Click()
Dim a
a = InputBox("请输入三位数")
MsgBox Mid(a, 2, 1)
End Sub