Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How To Get Array Values In Ascending Order.

Dear all ,
I have written the following program which is used to calculate the number of components and their names in an assembly file (solidworks, 3d modelling). But the array used in this program does not give values in ascending order. How to get a array values in ascending order.

For ex : a list box contains "n" No. of valuse, I need to extract all the values in ascending order, as it is listed in the list box.

How to get a array values in ascending order. ?


Sub main()
Dim swApp As Object
Dim SWConfig As SldWorks.Configuration
Dim SWRootComp As SldWorks.component
Dim Children As Variant
Dim SWChild As SldWorks.component
Dim ChildCount As Integer
Dim bOldSetting As Boolean
Dim bRet As Boolean
Dim SWModel As SldWorks.ModelDoc2

Set swApp = Application.SldWorks
Set SWModel = swApp.ActiveDoc
Set SWConfig = SWModel.GetActiveConfiguration
Set SWRootComp = SWConfig.GetRootComponent
Children = SWRootComp.GetChildren
ChildCount = UBound(Children)
'Debug.Print SWRootComp.Name
Debug.Print ChildCount
For i = 0 To ChildCount
Set SWChild = Children(i)

'SwCmp1InsNam = swChild.Name2
'SwCmp1InsNam1 = swChild.Name2
Debug.Print i
Debug.Print SWChild.Name
Next i
End Sub

Actual order


Result I am getting is


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How Can I Sort Array Elements In Ascending Order?
How's everyone doing?

I just wanted to know if anyone can tell me how I can sort the elements of an array in ascending order. Thanks

SQL Order Ascending
Can some one please tell me where to add this part:

into this sql statement:

Thanks in advance

Ascending Order (A-Z)
i am use MS Access... can anyone come out with a vb code to arrange letter from A-Z... pls help.... TKS in advance...

E.g. i have just key in a new Data in the DB... In the combo box, it will have the new Data. But it will not be in the Ascending order...

What The Code For Ascending Order
what the VB code for ascending order.... tks...

What The Code For Ascending Order
what the VB code for ascending order.... tks...

Last 3000 Records In Ascending Order

What can I have our client put in his query, in our VB app, to receive the last 3000 records only? What about the first 3000 records only?

Say the query as it stands now is:

Select * from Data where animal = 'dog'

and I just want the last, or first, 3000 records to show?

Thank you,

Help...How Can I Arrange My Records In Ascending Order?
Hi everyone,

I need your help... How can I arrange my records, in a MsAccess database, in ascending order so that whenever the datagrid displays them, they are in order. and also, whenever I add new records, how can I make vb arrange those records automatically? Hope you can help.


Help... How Can I Arrange My Records In Ascending Order?
Hi everyone,

I need to know how to arrange my records in an MSAccess database in ascending order so that whenever I display those records on a datagrid, they are already arranged. And also everytime I add new records, How can they be arranged automatically?

Thank you..

Ascending/sort Order In Excel
 I need help in arranging the columns in ascending order.

Assuming i got 10 columns and 10 rows.

And i want to arrange in ascending order based on column "C". i,e when we arrange based on col "C" all the other columns in that row also arrange the same way as column "C".


Edited by - chand22 on 5/12/2003 2:22:06 PM

Arranging Values Inside Array In Order
i have an array consisting of the following values, how to arrange the values in descending or ascending order inside the array? or i should do compararison every time i add a value inside the array?


Sorting A Data File In Ascending Order
I need to sort a data file by a 2 character field in ascending order. The only info I could find on sorting is how to sort an array. Does anyone know the command I need to use? Any help would be greatly appreciated.

THANKS!!! 8^)

How To Sort 4 Columns Of Data In Ascending Order?
Name1 Volume1 Name2 Volume2
A 18 B 100
B 59 C 43
D 356 C 248
E 160 B 20
A 215 D 133

How do i sort Volume1 and Volume2 in ascending order?
While sorting Volume1, it should include the values in volume2.
So while sorting Volume1, the alphabets in the name column should also change accordingly.

So the end product should look like this:
Name1 Volume1 Name2 Volume2
A 18 D 133
B 20 E 160
C 43 A 215
B 59 C 248
B 100 D 356

How do i write the code using Visual Basic to sort the data accordingly?
Note: i have 65536 rows in Name1,Volume1 and 65536 rows in Name2,Volume2
Can anyone help? Thanks.

Printing Numbers In Ascending Order (in A String)

My code below choses 10 numbers from 1 to 10 (same number not repeated twice).
The numbers are then listed in my picturebox, but I need to sort them in ASCENDING ORDER.

Any idea how I can do this?

Thanks for any help!

