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
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
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, Western Australia.) 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


Possibly Related Threads…
Thread Author Replies Views Last Post
  getting the number of dimensions in an array on the fly? madscijr 7 723 09-16-2025, 12:34 AM
Last Post: madscijr
  Testing against multiple elements at a time without select case CMR 4 821 04-17-2025, 02:16 AM
Last Post: CMR
  Endian swapping in QB64pe tantalus 8 1,228 03-22-2025, 05:03 PM
Last Post: Petr
  Quesiton on Dimensioning an Array Dimster 5 982 02-06-2024, 01:55 PM
Last Post: Dimster
  ARRAY declaration in GOSUB routines. bartok 19 3,208 02-05-2024, 06:56 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)