重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net变量排序,VB 排序

vb.net 如何对数据库查询结果记录集排序?

加了单引号就是一个常量字符串了,对于每一行都是一样的

创新互联一直在为企业提供服务,多年的磨炼,使我们在创意设计,全网整合营销推广到技术研发拥有了开发经验。我们擅长倾听企业需求,挖掘用户对产品需求服务价值,为企业制作有用的创意设计体验。核心团队拥有超过十年以上行业经验,涵盖创意,策化,开发等专业领域,公司涉及领域有基础互联网服务眉山服务器托管app软件开发公司、手机移动建站、网页设计、网络整合营销。

像这种放在最前面的字段,order by 1 就可以了

VB.NET 程序 随机产生10个整数并进行排序

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim N As Integer = 9

Randomize()

Dim xx(9) As Integer

For i As Integer = 0 To N

xx(i) = Int(Rnd() * 1000) '产生 [0,1000) 之间的整数

Next

For i As Integer = 0 To N - 1

For j As Integer = i + 1 To N

If xx(i) xx(j) Then

Dim temp As Integer = 0

temp = xx(i) : xx(i) = xx(j) : xx(j) = temp

End If

Next

Next

Dim sum As Integer = 0

For i As Integer = 0 To N

TextBox1.Text += xx(i) vbCrLf

sum += xx(i)

Next

TextBox1.Text += "最大值:" xx(9) vbCrLf "最小值:" xx(0) vbCrLf "平均值:" sum / 10

End Sub

End Class

VB.NET中数据的排序问题

建议用 DataGridView(你用的是它吧?)内建的排序方法来排序。介绍和示例代码可以参考MSDN:

vb.net 排列组合 代码

第一题:

不需要任何控件,代码如下:

Private Sub Form_Click()

Dim A() As Integer, N As Integer

Dim St As String, I As Integer, J As Integer

Randomize

Do

St = InputBox("数字的个数", "输入", Int(Rnd * 100))

If St = "" Then

MsgBox "请输入数字!"

Else

N = Int(Val(St))

If N 1 Then

MsgBox "请输入大于0的数字!"

Else

Exit Do

End If

End If

Loop

ReDim A(N)

For I = 1 To N

Do

St = InputBox("第" + Str(I) + "个数字", "输入", Int(Rnd * 100))

If St = "" Then

MsgBox "请输入数字!"

Else

A(I) = Int(Val(St))

Exit Do

End If

Loop

Next

For I = 1 To N - 1

For J = I + 1 To N

If A(I) A(J) Then

A(0) = A(I)

A(I) = A(J)

A(J) = A(0)

End If

Next

Next

For I = 1 To N

Open App.Path "\" Trim(Str(I)) ".txt" For Output As #1

Print #1, A(I)

Close #1

Next

Print "已经把"; N; "个数写入到"; App.Path; "\1.txt 到 "; N; ".txt中.请查看."

End Sub

'已经运行过.

第二题:

DIM 是变量声明语句,它的格式为:

dim 变量名[as 格式] [,变量名[as 格式][,变量名[as 格式]......]

其中:

变量名:以字母或汉字开始的字串,代表一个变量

格式有以下几种:

属于数字的有五种:

(1)字节型:byte可取值0-255

(2)整形:integer可取值-32768至32767

(3)长整形:long(可取值范围很大的正负整数)

(4)单精度型:single(可取值小数)

(5)双精度型:double(可取值范围更大,小数位数更多的小数)

字符串型:string(可代表由字母\数字或汉字组成的字符集合)

布尔型:boolean(取值为ture\false)

日期型:date(可表示形如2009-5-26 02:36这样的组合)

如果要用姓名\住址\单位名称...等用字符串型(string)

eg:dim name as string(用name变量表示名字时,声明成字符串变量)

如果是用数字需要做计算,如工资\合计\人数....等要用数字型,但有一个原则,优先选用范围小的(按照字节型(byte)\整形(integer)\长整形(long)\单精度型(single)\双精度型(double)的顺序选择),够用就可以了,这样可以占用内存少,运算速度快.

eg:dim count as integer(用integer表示员工人数时,可声明成整形变量)

eg:dim sum as single(用sum表示工资时,可声明成单精度型变量)

不知是否说得清楚了.

VB.net 数组怎么按任意元素的顺序排序输出

你直接传一个数组进去,而且是一个结构体数组,array.sort怎么知道根据结构中的哪一个属性进行排序?放一个c#的代码你看看,VB和C#很相似的

class Program

{

static void Main(string[] args)

{

People[] p = new People[3]

{

new People{name="张三"},

new People{name="李四"},

new People{name="张二名"}

};

//重点传一个实现了IComparer接口的类进去,告诉Array.Sort怎么排序

Array.Sort(p, new PeopleCompare());

foreach (var item in p)

{

Console.WriteLine(item.name);

}

Console.ReadKey();

}

}

//People结构体,换成类一样的

public struct People

{

public string name { get; set; }

}

//实现了IComparer接口的类

public class PeopleCompare : IComparer

{

public int Compare(object x, object y)

{

People p1 = (People)x ;

People p2 = (People)y;

return p1.name.CompareTo(p2.name);

}

}

VB.NET 2维数组排序排序和赋值问题

窗体上添加3个标签,1个按钮,在按钮的单击事件里写代码,如下:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim a(,) As Integer = {{5, 6}, {1, 3}, {8, 9}, {72, 1}, {63, 4}}

Dim Temp As Integer

Dim i As Integer

Dim j As Integer

Dim x As Integer

Dim y As Integer

'显示排序前的数据

Label1.Text = "排序前数据:" vbCrLf

For i = 0 To 4

Label1.Text = Label1.Text a(i, 0) " " a(i, 1) vbCrLf

Next

For i = 0 To 3

For j = i + 1 To 4

If a(i, 0) a(j, 0) Then

Temp = a(i, 0)

a(i, 0) = a(j, 0)

a(j, 0) = Temp

Temp = a(i, 1)

a(i, 1) = a(j, 1)

a(j, 1) = Temp

End If

Next

Next

'显示排序前的数据

Label2.Text = "排序后数据:" vbCrLf

For i = 0 To 4

Label2.Text = Label2.Text a(i, 0) " " a(i, 1) vbCrLf

Next

'把第3行元素赋予X,Y

x = a(2, 0)

y = a(2, 1)

'输出X,Y

Label3.Text = "X=" x vbCrLf "Y=" y

End Sub


文章题目:vb.net变量排序,VB 排序
网页路径:http://cqcxhl.com/article/heeioh.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP