BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / dot-net / #3697同步于 2012/5/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖

小白求高手解,VB求最大值,下面的代码是哪儿错了啊

fzl
2012/5/1镜像同步4 回复
Dim I As Integer = TextBox10.Text, J As Integer = TextBox16.Text, K As Integer = TextBox15.Text, L As Integer = TextBox14.Text, M As Integer = TextBox13.Text, N As Integer = TextBox12.Text, S As Integer = 0 If I < J Then S = J ElseIf S = I Then ElseIf S < K Then S = K ElseIf S = S Then ElseIf S < L Then S = L ElseIf S = S Then ElseIf S < M Then S = M ElseIf S = S Then ElseIf S < N Then S = N ElseIf S = S Then End If
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
yanglei5658机器人#1 · 2012/5/1
首先,TextBox.Text中的参数都是string类型吧,能不能直接赋值给integer类型的变量不得而知。可能需要类型转换。 其次,你这找最大值的方法也有点麻烦,为什么不把数值全部存到数组中,然后从数组中找到最大. 如果需要N个数比较大小,先把N个数存到数组中,然后: Dim Length As Integer Dim a(N) As Integer Dim i As Integer Dim maxValue As Integer Length = Len(a) maxValue = 0 for i = 0 to Length If a(i)>maxValue Then maxValue = a(i) End If Next i 【 在 fzl 的大作中提到: 】 : Dim I As Integer = TextBox10.Text, J As Integer = TextBox16.Text, K As Integer = TextBox15.Text, L As Integer = TextBox14.Text, M As Integer = TextBox13.Text, N As Integer = TextBox12.Text, S As Integer = 0 : If I < J Then : S = J : ...................
fzl机器人#2 · 2012/5/1
小白啊,刚开始学,数值是前一步的计算结果,不知道怎么存到数组里面,你写的后面的倒是看懂了,O(∩_∩)O谢谢
KuroNeko机器人#3 · 2012/5/1
下面的代码假设textbox里面都是数字,不一定是数字的话要用tryparse以防止异常 其实这种输入数字的建议用NumericUpDown控件,可以自动过滤掉非数字输入 Dim li As New List(Of Integer) From {Integer.Parse(TextBox1.Text), Integer.Parse(TextBox2.Text), Integer.Parse(TextBox3.Text), Integer.Parse(TextBox4.Text), Integer.Parse(TextBox5.Text)} li.Sort() MsgBox(li(li.Count - 1).ToString)
fzl机器人#4 · 2012/5/1
ls这种方法好方便啊,而且理解起来更容易,我受教了