473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how do i arrange the items in the list box in ascending order ?

Expand|Select|Wrap|Line Numbers
  1.  For b = 1 To 5
  2.             a(b) = InputBox("Input Grade")
  3.             ListBox1.Items.Add(a(b))
  4.         Next
  5.         ListBox1.Sorted = True
  6.  
  7.  
i input(98, 100, 93 ,94,96)

then it displays ( 100,93,94,96,98)

but it should be (100,98,96,94,93)

thanks in advance.
Feb 28 '11 #1
2 16224
I think you have to code it somehow. Eg:

Expand|Select|Wrap|Line Numbers
  1. Dim List As New List(Of Integer)
  2.  
  3.         'Add ListBox Items to List
  4.         For Each ListBoxItem In ListBox1.Items
  5.             List.Add(ListBoxItem)
  6.         Next
  7.  
  8.         'Sort the List and Clear the ListBox
  9.         List.Sort()
  10.         ListBox1.Items.Clear()
  11.  
  12.         'Add to ListBox Ascending
  13.         For Each ListItem In List
  14.             ListBox1.Items.Add(ListItem)
  15.         Next
  16.  
  17.         'Add to ListBox Descending
  18.         For i = List.Count - 1 To 0 Step -1
  19.             ListBox1.Items.Add(List(i))
  20.         Next
Mar 2 '11 #2
And when using Kalen's method, don't forget to remove the line:

"ListBox1.Sorted = True

from your code, or you'll be back where you started. Note that the Sorted list box is sorting according to expectation. The ListBox entries are strings (not numbers) and they are being sorted in alphabetic order.

Cheers,
Randy
Mar 5 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: sriram | last post by:
Hi, I have been seing a weird problem with db2look tool in db2 8.2 on Windows 2000 platform. When i spool the DDL using db2look, it spools the DDL in the ascending order of database objects...
2
by: PRadyut | last post by:
In this code i tried to add the elements in ascending order but the output is only 0 1 2 the rest of the elements are not shown. the code...
2
by: Joe | last post by:
Hi, I have an asp.net script that connects to MS Access database and displays data in a table. For some reason I am do not know how to display data say in ascending order of column1. I have...
5
by: Nick Weisser | last post by:
Hi there, I'm not sure how to select the last 3 items in ascending order. This does the trick in descending order: select * from user_menu_main where deleted = 0 and hidden = 0 order by...
6
by: askmatlab | last post by:
Hello all: I would like to insert a number into a linked list in ascending order. Is the following function correct? void insert(Node **node, int v) { Node *tmp = (Node...
3
by: flyaway888 | last post by:
Hey. I know how to sort a list into ascending order by using a function but I need to determine whether or not the list is already sorted. Any ideas?? Thanks
6
by: flyaway888 | last post by:
Hey, I have a function that compares 2 arrays with 6 numbers in each and outputs the matching numbers. I have written a function that does this but I need to output the numbers in ascending order...
1
by: reni | last post by:
haii, plzz help me to arrange the userid in ascending order, the userid contains both numeric and alphanumeric values, i am using vb dot net2005 and sql2000, when i arrange the userid it is coming...
1
by: Orkinman34 | last post by:
Hello, I was wondering if someone could help me out on a question? You are suppose to type in 3 integers, any integers. List them in ascending order and if any of them are duplicate integers...
7
by: kwstriker299 | last post by:
Today in class, my professor posed an interesting question for us to think about before our next class. If you insert items that are in ascending order into a binary search tree, then you will build...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.