双击command1,写下
dim a as string
dim amax as integer,temp as integer
a=trim(text1)'去除text1中的空格,将值赋给a
amax=0'设置amax的初值,因为是找最大值,所以取0
for i=1 to len(a)'循环,从1到a的长度
temp=val(mid(a,i,1))'从a中第i个位子取一个数
if temp>=amax then amax=temp'和最大值比较
next i
text2=amax
function
maxfound(a()
as
long)
'long可修改为其它类型,以适应不同的要求
dim
nummax
nummax
=
a(1)
for
i
=
2
to
8
if
nummax
<
a(i)
then
nummax
=
a(i)
end
if
next
i
maxfound
=
nummax
end
function
函数条用格式:变量=maxfound(long型数组),则最大值别存储到变量中
两个文本框,一个按钮
Option Base 1
Private Sub Command1_Click()
Dim max As Integer
If Text1.Text = "" Then
MsgBox "文本不能为空"
Exit Sub
End If
max = Mid(Text1, 1, 1)
For i = 2 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) > max Then
max = Mid(Text1.Text, i, 1)
End If
Next i
Text2.Text = max
End Sub
Option Explicit
Private Sub Command1_Click()
Dim l As Integer, max As Integer
Dim i As Integer, a As Integer
l = Len(Text1.Text)
If IsNumeric(Text1.Text) = False Then MsgBox "text1内不是数字"
max = Left(Text1.Text, 1)
For i = 2 To l
a = Mid(Text1.Text, i, 1)
If a > max Then max = a
Next
Text2.Text = max
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = 9 To 0 Step -1
If InStr(1, Text1.Text, i) > 0 Then Text2.Text = i: Exit Sub
Next
End Sub