Jump to content

Some array sorting troubles...


Recommended Posts

This code is supposed to sort my multi dimensional array into a descending order

for $trp = 1 to 50

$ral = $info[$as][0][0][0]

    For $nomb = $as to 50
    If number($info[$nomb][0][0][0]) > number($ral) Then
    $ral = $info[$nomb][0][0][0]
    $teb = $nomb
    
EndIf


Next
$as = $as + 1

$temps = $info[$tap][0][0][0]
$tempss = $info[$tap][$tap][0][0]
$tempsss = $info[$tap][$tap][$tap][$tap]

$info[$tap][0][0][0] = $info[$teb][0][0][0]
$info[$tap][$tap][0][0] = $info[$teb][$teb][0][0]
$info[$tap][$tap][$tap][$tap] = $info[$teb][$teb][$teb][$teb]

$info[$teb][0][0][0] = $temps
$info[$teb][$teb][0][0] = $tempss
$info[$teb][$teb][$teb][$teb] = $tempsss

$tap = $tap + 1

It works fine, except there is always one unsorted entry remaining. Any ideas on why one part of the array remains unsorted?

Link to comment
Share on other sites

  • Moderators

Did you try starting at 0 instead of 1 for the loop? Are you sure there are only 50 elements and not 51?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I am sure it is neither of those... This is quite annoying though as only one entry is out of place.

even more annoying not being able to have a working example to test with lol.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It is messy as hell, and the variable names often do not make sense... But this was just a script I made to fill in a bit of time, so please bear with me.

The array is populated by a website you will not be able to get to, but I can upload the source if you like. Then you can still use it with fileread.

#include <IE.au3>
#include <Array.au3>
#include <file.au3>

global $info[55][55][55][55]
global $lin
global $tel
global $ran


$tap = 1
$as = 1
$index = 0




$string = _IEBodyReadHTML ( $o_IE )

$source = FileOpen ( "testin.txt", 2 )

FileWrite ( $source, $string )

FileClose ( $source )

$lcount = _FileCountLines( "testin.txt" )

$sourc = FileOpen ( "testin.txt", 0 )



$found = 0





For $number = 1 to $lcount



$unpnair = FileReadLine ( $sourc, $number)


If StringInStr ( $unpnair, "Nairagua </FONT>") <> 0 then


$unair = StringTrimleft ( $unpnair, 22 )

$nag1 = StringTrimright ( $unair, 27 )


If StringInStr ( $nag1, "??") = 0 Then
    
    $index = $index + 1
    
    $nair = StringReplace ( $nag1, ",", "")
    $upname = FileReadLine ( $source, $number - 4)
    $temp = StringSplit ( $upname, ">")
$uname = $temp[4]

    $name = StringTrimright ( $uname, 4 )

