.net - Array.Sort() Doesn't Correctly Order Target Array

Apr 13, 2012

I'm using the following code to read in a highscores file with the score written first and the player's name written to the next line, and then display the top 3 scores or fewer if there aren't 3 scores written to the file. A highscores display should have the scores sorted with the highest first so that's what this program tries to implement.

Array.sort() isn't doing a damn thing. In fact, the program's not even reversing the arrays like it should either. I've tested array.sort() this way with the names and scores arrays given explicitly and it works fine. I thought maybe it was still reading the data as string even though it's declared otherwise but it rounds off decimals when I change the array type to Integer so I'm pretty sure it's not that.

I have no idea why reading the data in from a file changes how it's sorted. My teacher didn't understand what was going on either. Does anyone know what's going on here?

Imports System.IO
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code].....

View 1 Replies


ADVERTISEMENT

Array Sort In Ascending Order

Nov 9, 2009

I am loading an array with data at form load from a text file. I then display that data in a label box. When a user clicks a button I want to sort the data in ascending order. I have a sort code right nowbut it is not correct at all! Another problem i dont know if it will correctly sort becuase the data from the input file is like this: C2 CA D4 S9 HA C4 CQ D3 DA DQ .....AND SO ON AND SO on up to 52 like a card deck, here is my

[Code]...

View 2 Replies

Array.Sort(array) - Specify A Numeral Sort Based On The First Character In The String?

Jan 29, 2009

Sub Sort()
ReDim RollsCC(NumOfPlayers - 1)
For N As Integer = 0 To (NumOfPlayers - 1)[code]....

Here I am creating a temp single dimensional array, merging my 2d array into it, and then attempting to sort it by Rolls(N,1), which is a integer 1-6, Everything seems to be working right with the exception of this.

RollsCC.Sort(RollsCC, 0, 1)

How would one specify a numeral sort based on the first character in the string? im aware that I am switching Rolls(n,1) and Rolls(n,0) information during the sort.

View 5 Replies

Using The Array Type .Sort Function To Sort An Array?

Mar 1, 2010

I am using the Array type .Sort function to sort my array.By default it places the result Array into Ascending order Least to Greatest How do I change that to Descending order Greatest to Least?and How do I change it to Closest to logic? or does that not exist?Assume there is an Array of Numbers 0,13,21,-2,4,5,1.34 and I want them to sort closest to 0 or some other arbitray value; the Output should look similar to:

0,1.34,-2,4,5,13,21

View 19 Replies

Merge Array Of Elements Into Larger Array When Element Order Is Different?

Nov 23, 2010

Assume I have an array myArray1 = { A, B, C, D, E, F, ., T}I have another that contains a subset of the elements of myArray1 but where the order may vary

View 3 Replies

Array.Sort Returns Blank Data When Sorting A Structure Array?

Jun 19, 2009

I'm trying to sort an array based on a structure but whenever I do this, it basically erases all the data in the entire array.I have verified that the array is populated correctly, it is when using array.sort that everything returns blank.

View 6 Replies

Sort An Array Of Doubles Into A Lowest To Highest Array Of The Same Length?

Nov 29, 2011

best way to sort an array of doubles into a lowest to highest array of the same length.

View 10 Replies

C# - .net - Array.Sort And Array.BinarySearch - Culture And Globalization?

Apr 19, 2009

I need to sort an array containing a list of words and search the same using binarysearch. For certain reasons, the word-list must always be sorted using the sorting-rules of "en-US" i.e. American Regional Settings. The code will run under various international Operating Systems and of course this will mean that the word-list will be sorted differently according to the local Regional Settings in use. One problem could arise on a computer/device running with Lithuanian Regional Settings. Why? Because the letter "Y" in most languages is sorted like X-Y-Z while in Lithuanian, the sort order is I-Y-J. This behavior would create havoc to my program.

[Code]...

However, in means of flexibility I believe Guffa's answer is the best one. Why? Let's use another example:In German, the letter Ö is sorted Ö-X-Z while in Swedish and Finnish, the order is X-Z-Ö. In Estonian the sort order is Z-Ö-X. Complicated, isn't it? Guffa's solution will let me force Swedish sorting-oder (changing CultureInfo) on a device running under German Regional settings. Using Comparer.DefaultInvariant with its association to English wouldn't help in this case, probably the letter Ö would end up with O. Therefore my vote will go to Guffa.