Public First As Integer, Second As Integer, Third As Integer, _
Fourth As Integer, Fifth As Integer, Sixth As Integer, _
Seventh As Integer, Eigth As Integer, Ninth As Integer, _
Tenth As Integer

Private Sub Command1_Click()
Dim Numbers As New Collection, a As Integer
Dim result As New Collection, temp As String


For a = 1 To 10
Numbers.Add a
Next a
Do While Numbers.Count
a = Int(Rnd * Numbers.Count) + 1
result.Add Numbers(a)
Numbers.Remove a

First = result(1)
Second = result(2)
Third = result(3)
Fourth = result(4)
Fifth = result(5)
Sixth = result(6)
Seventh = result(7)
Eigth = result(8)
Ninth = result(9)
Tenth = result(10)

Picture1.Print First & " " & Second & " " & Third & " " & _
Fourth & " " & Fifth & " " & Sixth & " " & _
" " & Seventh & " " & Eigth & " " & Ninth & " " & Tenth
End Sub

Code For Ascending/Descending Order Of Records
I think this is the first time I've ever asked for code i general and specifically. I could use some help on figuring ou a code for ordering data in a database table through VB, sinc the database isn't in order when it comes through a form, but i in order in the actual table.

I say figure out because I would like to come up with the cod without too much help, since it would help me learn. But, an help, even a complete code, I would appreciate it very much.

ADODC Sorting In Ascending Order By A Field
I use VB6 and ADODC control
I want to sort the data in another field(named Stream) in ascending order whose field type is numeric. How and where can I write it? The control is set to the DataGrid. Pleae advise.
My code is like this:

Adodc1.Recordset.Filter = "subject_name='" & Combo1.Text & "' "

Sql Query In Access To Display Ascending With Null Values Rows Following It
I want to select and order records.
The problem is that the order by clause field has null values in it.
Suppose if i give a select query with a order by ascending, i find the nulll valued colums displayed first and then the ascending order works.

how to eradicate this problem in Access query, to display the ascending order values first and then the null valued rows.

The same things works good in Oracle, the ordered values in the first and then the null valued rows.

I need a sql query to do this in Access !!

Order Values
Hi all,
How I can order values in a DBList?

Sorting Values Into Order
i asked this question before, but i only got half of it answered. i have created a program in vb that allows me to display grades for three subjects, after people have entered a mark out of 100. i have then got all of the results to display in a textbox. the only thing i need to do is to sortmy values into order. i do not know how to do this, i am new to vb so if you could put it relativley simply for me. thanks rammstein.

SQL 'ORDER BY' With Specific Values

Is it possible for me to use 'ORDER BY' with specific values? For example, column 'TransType' consits of values 1, 2, 9, 4, 3. I wish to order them by 9, 3, 1, 4, 2.

Is this at all possible?


I Want To Sort From 10 Values(Descending Order)
 guys, i want to sort (Descending order) of 10 values.

Can anyone help me on this.

Order Array

Can I order an array in a alphabetical order???

Thank you


Edit: Per PM, this post is for ASP, so I'm moving it there - Lou

Reversing Order Of An Array

What I am trying to accomplish it reversing the data in an array.

a = 2
b = 0

strSearchText = "2/1/2005"

strQueryType = "date"
strDate = Split(strSearchText, "/")
For i = 0 To (UBound(strDate) + 1)
strDate(b) = strDate(a)
a = a - 1
b = b + 1

Though the value of b is being weird and then it gets back to strDate(b) after doing the first b = b + 1 , strDate(b) has a value of 2, which isnt what I want, I want it to have a value of 1 so that it turns the array around.


2/1/2005 <-- VB Date Format (displayed on a form for users)
2005/2/1 <-- MySQL Date Format so that date queries can be done

What am I doing wrong?

Order Data Within An Array

I have an array with the following data:


I want to arrange this array to be:


I will be glad if I can get an algorithm that solves this problem.

Thanks ..

Reverse The Order Of An Array
i have an array that i would to reverse its order for me to use in summation with another array. can any1 help me with this?

2D Array's To Copy Data In Order

I'm currently writing some VB code that will take some information from a report (dumped down from DB software) and, depending on certain criteria, paste it to a new sheet with the the Excel workbook.

The report lists all deadlines within a pre-defined range, for outstanding payments owed to the company. I need to copy all instances that have a due date PRIOR to today's date. The instances should be pastes as such:-

Due within 0-2 weeks, but a letter requesting payment has not been sent out for
Due within 2 or more weeks, but a letter requesting payment has not been sent out for
Due within 0 or more weeks, but that a letter requesting payment HAS been sent for.