$upid = StringTrimLeft ( $upname, 53 )
$uid = StringSplit ( $upid, """")
$id = $uid[1]


If $index >= 50 Then

    $ran = $info[1][0][0][0]
    
    
    For $numb = 1 to 50
    If $info[$numb][0][0][0] < number($ran) Then
    $ran = $info[$numb][0][0][0]
    $tel = $numb
    
EndIf


Next
    FileClose ( $sourc )

If number($nair) > number($ran) Then
    $info[$tel][0][0][0] = $nair
$info[$tel][$tel][0][0] = $name
$info[$tel][$tel][$tel][0] = "Defence"
$info[$tel][$tel][$tel][$tel] = $id

EndIf
Else


$info[$index][0][0][0] = $nair
$info[$index][$index][0][0] = $name
$info[$index][$index][$index][0] = "Defence"
$info[$index][$index][$index][$index] = $id

EndIf
EndIf
EndIf
Next



for $trp = 1 to 50

$ral = $info[$as][0][0][0]

    For $nomb = $as to 50
    If number($info[$nomb][0][0][0]) > number($ral) Then
    $ral = $info[$nomb][0][0][0]
    $teb = $nomb
    
EndIf


Next
$as = $as + 1

$temps = $info[$tap][0][0][0]
$tempss = $info[$tap][$tap][0][0]
$tempsss = $info[$tap][$tap][$tap][$tap]

$info[$tap][0][0][0] = $info[$teb][0][0][0]
$info[$tap][$tap][0][0] = $info[$teb][$teb][0][0]
$info[$tap][$tap][$tap][$tap] = $info[$teb][$teb][$teb][$teb]

$info[$teb][0][0][0] = $temps
$info[$teb][$teb][0][0] = $tempss
$info[$teb][$teb][$teb][$teb] = $tempsss

$tap = $tap + 1

Next




$lis = FileOpen ( "tet.txt", 2 )

For $tr = 1 to 50


FileWrite ( $lis, $info[$tr][0][0][0] & "    " & $info[$tr][$tr][0][0] & "   " & $info[$tr][$tr][$tr][0] & "     " & $info[$tr][$tr][$tr][$tr] & @CRLF)


next

FileClose($lis)
Edited by brodie28
Link to comment
Share on other sites

  • Moderators

May I ask a silly question... are you just trying to get the text between something like: "Nairagua </FONT>"And Whatever?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Yeah... I left out all the IE code... But it sorts through pages doing that. I could have used stringregexp but it is not in the help file. For now, this is fine as it works perfectly.... Any ideas about the array sort?

No ideas about it ... seems over kill to me for the little bit of info it gathers. A suggestion, I made a function called _SRE_BetweenEX()...

Here it is:

Func _SRE_BetweenEX($s_String, $s_Start, $s_End, $iCase = 'i')
    If $iCase <> 'i' Then $iCase = ''
    $a_Array = StringRegExp($s_String, '(?' & $iCase & _
                ':' & $s_Start & ')(.*?)(?' & $iCase & _
                ':' & $s_End & ')', 3)
    If @extended & IsArray($a_Array) Then Return $a_Array
    Return SetError(1, 0, 0)    
EndFunc

_SRE_BetweenEX(FileRead($FileNameLocation), 'Start of Text', 'End Of Text') << this will get the informatin between the start and end of the text.

If the beginning of the text is a special character... such as "<Something" it would look like "\<Something" with the slash. But it's quite efficient and "Quick"!

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

This code is supposed to sort my multi dimensional array into a descending order

for $trp = 1 to 50

$ral = $info[$as][0][0][0]

    For $nomb = $as to 50
    If number($info[$nomb][0][0][0]) > number($ral) Then
    $ral = $info[$nomb][0][0][0]
    $teb = $nomb
    
EndIf
Next
$as = $as + 1

$temps = $info[$tap][0][0][0]
$tempss = $info[$tap][$tap][0][0]
$tempsss = $info[$tap][$tap][$tap][$tap]

$info[$tap][0][0][0] = $info[$teb][0][0][0]
$info[$tap][$tap][0][0] = $info[$teb][$teb][0][0]
$info[$tap][$tap][$tap][$tap] = $info[$teb][$teb][$teb][$teb]

$info[$teb][0][0][0] = $temps
$info[$teb][$teb][0][0] = $tempss
$info[$teb][$teb][$teb][$teb] = $tempsss

$tap = $tap + 1

It works fine, except there is always one unsorted entry remaining. Any ideas on why one part of the array remains unsorted?

Was anything wrong with the answer i wrote in the other threat and the example I gave ?

http://www.autoitscript.com/forum/index.php?showtopic=31639

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Arraysort does not work with a four dimensional array so I had to write my own code for it.

Why do you think you need $array[50][50][50][50] and not $array[50][4] ?

Didn't you have 4 values per record that you needed to sort ?

Or do you have 50*50*50 fields per logical record ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I guess I just did it the other way because I am an idiot ><

I don't think so... but it would have been better to stick with the previous threat since that explained what you wanted...

Just have a look at the example i posted and see if you can get that working for your case...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Thanks alot man. I changed all my arrays and now it sorts perfectly with just the Array sort function.

Wish I had of used this from the beginning, but it was a good learning experience.

As I said: You are not an Idiot... stubborn maybe but not an idiot ..... :P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...