如何使用VB中的第一项对列表框行进行排序? [英] How to sort listbox rows using first item in VB?

查看:581
本文介绍了如何使用VB中的第一项对列表框行进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在保存库存信息,例如产品ID,产品名称,价格和数量。我希望能够使用冒泡排序按产品ID排序。

我首先将数据从相关文本文件加载到列表框中然后排序。

我尝试使用下面的那个,但它似乎没有工作。谢谢你提前。

未声明StringBubbleSort



我尝试过:



I am saving stock info such as product ID,Product name,price and quantity. I want to be able to sort by product ID using a bubble sort.
I am first loading the data into the list box from the relevant text file and then sorting.
I have tried using the one below but it doesn't not seem to work.Thanks in advance.
"StringBubbleSort not declared"

What I have tried:

Dim STUDENT_FILE As String = ("C:\Users\Windows 7 User\Desktop\Stock.txt")
        Dim objReader As New System.IO.StreamReader(STUDENT_FILE)

        Dim strDataline As String 'Data line
        Dim strArr(2) As String ' Array for bits of line
        Dim blfound As Boolean
        ListBox1.Items.Clear()

        Do While objReader.Peek() <> -1 'read the file till the end.
            strDataline = (objReader.ReadLine()) ' read line and store into variable
            strArr = strDataline.Split(",") 'Split line and put into array
            ListBox1.Items.Add(strDataline)
            blfound = True

        Loop
        MsgBox("Stock data has been loaded")
        objReader.Close()
        If blfound = False Then MsgBox("stock data has not been found")

         'Bubble sort'
        Dim arr(ListBox1.Items.Count - 1) As String
        Dim i As Integer

        For i As Integer = 0 To arr.Length - 1


            arr(i) = CStr(ListBox1.Items(i))
        Next
        For i As Integer = 0 To arr.Length - 1
            For j As Integer = 0 To arr.Length - 2 - i
                If String.Compare(arr(j), arr(j + 1)) > 0 Then
                    Dim temp As String = arr(j)
                    arr(j) = arr(i)
                    arr(i) = temp
                End If
            Next
        Next
        StringBubbleSort(arr)
        ListBox1.Items.AddRange(arr)

推荐答案

StringBubbleSort(arr)



您还没有在任何地方定义该子程序。


You have not defined that subroutine anywhere.


这篇关于如何使用VB中的第一项对列表框行进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