Would a suitable way to execute this code, be to loop through each row the of the report. Use if-statements to search for the date criteria and letter sent boolean being fulfilled and, for each particular scenario, copy each cell in the row at hand into a corresponding row in a 2D array. That way three 2D arrays would be used:-

Array LessThanTwoWeeks [] [] As String
Array MoreThanTwoWeeks [] [] As String
Array RequestAlreadySent [] [] As String

The data in the "LessThanTwoWeeks" array can be pasted into the new sheet first (it takes presedence), followed by "MoreThanTwoWeeks" and "RequestAlreadySent" last of all.

Would all work?



Sort An Array In Alphabetical Order
Hi i was wondering about sorting an Array in alphabetical order.
Is this posible?
eg data

people(1) = Me
people(2) = You
people(3) = Dad
people(4) = Harry
people(5) = John


Sorting An Array In Alphabetical Order
I'm just wondering if anyone knows of a way to quickly sort the contents of an array by alphabetical order.

I have a Type defined, and I have an array of that type, and I want to sort it alphabetically based on one of the elements of that type. For example:

Type DataEntry
Name As Variant
Age As Variant
End Type

Dim PeopleArray(32) As DataEntry

... the array is populated with data, and I want to sort the array in alphabetical order according to the 'Name' field. Is there any easy way to do this?


- Shawn Kubik.

Make Array Be In Order By Number
How can I make an array be in order by value from s to n s is equal to where to start and n is equal to where to stop sorting.. e.g.

Lets say that the array looked something like this


I want the array to be like this


Whats the quickest way of sorting an array like that. and also whats the quickest way of sorting an array from s to n.

Thanx in advance!

Re-order Contents Of A String Array
Assuming I have the following 4-element string array:

MyArray: (0) "Joe", (1) "Ben", (2) "Greg", (3) "Mark"

How would I go about re-ordering the array to get the following?:

MyArray: (0) "Mark", (1) "Ben", (2) "Joe", (3) "Greg"

As you can see, my new array order is strictly arbitrary (not alphabetized). I've thought about ordering my array from the start, but think that this would be just as much work as my array is and must be dynamic - Dim MyArray() As String

Thanks in advance!

Mark Sanchez
SPEC Services, Inc.
Fountain Valley, CA

Sorting Array Into Numerical Order
This is how I sort out my array into descending order

Dim i, j As Integer
Dim dump, dumpIP

i = 0
j = 0

For i = 1 To UBound(IPTally, 2) - 1
For j = 1 To UBound(IPTally, 2) - 1

If IPTally(1, j) < IPTally(1, j + 1) Then

' If one is bigger than the other ..

' Put high number into dump

dump = IPTally(1, j)
dumpIP = IPTally(0, j)

' Swap high number with low number

IPTally(1, j) = IPTally(1, j + 1)
IPTally(0, j) = IPTally(0, j + 1)

' Lower number is the higher number

IPTally(1, j + 1) = dump
IPTally(0, j + 1) = dumpIP

End If

Trouble is, I will get a descending list that looks like the following :


You see the problem? Its not quite in descending order. It would see the the left hand number (is that LSB or MSB?) is taken as being in the decending list. Ie 10 is above 1 but below 2. What am I doing wrong?

Filling A Data Array With Control Array Values
I have a program that collects data and transfers it into an excel database. My collection method is a control array of textboxes. I am trying to collect all the textbox values and transpose the data into a fixed size area in my excel database but i keep getting errors.

Private Sub cmdSubmitDaily_Click()

Worksheets("Daily Data").Range("A9").Value = Date
Worksheets("Daily Data").Range("B9").Value = (cboDay.Text & "-" & cboMonth.Text & "-" & cboYear.Text)
Worksheets("Daily Data").Range("C9").Value = (cboFuelHour.Text & ":" & cboFuelMin.Text)
Worksheets("Daily Data").Range("D9:AN9").Value = txtDailyData????????
End Sub

Any help would be great .

Puting An Array With A Complex Data Type In A Certain Order.
Lets say im using the POINTAPI data type. it has .X and .Y property. now lets say a person adds a random number to 2 textboxs one for X and the other for Y. I want my program to redim and preserve the array to increase how much it stores by 1. Now I want to make all the Y in the array be in numerical order from lowest to highest and X to be in numerical order. at the end I want the array to look something like this:

2 1
3 1
4 1
1 2
2 2
3 3
5 3

and so on. As you can see Y is in order from lowest to highest and X is in order from lowest to highest associated with the Y. so array(2) its X would be 4 and Y would be 1. The array is zero based. and if someone would add another one with x to be 2 and y to be 3 then it would be placed here:

