Results 1 to 10 of 10

Thread: SORT BY VALUE

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446
    How can i sort the list box by value, i am using
    List1.AddItem curChar & " " & occurred(Result.text, curChar)

    to display results but wish to display highest value first.

    Many Thanks

    G.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Sub SortNumbers(iArray As Variant)
         
         Dim lLoop1 As Long
         Dim lLoop2 As Long
         Dim lTemp As Long
         
         For lLoop1 = UBound(iArray) To LBound(iArray) Step -1
           For lLoop2 = LBound(iArray) + 1 To lLoop1
    
             If iArray(lLoop2 - 1) > iArray(lLoop2) Then
               lTemp = iArray(lLoop2 - 1)
               iArray(lLoop2 - 1) = iArray(lLoop2)
               iArray(lLoop2) = lTemp
             End If
           Next lLoop2
         Next lLoop1
       End Sub
    '
    'I would load my numbers into and array, sort the array, 
    ' and then load the listbox.
    dim myfile as string
    dim myArr
    dim i as integer
    
    Open myfile for input as #1
      Do while not eof(#1)
        input #1, myNum
        redim preserve myArr(i)
        myArr(i) = myNum
         i = i + 1
       loop
    call SortNumbers(myArr)
    
    For i = lbound(myArr) to ubound(myarr)
       list1.additem myarr(i)
    next i
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Here's the real sort routine thread:
    http://forums.vb-world.net/showthrea...threadid=31965
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    VALUE

    My value is returned in this way
    List1.AddItem curChar & " " & occurred(Result.text, curChar)

    how can i list the value of occurred(result.text,curChar) = ? before list1.additem....

    Cheers

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    you want to sort the returnvalues of occurred? where did you get the occurred function from? I had replied to a thread of certain character occurrance in a string, where you get an array of all ascii chars count. Maybe that would be easier?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    HOW IT WORKS

    The app works as follows: Opne a text file reads the contents, trims and removes chr$(10 and 13's) looks to see how many a's b's c's etc are in the text and reports it to a list box.

    Many Thanks

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    http://forums.vb-world.net/showthrea...threadid=34475
    Go here and get the code i wrote for you, you can use the array ASCII as you want, then make another array with the A-Z and then sort them parallel, go check the sortroutine thread of how to do that. Finally you add the arrays by index to the listbox
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446
    flippin eck ... whats going on here.. isnt it easier to modify the one below..?
    --------------------------------------
    Dim buffer() as byte, x&, ascii&(255)
    Open File for binary as #1
    Get#1,,buffer
    close #1
    For X=0 ubound(buffer)
    ascii(buffer(x))=ascii(buffer(x))+1
    next X
    --------------------------------------


    Private Sub command2_click()
    Dim lne$
    Dim x
    Dim szTemp As String
    Open "C:\mystery\mystery.txt" For Input As #1
    szTemp = Input$(LOF(1), #1)
    szTemp = TrimChar(szTemp, Chr$(10))
    szTemp = TrimChar(szTemp, Chr$(13))
    Result.text = szTemp

    Close #1
    Dim curChar As String
    Dim counter As Integer
    curChar = "a"
    For counter = 1 To 26

    If occurred(Result.text, curChar) != 0 Then
    Debug.Print curChar & " " & occurred(Result.text, curChar)
    List1.AddItem curChar & " " & occurred(Result.text, curChar)
    End If
    curChar = Chr(Asc(curChar) + 1)
    Next counter
    End Sub


  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    No, it's easier to have an array, then you don't need to modify the sort method for the listbox, just make it swap the ASCII codes too.
    Code:
    'now this will only get the text chars in the array:
    Dim buffer() as byte, x&, ascii&(255) 
    Open File for binary as #1 
    Get#1,,buffer 
    close #1 
    For X=0 ubound(buffer) 
      Y=Buffer(x)
       If Y>=65 and Y<=90 then
          ascii(buffer(x-65))=ascii(buffer(x-65))+1 
       End if
    next X 
    'this will create the array for ascii codes
    Dim Asciicode(25) as string
        For X=0 to 25
            asciicode(X)=asciicode(X)=chr(65+X)
        Next X
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    PROBLEMS

    I'm having great problems with this

    Dim buffer() as byte, x&, ascii&(255)
    Open File for binary as #1
    Get#1,,buffer
    close #1
    For X=0 ubound(buffer)
    Y=Buffer(x)
    If Y>=65 and Y<=90 then
    ascii(buffer(x-65))=ascii(buffer(x-65))+1
    End if
    next X
    'this will create the array for ascii codes
    Dim Asciicode(25) as string
    For X=0 to 25
    asciicode(X)=asciicode(X)=chr(65+X)
    Next X


    could you make this work please. my VB is not as sharp as my C

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width