Jump to content
Macro Express Forums

Sorting text strings in alphabetical order


Recommended Posts

Few month ago I accidently used this IF command in a macro:

 

If variable %T[1]% is greater than %T[2]%

do something

End if

 

I couldn't figure out what was happening with the macro untill I saw the typo (originally I was supposed to compare %N[1]% and %N[2]%). I didn't know I could compare text strings that way. I figured, macro was checking which variable was longer. I tried it with few random words and my theory proved right. I was like 'Cool, now I will be able to skip "variable set integer to the length of text variable" by simply using the string itself to compare.

 

Today I tried this "trick" and it wouldn't work. Macro claimed that %T[1]%="john" is greater than "%T[2]%="africa". That left me stunned for 7 minutes.

Then I realized macro wasn't comparing the variables' length at all. It was checking which of the two variables comes first in the alphabetical order. Which by the way is very handy.

 

I wish there were some info in ME Help file about this particular use of IF commands. Cause that's where I turn first if I want to see possible uses of a command.

 

It just sounds so odd, that "b" is greater than "a", and "a" is less than "b" (apart from ie.: if "africa" contains "a" or if "africa" equals "africa".) To me at least.

 

That's it. No problem to solve, just felt like sharing :) Maybe somebody finds this useful. I searched the forum for posts concerning the topic and didn't found any info on this usage of IF command. I hope it's not because it's such common knowledge that is not worth mentioning, and I was the only one who didn't know about it :D

Link to comment
Share on other sites

Mehhh... Pretty common knowledge ;-) And as it is with a lot of things in the programming world it's just expected that one needs to do little experiments now and then. EG is "1" greater than or less than "a" or "A". In some systems "1" is less than "A" which is less than "a" because of their ASCII values 0x31, 0x41, and 0x61. BTW it's handy to remember all the major sets start with 1.

 

I do encourage you to make suggestions to ISS directly. In my experience they're very responsive to suggestion to add information to help files.

 

 

Link to comment
Share on other sites

Mehhh... Pretty common knowledge ;-) And as it is with a lot of things in the programming world it's just expected that one needs to do little experiments now and then.

I do agree about the experimenting part. It's just sometimes, like in this case, for a person who hasn't ever programmed anything in C or ANY other language (except adding two integers in Pascal 10 years ago...unsuccessfully...), and doesn't know how the whole magic happens, it may be difficult to even allow consideration of an experiment. This last sentence probably doesn't make sense at first, just Repeat Until it does :). Even for a non-programmer most ME commands are pretty strightforward and unambiguous, however the usage of IF command mentioned in the OP was not.

 

Pretty much all my knowledge in ME programming comes from experimenting and help files. From capturing and playing back macros about 3 years ago, to now, writing advanced macros from the scratch. Few times I even happened to provide a throughout solution for my friends to their problems with ME*. Nothing unusual, but some of them are univeristy grade programmers and you wouldn't expect a self-taught rookie like myself to solve their programming problems (but by no means I will claim I am a better programmer/coder than they are!). I'm just an every-day ME addict. One of many.

 

*FYI

The problems mainly concerned screen reading in games, no text selection posssible. They write advanced programs in C++ on daily basis, but they simply couldn't figure out how to read whole words off the screen.

Screen reading and conditioning the results is what I do for pleasure.

 

I do encourage you to make suggestions to ISS directly. In my experience they're very responsive to suggestion to add information to help files.

I will suggest addidng the info to them.

 

 

 

 

Thanks for you comment on this Cory. I feel enlightened now :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...