2 1
3 1
4 1
1 2
2 2
2 3
3 3
5 3

The data starts from an array that is not demonsionized. Iam able to start it but after it has been started Errors start arrising.

Thanx in advance!

Critique My Solution To Finding The Sort Order Of An Array
THE PROBLEM: An array of txtBoxes can be dragged and dropped and when the submit button is hit, their order from top to bottom must be logged. The form resizes proportionally, so we can't check spots, we need to figure out the sort order of each

MY SOLUTION: An invisible sorted list box, format the txtBox tops to "00000" with added sixth digit containing the value of the variable of the array. Take the last digit of each item in the list box and put it into the DragLog.

Here's the bit code I tested this idea out with:

Option Explicit
Dim ArrayDepth As Integer
Dim StrArray(8) As Integer
Dim x As Byte
Dim DragLog As String

Private Sub Command1_Click()
Randomize Timer
Erase StrArray()
ArrayDepth = Int(Rnd * 7) + 2 'from 2 to 8 txtBoxes to sort
For x = 1 To ArrayDepth 'create hypothetical array
StrArray(x) = Int(Rnd * 13000) + 3000 'top min. 3000, top max. aprox. 16000

For x = 1 To ArrayDepth 'fill list with array
List1.AddItem Format(StrArray(x), "00000") & x 'adding x as sixth digit
Next 'identifies w/o changing order

DragLog = vbNullString 'convert sorted list to Log
For x = 0 To ArrayDepth - 1
DragLog = DragLog & Right$(List1.List(x), 1)
Text1.Text = DragLog
End Sub

MY QUESTION: Okay, it definately works, but what I really want to know is, if you joined a project and came across this bit of code, what would you think? Is this a goofy way of doing things and could you think of a more straightforward and acceptable way of finding out the sort order of this array?

Order By Date(text Data Type In Access Mdb) Is Not In Proper Order

I am using crystal reports 9 with vb6 and the db is ms-access 2002.
I am just adding the "tbltime" table to display all the fields in the crystal reports.
In the "tbltime" table a column called logdate which is of text datatype in the database.
when i view it in the report the result is not in the proper order but in the database table it is in the ascending order.

logdate in TblTime in dd/mm/yyyy format:


when i view in the reports the logdate field is displaying like this.....


what to do now?


Array Values In Vbe Only
Can you create and refer to array variables only in the VBE (that is, without putting the array variables on a spreadsheet). The below code lists the names of files in a particular directory. I wish to put these fildenames as arrays and then refer to them without having to put their names on a spreadsheet:

sub file()

Directory = "C:My DocumentsTezcanWorkclient"

r = 1

Filename= Dir(Directory)

Do While FileName &lt;&gt; ""

FileName = Dir

If FileName &lt;&gt; "" Then

r = r + 1

End If


Ens sub

Max/Min Values Of Array

Does anyone know how to find the maximum and minimum value of an array? I have an array with numbers (elevation) and I need to know the highest and lowest elevations, using VB6.


Array Values
hi all. can anyone tell me how to get the highest, lowest and average values fron an array please?

Set All Array Values
Is it possible to set all array elements to the same value (not zero) without looping through the entire thing?

e.g. something like MyArray(*) = 126 would be nice

Array Values
How do I get the value of one array to another form to be listed in a text box?
I thought I could do it like this but I can't get it to work

For I = 0 To 7
Str = CmboSize(I)
str2 = CmboLabel(I)
str3 = TxtDesc(I)

TxtIngredients.Text = "str" & vbTab & "str2" & vbTab _
& "str3" & vbCrLf
I = I + 1
If I = 7 Then
End If

Next I

'Code improved by vBulletin Tool (Save as...)


Max Values In A Array

For Generating new id for the table first i use the select query

Quote: CheckID = txtRegion.Text & txtCountry.Text
 select * from ProductSales where ProductId like % '" & CheckID & "'"
 By the above query i will get the Product Sold in a Region and in 1 Country, then with this i need to
add the unique id value (i.e) increment value. How can i do this.


Can i store all the ID's which are like CheckID in a Array and is it possible to check the Max(ArrayName) and increase the value 1 to generate the new ID. How to check the Maximum value in a array.


Edited by - chs on 5/24/2005 12:07:48 AM

Change Order Of Xml Nodes Nased On Order Of List Bx
i have the following xml
<b url="abc1" />
<b url="abc2" />
<b url="abc3" />

this is loaded into a listbox

I can move items in the list up or down and i want the xml to save in the order the list box is in

any ideas?

