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.
Printable View
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.
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
Here's the real sort routine thread:
http://forums.vb-world.net/showthrea...threadid=31965
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
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?
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
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
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
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
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