Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Swapping array elements
#21
(11-18-2022, 12:36 AM)SMcNeill Wrote:
(11-18-2022, 12:27 AM)bplus Wrote:
Code: (Select All)
a$ = "12345"
swapLetters a$, 3, 5
Print a$
swapLetters a$, 1, 4
Print a$

Sub swapLetters (a$, n, m)
    t$ = Mid$(a$, n, 1)
    Mid$(a$, n, 1) = Mid$(a$, m, 1)
    Mid$(a$, m, 1) = t$
End Sub

You might want to swap to ASC over MID$, due to the speed and performance difference between the two commands.  Letter swapping is usually something which ends up getting called inside loops, and it could really make a difference in how quickly the overall program performs here.  Wink

(11-18-2022, 02:49 PM)mnrvovrfc Wrote:
(11-18-2022, 12:36 AM)SMcNeill Wrote: You might want to swap to ASC over MID$, due to the speed and performance difference between the two commands.
"ASC" might make a good keyword of the day, "my gosh how it's grown" or "not if you went to Dartmouth" or something like that.


It's definitely my keyword of the day.  I'm gonna drag my ASC back to the Wiki.
Reply
#22
Yeah without ASC what's Pete going to joke about?  Big Grin
b = b + ...
Reply
#23
Actually, when Rob started work on what got officially got labeled as _KEYHIT, he was batting around the idea and posted a proposal to name it _HITKEY. That came to an abrupt end when I replied... "Is there and "S" Pat? Besides, it sounded way too Russian.

Pete Big Grin

And now, back to the future!
Reply
#24
I still almost always start use of _keyhit by writing it as _hitkey, before correcting it Big Grin ! Now I think I'll pay more attention!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#25
(11-19-2022, 12:12 AM)PhilOfPerth Wrote: I still almost always start use of _keyhit by writing it as _hitkey, before correcting it Big Grin ! Now I think I'll pay more attention!

Glad to be of help, anyway I can! Big Grin

Pete
Reply




Users browsing this thread: 3 Guest(s)