Calculating Array Values??
I currently have code that finds specific data on one spreadsheet, copies it to certain cells on another so calculations can be done on the data, then copies the calculated values to third spreadsheet. I would like to cut out the middle-man and use VB code to pull the data from the first spreadsheet, automatically perform the necessary calculations, then paste the new values to the third spreadsheet, thereby eliminating the middle spreadsheet.

I am thinking this might be accomplished using arrays. However, I am not knowledgeable enough to know how to perform calculations on array values and assign them to another array.

The source spreadsheet contains data for total calls taken by a specific group and the average availability time for the group. It then also has the total calls for all groups. What I need to do is calculate the weighted average availability for each group. Something like this (don't laugh):

Dim grpCalls() As Integer 'total group calls
Dim grpAvail() As Integer 'average group availability
Dim totalCalls As Integer 'total calls for all groups
Dim wgtAvail() As Integer 'weighted availability

'perform this calculation, but in VB... need help
wgtAvail = (grpCalls/totalCalls)*grpAvail
'code to paste wgtAvail for each group to cells in second spreadsheet.

This is difficult, as there are upwards of 150 groups in the source spreadsheet at times. As I said, I am pretty sure it can be accomplished using arrays. But am not sure how to go about it. Can anyone help?

Passing Array Values
Using Excel VBA and I have an array 'FOO (x,y,z) as string' defined in a module. I'm reading data from a excel file into the array for processing.

I part of the process is to display the array on the screen and allow the user to make updates using a form.

When I reference the array in the form, I get a...procedure not defined error.

I have my index pointers defined as PUBLIC IX, IY, IZ as integers in both areas, VBA will not allow me to make an array PUBLIC. When I define the array in the form the process works...but the form array is blank and I get no usable data from the array.

QUESTION: What is the correct procedure to declare an array (and pointers) that I will use across modules and with Forms; so that the data is accessable.


Array Using Textbox Values
Hi, I'm a bit stumped on this one, how can I convert my textbox values into an array?

'This is not part of the script, just values that may be in my textbox
'TextBox1.Value = "abc 123 xyz"

txtboxval = """" & Replace(TextBox1.Value, " ", """,""") & """"
'removes all the spaces in the textbox and converts them to ","

'if you look at the value of txtboxval in a msgbox, it looks fine for an array, but doesnt seem to work..
msgbox txtboxval

abc = Array(txtboxval)

For i = 0 To 2
MsgBox abc(i)
Next i

Need Help Adding The Values Of An Array
I am very frustrated with this!

I have an application that requires a user to enter a code into a text field
A function in my program then needs to add all the digits to one final value and set a variable equal to that.
The code would be in this format:
(Just a string)

Any suggestion on how i would do this would be greatly appreciated!!!!!!!

Duplicate Values In Array
Hey guys,

Very simple q- whats the best / an easy way of retrieving the indexes of any duplicate values in an array?



Add Values Using Array Into Textbox
Hey all. I'm not very good at VB6 and I have this assignment which I'm stuck on...

Here is how my form looks like:

I'm using an array called SnapGreenScoreBox for the left side and SnapYellowScoreBox for the right side. The only reason I went for Array was to save me the time of creating all those boxes manually.

What I need is to add up all values from those boxes and when I click "Calculate Score" button, all total figures will appear in 2 boxes at the bottom.

Here is how the code would look like if I wasn't using an Array:

Private Sub cmdSnapCalculate_Click()
SnapGreenTotalBox.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub

That's only for 2 text boxes. I have 18 on each side and 3 more forms with the same amount of boxes on each one, so it would have taken me some time. I somehow think that Array will save me all that time...

Am I thinking right? Is that possible to do with an Array?

I'm looking for something like:

Private Sub cmdSnapCalculate_Click()
SnapGreenTotalBox.Text = Sum(SnapGreenScoreBox(17))
End Sub

But that obviously doesn't work...

Thank you for the help in advance...

Getting Cells Values Into An Array
Hi Guys,

I want to copy the value of a range of cells into an array, here is the code.

Dim compare(20) as string
dim i as Integer


For each cell in selection
for i = 0 to 20 step 1
compare(i) = Activecell.value
next i
next cell

There are no errors returned when runing this code, but I can not get the array to output correctly to a listbox. Is this the correct code for what I am trying to achieve?

Thanks in advance

Several Values To An Array In One Statement

I doesn't seem possible to initialise or place more than one value in an array in one statment. I'm looking for something like:

dim a(1 to 3) as integer = {12,34,56}

or at least

dim a(1 to 3) as integer
a = {12,34,56}

But this doesn't seem possible. Is that right?

Copyright 2005-08, All rights reserved