View 3 Replies

Getting Elements Into Array Correctly?

May 12, 2009

In this case I'm trying to create a number analysis app. I'm required to declare an array and get the data for the array using ten text boxes. Why, because my instructor said so.

My problem is my event is returning zero. Therefore I believe my code is somehow flawed.

My approach is to create functions that calculate the required metrics. I have only tried to code one function to date. If I can get help making one function work, I will be able to do the others .

Public Class Form1
Dim decScore0, decScore1, decScore2, decScore3, decScore4 As Decimal
Dim decScore5, decScore6, decScore7, decScore8, decScore9 As Decimal

[Code].....

View 3 Replies

Reading A File To Array Correctly

Apr 7, 2009

I have a file C:\level1.txt that has a long row of numbers 0 or 1 to represent a green or red tile drawn.For example here is the txt file I am using right now: [code]This is the EXACT formating of the txt document.The issue on hand is I am unsure if this data gets written to the array correctly, since all my "tiles" are red.Here is the code I wrote: NOTE: Just add a 250 by 250 picturebox1.[code]

View 1 Replies

VS 2010 : Copy This Array To A Temp Array So That The Temp Array Has All The Same Values As The Original Custom Array?

Jun 19, 2011

I have an array of people stored in a custom structure array... how can i copy this array to a temp array so that the temp array has all the same values as the original custom array?

View 4 Replies

Add An Array Sort Inline?

May 6, 2012

strtest() = objFile.ReadToEnd.Trim.Replace(vbCr, "").Split(vbLf).Distinct.ToArray

I created this command from a few examples which reads the text from a StreamReader, Trims, splits on EoL, and returns a unique list. My next command is a sort. I couldnt figure out how to add a sort to this command. Its really not that important but I was curious if there�s an easy way.

Additionally if there's a better way to take a text file into an array or collection I'm all ears.

View 10 Replies

Sort A Multidimensional Array?

Sep 23, 2011

vb.net 2005.

I have profitMarginArray(29,3) <29 is actually a variable, but figured I'd put in a number for the example> and what I need is to retreive elements 0 and 3 sorted on 3 in some way shape or form. The biggest problem is element 3 isn't unique so there could be 5 that have the same value (56.34 for instance) so a sorted list is out.

The current array could look something like

Item1, .34, .75, 54.67
Item2, .32, .75, 57.33
Item3, .29, .5, 42

[Code]....

View 5 Replies

Sort An Array List?

May 27, 2009

I'm trying to sort an arraylist the code is below.

the value.sort() is returning the following error - Failed to compare two elements in the array. At least one object must implement IComparable."[code]...

View 2 Replies

Sort An Array Of Structures In .NET?

Nov 17, 2009

I have an array of structures:
Structure stCar
Dim Name As String

[code].....

View 4 Replies

Sort An Array Structure?

Oct 25, 2011

I have the following array structure defined and am having trouble figuring out how to sort it..

Public svrElements() As svrElementRec
Structure svrElementRec
Public ElemName As String

[Code]....

View 8 Replies

Sort Array Of Points

Mar 23, 2012

how can i sort an array of points...? elements added out of sequence causing wrong shapes with e.graphics.drawlines.

View 12 Replies

Control Array Not In Order As Added

Apr 22, 2011

Why would the controls not be in the order that they were added. I am adding the controls below, the first one to be added is a label, would expect to see it at the top,but it appears below the other linklabels[code]...

View 3 Replies

Reversing Order Of An Array Or String

Jun 29, 2010

Im looking to dynamically populate a Placeholder with data sent from a textbox on the same page, but in reverse order i.e. the latest post goes to the top ratehr than the bottom - kidda like Twitter or Facebook.The code I have so far is below but I keep geeting an error stating that "BC30311: Value of type 'System.Collections.ArrayList' cannot be converted to 'System.Array'." [code]

View 7 Replies

Sorting An Array Into Alphabetical Order?

