AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sorting

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
FrEaK_nIcK



Joined: 02 Oct 2007
Posts: 4

PostPosted: Sat Oct 06, 2007 12:06 am    Post subject: Sorting Reply with quote

Is there a way to sort a number from lowest to highest. Example: 312 gets sorted to 123. Say the code looks like:

Code:
num_1 = 3
num_2 = 2
num_3 = 1
line = %num_1%%num_2%%num_3%


This would print out 321, but I want to sort from lowest to highest as in 123. This doesn't work:

Code:
num_1 = 3
num_2 = 2
num_3 = 1
line = %num_1%%num_2%%num_3%
Sort, line


just for fyi. Anyone got a good way to make this happen? Thanks in advance.
Back to top
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 978

PostPosted: Sat Oct 06, 2007 12:10 am    Post subject: Reply with quote

Use the R option for Sort.

Quote:
R: Sorts in reverse order (alphabetically or numerically depending on the other options).


Also, the you need to use a delimiter, eg:

line = %num_1%`n%num_2%`n%num_3%
Back to top
View user's profile Send private message Visit poster's website
FrEaK_nIcK



Joined: 02 Oct 2007
Posts: 4

PostPosted: Sat Oct 06, 2007 1:02 am    Post subject: Reply with quote

I don't want a delimiter, I need the numbers to be grouped together. And R doesn't work. Maybe I didn't explain myself clearly.

Lets say I have 6 numbers:

    132
    321


each number has a unique call (variable) so it would look like:

    num_1 num_2 num_3
    num_4 num_5 num_6


and lets say I make six 3 digit numbers:

    132, 321, 213, 123, 231, and 312


each number has it's own variable so it would look like this:

Code:
line1a = %num_1%%num_2%%num_3% //132
line1b = %num_4%%num_5%%num_6% //321
line1c = %num_3%%num_6%%num_4% //213
line1d = %num_1%%num_3%%num_2% //123
line1e = %num_5%%num_4%%num_6% //231
line1f = %num_4%%num_6%%num_5% //312


Now what I want to do is sort all possible combinations of the number from lowest to highest which in this example is 123. I hope that helps a bit in the explanation. Smile
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Sat Oct 06, 2007 1:20 am    Post subject: Reply with quote

The R option would give 321

the delimiter is what you need.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
FrEaK_nIcK



Joined: 02 Oct 2007
Posts: 4

PostPosted: Sat Oct 06, 2007 4:11 am    Post subject: Reply with quote

engunneer wrote:
The R option would give 321

the delimiter is what you need.


The R option would have the number going down to 0 which is the opposite of what I want. I need the number to increase from 0. Also the delimiter cause the numbers to break, something I also don't want.

I appreciate the help but I think I'll use C# or PHP to develop this project. I was just testing AHK because a friend pointing me in this direction.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Sat Oct 06, 2007 5:31 am    Post subject: Reply with quote

I somehow missed your previous post.

Code:

line1 = %num_1%%num_2%%num_3% //132
line2 = %num_4%%num_5%%num_6% //321
line3 = %num_3%%num_6%%num_4% //213
line4 = %num_1%%num_3%%num_2% //123
line5 = %num_5%%num_4%%num_6% //231
line6 = %num_4%%num_6%%num_5% //312

Loop, 6
  lines .= line%A_index% . "`n"
StringTrimRight, lines, lines, 1
Sort, lines
Msgbox, %lines%

;if you want them split back out
StringSplit, line, lines, `n, `r
listvars
pause

_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
FrEaK_nIcK



Joined: 02 Oct 2007
Posts: 4

PostPosted: Sat Oct 06, 2007 11:51 am    Post subject: Reply with quote

@engunneer

I was a good idea but it doesn't work either. All it does is sort not number from smallest to largest but doesn't sort the number itself. Thanks though, but I'll program it through C#, I can accomplish what I need there with Array.Sort or something. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group