窗體上添加3個(gè)標(biāo)簽,1個(gè)按鈕,在按鈕的單擊事件里寫代碼,如下:
10多年的盧龍網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營銷的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整盧龍建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“盧龍網(wǎng)站設(shè)計(jì)”,“盧龍網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
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
'顯示排序前的數(shù)據(jù)
Label1.Text = "排序前數(shù)據(jù):" 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
'顯示排序前的數(shù)據(jù)
Label2.Text = "排序后數(shù)據(jù):" 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
你直接傳一個(gè)數(shù)組進(jìn)去,而且是一個(gè)結(jié)構(gòu)體數(shù)組,array.sort怎么知道根據(jù)結(jié)構(gòu)中的哪一個(gè)屬性進(jìn)行排序?放一個(gè)c#的代碼你看看,VB和C#很相似的
class Program
{
static void Main(string[] args)
{
People[] p = new People[3]
{
new People{name="張三"},
new People{name="李四"},
new People{name="張二名"}
};
//重點(diǎn)傳一個(gè)實(shí)現(xiàn)了IComparer接口的類進(jìn)去,告訴Array.Sort怎么排序
Array.Sort(p, new PeopleCompare());
foreach (var item in p)
{
Console.WriteLine(item.name);
}
Console.ReadKey();
}
}
//People結(jié)構(gòu)體,換成類一樣的
public struct People
{
public string name { get; set; }
}
//實(shí)現(xiàn)了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);
}
}
你這個(gè)是冒泡排序么?從大到小么?
For j = 0 To lstNetworkRisk.Items.Count - 1 應(yīng)該改成
For j = i To lstNetworkRisk.Items.Count - 1
另外盡量不要用GOTO語句。而且完全也可以不用這個(gè)GOTO。
還有不知道你用的什么版本的.net 如果是3.5的完全可以直接用linq。
加了單引號(hào)就是一個(gè)常量字符串了,對(duì)于每一行都是一樣的
像這種放在最前面的字段,order by 1 就可以了