Please help me !!!!!

I want to know how to sort a list of records in a text file.

I want to sort them by customer number.

Here's whats in my module

Public CustomerArray() As CustomerRecord

Public Type CustomerRecord
Number As String
Name As String
Address As String
Town As String
PostCode As String
Phone As String
Email As String
PromoInfo As String
End Type


I can add new records, update records, delete records and display records.

I want to be able to display them all. I.E. load the first record into my form thenwhen i press next it will display the next number.

I have searched through loads of websites and i can find plenty of search algorithms but i'm new at this so i dont know how to get my records into them.

I dont want to use bubble sort because every website says its slow.

If you want i'll email you the code for my program.

Recommended Answers

All 8 Replies

Hi ..
Quick sort is the best way than Bubble Sort..

Check this out ..
This is something I found in the internet.. hope this might help u to get it done. Since I’m busy with a new development I’m not willing to modify u’r code at this time..I’m very sorry

Just go through this sample code.. Defiantly it might fulfill u’r goal.


This code is working and hopefully u might able to get it done..
http://www.vb-helper.com/howto_sorted_dir.html


http://www.hobbithouseinc.com/VB/quicksort%20sub.txt

Hi, Thanks. I'm at college just now so i'll read it later. :twisted:

Nope , Like i said i'm a begginer programmer and thats too complicated for me.

I can't believe there are no tutorials on the internet. I've looked at hundreds of web pages about sorting.

It must be easy to sort a few lines of data in a text file. :-|

I have made a tiny program and uploaded it for you (anyone) to see. Sorry to be a pain.

Right, this is my last plea for help. I've made another example of what i want sorted. This time i've included a few customer records and displayed them out in a list box. I've deliberately put the records randomly to show you why i need them in order.

I dont really care what sorting method i use as long as it displays the records by customer number.

Thanks.

Oh and the post i made before this one, the program contains sevral errors. I've fixed them but i can't edit the previous post.

Solution.

I got my dad to help me, and he found a way to do it.

Here is the code.

Private Sub SortCustomers() 'Bubble Sort

Dim Pass As Integer
Dim Compare As Integer
Dim Hold As CustomerRecord
Dim Key, Key2 As Integer 'To convert the customer number from a string to an integer

For Pass = 1 To (UBound(CustomerArray) - 1)
For Compare = 1 To (UBound(CustomerArray) - 1)
Key = CustomerArray(Compare).Number
Key2 = CustomerArray(Compare + 1).Number

If Key > Key2 Then
Hold.Number = CustomerArray(Compare).Number
Hold.Name = CustomerArray(Compare).Name
Hold.CompanyName = CustomerArray(Compare).CompanyName
Hold.Address = CustomerArray(Compare).Address
Hold.Town = CustomerArray(Compare).Town
Hold.PostCode = CustomerArray(Compare).PostCode
Hold.Phone = CustomerArray(Compare).Phone
Hold.Email = CustomerArray(Compare).Email
Hold.PromoInfo = CustomerArray(Compare).PromoInfo

CustomerArray(Compare) = CustomerArray(Compare + 1)
CustomerArray(Compare + 1).Number = Hold.Number
CustomerArray(Compare + 1).Name = Hold.Name
CustomerArray(Compare + 1).CompanyName = Hold.CompanyName
CustomerArray(Compare + 1).Address = Hold.Address
CustomerArray(Compare + 1).Town = Hold.Town
CustomerArray(Compare + 1).PostCode = Hold.PostCode
CustomerArray(Compare + 1).Phone = Hold.Phone
CustomerArray(Compare + 1).Email = Hold.Email
CustomerArray(Compare + 1).PromoInfo = Hold.PromoInfo
End If
Next Compare
Next Pass
End Sub


To call the function type: Call SortCustomers

Yes i know i'm talking to myself but what the hell.

For anyone interested, the above method i showed is bad. Here is a better way.

Call BubbleSort(CustomerArray)  'To call the procedure

Private Sub BubbleSort(theArray() As CustomerRecord)
Dim pass As Integer, compare As Integer
Dim hold As CustomerRecord
Dim CurrentNumber As Integer, NextNumber As Integer
'Customer Number is converted to an integer instead of a string
'otherwise when sorting it only converts the first character

For pass = 1 To (UBound(theArray) - 1)
    For compare = 1 To (UBound(theArray) - 1)
    CurrentNumber = theArray(compare).Number
    NextNumber = theArray(compare + 1).Number
    If CurrentNumber > NextNumber Then
        hold = theArray(compare)
        theArray(compare) = theArray(compare + 1)
        theArray(compare + 1) = hold
    End If
    Next compare
Next pass
End Sub

Also i have attached a program that i'm quite please with. It allows you to add records to an array, Display the array, Save the array to file, Search for records in the array, Goto the next and previous records.

Not bad for a begginer.

Nice program Richard Bishop
i m a biginner and it really helped me a lot
thank you for creating and sharing it.
i hope that u have got a good note for it in ur college ;)
good bye


ps:excuse my english i m french

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.