VB求最大值函数
text1里面有一个三位数,我想产生一个command1的点击事件,在text2输出text1中的三位数的最大的那位。控件3个:text1、text2、command1例...
text1里面有一个三位数,我想产生一个command1的点击事件,在text2输出text1中的三位数的最大的那位。
控件3个:text1、text2、command1
例如:text1中输入193,text2显示9
请试好了再来回答 展开
控件3个:text1、text2、command1
例如:text1中输入193,text2显示9
请试好了再来回答 展开
5个回答
展开全部
双击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
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型数组),则最大值别存储到变量中
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 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 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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询