May 27, 2012

I have the following code that sorts a number of names in alphabetical order(A to Z) Q,

1-How do I change it and make it from Z to A??

2-How do I cut back on the number of loops by placing -1 or whatever, because when I do that I tend to get a messy order

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim student(10)

[Code].....

View 7 Replies

VS 2008 ORDER BY That Does Not Order Correctly?

Jan 14, 2010

I have to order a table following a logical order but I cannot find the appropriate ORDER BY clause.To simplify I have 2 fields field1 and field2

1 record : field1 contains �2� and field2 contains �1�
2 record : field1 contains �1� and field2 contains �2�
3 record : field1 contains �2� and field2 contains �2�

[code].....

View 16 Replies

Seaching An Array - Store In A 1d Array A Set Of 5 Place Names And In 2d Array The Distances Between Places

Jul 28, 2010

I am trying to create the following program Store in a 1d array a set of 5 place names and in a 2d array the distances between the places. Ensure that the order of the places is the same in both arrays. When the names are places are input the distance between them is displayed. If they are not both in the table a suitable message is displayed

Dim town(1 To 5) As String

Dim Dist(1 To 5, 1 To 5) As Integer

Dim First As Integer

[CODE]......................

I think the best way forward is pass a parameter to the function findnumber.

View 1 Replies

Append / Keep The Last 5 Lines Into Some Sort Of An Array?

Nov 9, 2010

I need to capture the last 5 lines from my "write to log" function so I can add it to a debug email. I can't think of an easy way to do this.

I did think I could have an array with 5 items in it, but I'd still need to shuffle the existing items to add the current data.

View 3 Replies

Make Numeric Array Sort?

Dec 11, 2009

ow to sort an array so i've checked d i see only sorting for one-element arrays.is it possible to sort an array with 10 elements per row? or do i need to use a table?also, how to sort an array numerically? all the sort i tried are sorted textually. if my array contains 1 2 & 12 the sort gives me 1 12 2.

View 4 Replies

Sort A Multi-dimensional Array?

Jun 9, 2010

I was looking for a function I need in internet but I didn't find it... I need to sort a multidimensional array(matrix).. for example

Original matrix

1,b,3
2,c,5
3,a,1

I need a function, lets call it magic() xD with 2 arguments, the matrix and which col to sort first...so..the result of magic(originalmatrix,1) could be..

3,a,1
1,b,3
2,c,5

How can I make it ?

View 1 Replies

Sort A Multidimensional Array By The 3rd Column?

Oct 3, 2009

Dim array1(9,2) as String

So basically, 10 rows and 3 columns and say I want to sort them by the values in the 3rd column.

Each row is essentially a record of data and must be kept together.

Now I know that you can't use the array.sort method but would I have to use a bubble sort or something for this?

What's a good way to manipulate the records while still keeping each row linked together somehow.

View 5 Replies

Sort A Two-dimensional String Array?

Dec 3, 2009

My array is declared by

Dim vArray As Object
vArray = oXLSheet.Range("B2:C201").Value
It looks like[code].....

Both dimensions are strings. Obviously the values of 1,1 and 1,2 must stay together.

View 4 Replies

Sort An Array And Remove Duplicates?

Sep 8, 2009

I have a semicolon delimited string (e.g. an EMail Address List returned from a database or a textbox). How do I separate the string into an array, sort, and remove duplicates? The code below works to separate the string and sort the results, but doesn't remove the duplicates. I could probably then loop through the array and copy to a new array to eliminate the duplicates, but there must be a better way to do this using the VB.Net Array, String, and Collections handling classes.

Dim s As
String =
"Test; Test8;Test1;Test2;Test3; Test8;Test4;Test5; Test6"

[code]....

View 2 Replies

Sort An Array Of My Own Class Error

Aug 22, 2009

Sorting an array of my own class error

View 8 Replies

Sort An Array Of Strings By Numerical Value?

Dec 29, 2009

I have nine always changing values that are strings I need to know how to sort them. I have each of the nine values each on it's on panel. I want to make the panels stack highest value to lowest value. Shot of writing every possibility of combinations and let's say that would take forever.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved