SunQuest
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 22nd, 2003, 08:27 PM
astro86 astro86 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 astro86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Bubble Sorting and Txt File sorting help

ok i did a seach and found nothing i mean nothing so im really sorry if i upset anyone with my question.

Ok here is what i have but ive been asked to take the text file and sort if it isnt organized. and to be honest i have no idea can someone plz exaplain to me the general idea? i was thinking about using Case select for it, all i need is help on sorting the text file and any advise would be very helpfull. this is also for school

PHP Code:
Private Sub cmdCreateReport_Click()
  
Dim currentMonth As StringnewMonth As String
  Dim dayNum 
As Integeraddress As String
  Dim price 
As SinglemonthTotal As Single
  Dim yearTotal 
As SingledoneFlag As Boolean
  
'Display home sales by month
  picReport.Cls
  Open App.Path & "\HOMESALE.TXT" For Input As #1
  currentMonth = ""         '
Name of month being subtotaled
  monthTotal 
0
  yearTotal 
0
  doneFlag 
False              'Flag to indicate end of list
  Do While Not doneFlag
    If Not EOF(1) Then
        Input #1, newMonth, dayNum, address, price
      Else
        doneFlag = True             '
End of list
    
End If
    If (
newMonth <> currentMonth) Or (doneFlagThen  'Control break processing
        If currentMonth <> "" Then                    '
Don't print subtotal before 1st month
            picReport.Print
            picReport.Print Tab(15); "Subtotal for "; currentMonth; ":";
            picReport.Print Tab(38); FormatCurrency(monthTotal)
            picReport.Print
        End If
        currentMonth = newMonth
        monthTotal = 0
    End If
    If Not doneFlag Then
        picReport.Print newMonth;
        picReport.Print Tab(11); FormatNumber(dayNum, 0);
        picReport.Print Tab(18); address;
        picReport.Print Tab(38); FormatCurrency(price)
        yearTotal = yearTotal + price
    End If
    monthTotal = monthTotal + price
  Loop
  Close #1
  picReport.Print "Total for First Quarter: "; FormatCurrency(yearTotal)
End Sub 


Quote:
Text File
"January", 9, "102 Elm Street", 203000
"February", 23, "2 Vista Drive", 145320
"January", 20, "1 Main Street", 315200
"February", 15, "1 Center Street", 100000
"March", 15, "205 Rodeo Circle", 389100
"January", 25, "5 Maple Street", 123450

Last edited by astro86 : September 22nd, 2003 at 11:55 PM.

Reply With Quote
  #2  
Old September 22nd, 2003, 10:58 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,717 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 40 m 34 sec
Reputation Power: 688

Reply With Quote
  #3  
Old September 23rd, 2003, 03:21 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Bubble samplecode:
Private Sub Form_Load()
Dim x

x = Array("hello", "this", "is", "silly", "hello", "this", "is", "silly", "34", "not")

x = BubbleSort(x)

For i = LBound(x) To UBound(x)
MsgBox x(i), , i
Next
End Sub

Private Function BubbleSort(ByVal myArray As Variant) As Variant
Dim p, j, iCount As Integer
Dim x As Variant

'check to see if paramater is an array
If IsArray(myArray) Then
' count how many fields are in the array
iCount = UBound(myArray)

'loop from n to n-1 (first time)
For p = 0 To iCount - 1
'loop from n to n-p-1 (second time)
'after each time through this loop, the pth largest
'element is in the correct position
'p items are in the correct positions, so don't check them again
For j = 0 To iCount - p - 1
' check if current item is greater than the next item
' if so, swap
If myArray(j) > myArray(j + 1) Then
x = myArray(j)
myArray(j) = myArray(j + 1)
myArray(j + 1) = x
End If
Next j
Next p

'return sorted array
BubbleSort = myArray
Else
MsgBox "not an array"
End If
End Function


let's say you have an array that looks like this:

1,9,3,4,2,5,10

bubble sort will do this:

compare 10 and 5
10 > 5 so keep the same

then compare 5 and 2
5 > 2 so keep the same

then compare 2 and 4
2 < 4 so swap resulting in

1,9,3,2,4,5,10

then compare 2 and 3
2 < 3 so swap resulting in

1,9,2,3,4,5,10

then compare 2 and 9
2 < 9 so swap resulting in
1,2,9,3,4,5,10

then compare 2 and 1
2 > 1 so keep the same

keep running through it until the array is sorted

so right now we have 1,2,9,3,4,5,10

when it gets to comparing 3 and 9
3 < 9 so swap resulting in
1,2,3,9,4,5,10

repeat the process until the array is sorted...

U can use it to sort the textfile lines by sequence of the price or another...

Reply With Quote
  #4  
Old September 23rd, 2003, 04:32 PM
astro86 astro86 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 astro86 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thank's CP that was very helpfull im almost done with it ill post it up once im done

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Bubble Sorting and Txt File sorting help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway