Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
in list box 1000 showing next to 100..how can i solve that ??
Posted
Updated 20-Feb-14 22:41pm
v2
Comments
Maciej Los 20-Feb-14 17:42pm    
I can see more than 999 items. The limit of number of items is exactly 32767.
thatraja 21-Feb-14 2:19am    
what's the error/problem?

Further to OriginalGriff's solution and the OPs subsequent comments ...

If you set the type for field "id" to adBigInt and make sure that the recordset is sorted on that column (rs.Sort="id") then it should work. Make sure your ListBox Sorted property is set to False (design time only).

The following is a silly little example that I knocked up to prove this method ...

Dim rs As New ADODB.Recordset
rs.Fields.Append "Col1", adBigInt
rs.Fields.Append "Col2", adVarChar, 30
rs.Open
rs.AddNew
rs.Fields("Col1") = 100
rs.Fields("Col2") = "text 100"

rs.AddNew
rs.Fields("Col1") = 101
rs.Fields("Col2") = "text 101"

rs.AddNew
rs.Fields("Col1") = 1
rs.Fields("Col2") = "text 1"

rs.AddNew
rs.Fields("Col1") = 2
rs.Fields("Col2") = "text 2"
rs.AddNew
rs.Fields("Col1") = 1000
rs.Fields("Col2") = "text 1000"
rs.AddNew
rs.Fields("Col1") = 200
rs.Fields("Col2") = "text 200"
rs.Sort = "Col1"
rs.MoveFirst
Do While Not rs.EOF
    Me.List1.AddItem CStr(rs("Col1")) + " " + rs("Col2")
    rs.MoveNext
Loop

results in output
1 text 1
2 text 2
100 text 100
101 text 101
200 text 200
1000 text 1000


[EDIT] OP is using a tool I'm not familiar with but it would seem that changing the data type of the column on the database is not an option (note to other readers - always choose the appropriate data type for the data you are storing). So instead you could try something like this (NB - At my current location I do not have VB6 so the following code is completely untested)
Dim rsSort As New ADODB.Recordset
Set rsSort = rs.Clone(adLockUnspecified)
rsSort.Fields.Append "Sorter", adBigInt
rsSort.Open
rsSort.MoveFirst
Do While Not rsSort.EOF
	rsSort.Fields("Sorter") = val(rs.Fields("id")
Loop
rsSort.Sort="Sorter"
and then use rsSort to populate the ListBox. Remember to ensure that List1.Sorted = False at Design Time and to tidy up new recordset. If you try this method and you get problems try google for "DisconnectedClone"

Alternatively format the id to pad left with zeroes as the ListBox is being populated e.g.
List1.AddItem Format$(Val(rs.Fields("id")), String(5, "0")) & "   " & rs.Fields("name")
which is far neater presentation anyway (means the names will be lined up on the display). If you use this method then remember to set List1.Sorted=True
 
Share this answer
 
v3
Comments
zakariyaptpl 22-Feb-14 2:56am    
sorry ..i am setting the type by visual data manager and i am using access as data base ..so how can i set type as adBigInt these only option for integer .i tried with that and sort the listbox rs.Sort = "id" ..so now i can get 99 before 100 but 101 after 1000 only ..
CHill60 22-Feb-14 7:36am    
I've added some alternatives to my solution
zakariyaptpl 24-Feb-14 15:13pm    
I couldnt get with that ..at last i manualy sorted the data base and made soorted=false ..now its adding one by one ....thanks for your effort and helping mentality ..
Simple: you are using strings, so the sort order is character based: the first difference in characters controls the sort order.
So, it goes:
1
10
11
12
...
19
2
20
21
...
And the same problem occurs with 100 and 1000

Without your code I can't suggest a fix, but you need to look at where you load the ListBox, and use numeric values instead of string.
 
Share this answer
 
Comments
zakariyaptpl 21-Feb-14 6:35am    
List1.Clear
On Error GoTo Errorhandler
If error3021 Then
Exit Sub
Errorhandler:
If Err.Number = 3021 Then
MsgBox "No Membership Available"
End If
Else
rs.MoveFirst
End If
Do While Not rs.EOF
If Check2.Value Then
If DateDiff("m", rs.Fields("expdate"), Date) >= 2 Then
List1.AddItem rs.Fields("name")
End If
Exit Do
ElseIf Combo1.Text = "Member Name" Then
If rs.Fields("name") Like Text1.Text + "*" Then
List1.AddItem rs.Fields("id") & " " & rs.Fields("name")
ElseIf Text1.Text = " " Then
List1.AddItem rs.Fields("id") & " " & rs.Fields("name")
End If

ElseIf Combo1.Text = "Member ID" Then
If rs.Fields("id") Like Text1.Text + "*" Then
List1.AddItem rs.Fields("id") & " " & rs.Fields("name")
ElseIf Text1.Text = " " Then
List1.AddItem rs.Fields("id") & " " & rs.Fields("name")
End If
rs.MoveNext
Loop



its a running software so its difficult to change to numeric now ? any other way to get 101 after 100 intead of 1000??
OriginalGriff 21-Feb-14 6:50am    
Not really - unless you do the sorting manually and convert the numeric portion to a number first.
I'm pretty sure you can do that with VB6 List Boxes, but that is so old that I've forgotten how to do it! :laugh:

Try google: "VB6 list box custom sort" throws up some titles that seem relevant, but it may take a bit of searching to find exactly how you do it.
zakariyaptpl 21-Feb-14 7:08am    
ok ..if iam deleting this field and creating new one which "type" i want to select to get it as numberic ..i tried with long and double but its not working ...

thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900