资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net从大到小排列,vb从大到小排序

VB做 键盘输入三个数,按由大到小顺序输出。

private

创新互联公司自2013年创立以来,先为兴平等服务建站,兴平等地企业,进行企业商务咨询服务。为兴平企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

sub

command1_click()

dim

a

as

long,

b

as

long,

c

as

long

a

=

inputbox("请输入第1个数的值",

"提示")

b

=

inputbox("请输入第2个数的值",

"提示")

c

=

inputbox("请输入第3个数的值",

"提示")

d

=

iif(iif(a

b,

a,

b)

c,

iif(a

b,

a,

b),

c)

x

=

iif(iif(a

b,

a,

b)

c,

iif(a

b,

a,

b),

c)

z

=

a

+

b

+

c

-

d

-

x

cls

print

a

"

,

"

b

"

,

"

c

"按从大到小排列为"

d

"

"

z

"

"

x

end

sub

==============================

如果是vb.net

,可以用math类的max,min方法,呵

vb 由大到小与由小到大排序代码解释

Private Sub Command1_Click()

Dim a As Integer 定义a变量为整型变量

Dim b As Integer 定义b变量为整型变量

Dim c As Integer 定义c变量为整型变量

Dim m As Integer 定义m变量为整型变量,用作比较时的临时变量

Label3.Caption = Val(Text1.Text) 将Text1录入的值显示到Label3

Label4.Caption = Val(Text2.Text) 将Text2录入的值显示到Label4

Label5.Caption = Val(Text3.Text) 将Text3录入的值显示到Label5

a = Val(Text1.Text) 将Text1录入的值赋给变量a

b = Val(Text2.Text) 将Text2录入的值赋给变量b

c = Val(Text3.Text) 将Text3录入的值赋给变量c

If a b Then m = a: a = b: b = m

比较a,b的值,如果ab,则a,b互换,变量m起到临时存放数值的作用,

If a c Then m = a: a = c: c = m

比较a,c的值,如果ac,则a,c互换

If b c Then m = b: b = c: c = m

比较b,c的值,如果bc,则b,c互换

Label7.Caption = a " " b " " c

在Label7上显示由大到小的三个数值

End Sub

由小到大:

Private Sub Command1_Click()

Dim a As Integer 定义a变量为整型变量

Dim b As Integer 定义b变量为整型变量

Dim m As Integer 定义c变量为整型变量

a = Val(Text1.Text)将Text1录入的值赋给变量a

b = Val(Text2.Text)将Text2录入的值赋给变量b

Label4.Caption = Val(Text1.Text) 将Text1录入的值显示到Label4

Label5.Caption = Val(Text2.Text) 将Text2录入的值显示到Label5

If a b Then m = a: a = b: b = m

比较a,b的值,如果ab,则a,b互换,变量m起到临时存放数值的作用,

Label6.Caption = a " " b

在Label6上显示由小到大的两个数值

End Sub

求10个数按照从大到小的顺序排列 要求用插入、选择两种方法 vb.net程序 (控制台应用程序)

'选择法

Private Sub Command9_Click()

Me.Cls '创建Text1,输入10组数据,用空格分开之

Dim i, j, Maxid As Integer, Max, k(0 To 9), tmp As Single, f() As String

f() = Split(Trim(Text1), " ")

If UBound(f) 9 Then Exit Sub

For i = 0 To 9

k(i) = CSng(f(i))

Next i

For i = 0 To 9

Max = k(0)

Maxid = 0

k(0) = k(9 - i)

For j = 0 To (8 - i)

If k(j) Max Then

tmp = Max

Max = k(j)

k(j) = tmp

Maxid = j

End If

Next j

Print Max;

Next i

End Sub

'====================================================

'插入法

'创建控件Command5,Text3,在Text3中输入若干组数据,并用空格分开各组数据

Text3 = Trim(Text3)

Dim f() As String, tmp As Single, i As Single, j As Single

f = Split(Text3, " ")

If UBound(f) = 0 Then Exit Sub

ReDim h(0 To UBound(f) - 1) As String

For i = 0 To UBound(f)

For j = i To UBound(f)

If CSng(f(j)) CSng(f(i)) Then

tmp = f(i)

f(i) = f(j)

f(j) = tmp

End If

Next j

Next i

Text3 = ""

For i = 0 To UBound(f)

Text3 = Text3 CSng(f(i))

If i UBound(f) Then Text3 = Text3 " "

Next i

编写一个 VB.NET 程序,产生 100 个 100 以内的随机数,将他们从大到小排序后输出

Private Sub Command1_Click()

Dim a(1 To 100) As Integer

Dim i As Integer, j As Integer, k As Integer

For i = 1 To 100 '给数组a一百个元素赋值,并换每行十个数字输出来窗体上

a(i) = Int(Rnd * 101)

k = k + 1

Print Tab((k - 1) * 5); a(i);

If k = 10 Then k = 0: Print

Next i

Print

Print

For i = 100 To 2 Step -1 '用冒泡排序法对数组进行排序

For j = 1 To i - 1

If a(j) a(j + 1) Then

t = a(j): a(j) = a(j + 1): a(j + 1) = t

End If

Next j

Next i

For i = 1 To 100 '输出排好序的数组

k = k + 1

Print Tab((k - 1) * 5); a(i);

If k = 10 Then k = 0: Print

Next i

End Sub

vb编程提问:键盘输入三个数,按由大到小顺序输出。

Private

Sub

Command1_Click()

Dim

a

As

Long,

b

As

Long,

c

As

Long

a

=

InputBox("请输入第1个数的值",

"提示")

b

=

InputBox("请输入第2个数的值",

"提示")

c

=

InputBox("请输入第3个数的值",

"提示")

d

=

IIf(IIf(a

b,

a,

b)

c,

IIf(a

b,

a,

b),

c)

x

=

IIf(IIf(a

b,

a,

b)

c,

IIf(a

b,

a,

b),

c)

z

=

a

+

b

+

c

-

d

-

x

Cls

Print

a

"

,

"

b

"

,

"

c

"按从大到小排列为"

d

"

"

z

"

"

x

End

Sub

==============================

如果是VB.net

,可以用math类的MAX,MIN方法,呵

求vb.net(vb2010)程序代码 产生30个50以内的随机正整数,将他们从大到小排序后输出

vb2010写的:

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Dim str As String = ""

Dim a(30) As Integer

Dim temp As Integer

str = str  "生成的30个随机数字是 "  vbCrLf

For i = 1 To 30

a(i) = Int(Rnd() * 50 + 1)

str = str  a(i)  " "

If i Mod 10 = 0 Then

str = str  vbCrLf

End If

Next

str = str  vbCrLf

For i = 1 To 30

For j = 1 To 30 - i

If a(j)  a(j + 1) Then

temp = a(j + 1)

a(j + 1) = a(j)

a(j) = temp

End If

Next j

Next i

str = str  "排序后的数字是 "  vbCrLf

For i = 1 To 30

str = str  a(i)  " "

If i Mod 10 = 0 Then

str = str  vbCrLf

End If

Next

TextBox6.Text = str

End Sub

运行结果:

生成的30个随机数字是

36 27 29 15 16 39 1 39 41 36

3 21 44 40 19 49 44 3 48 19

27 39 3 30 24 15 32 33 14 14

排序后的数字是

49 48 44 44 41 40 39 39 39 36

36 33 32 30 29 27 27 24 21 19

19 16 15 15 14 14 3 3 3 1


网页标题:vb.net从大到小排列,vb从大到小排序
路径分享:http://cdkjz.cn/article/dsseecg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220