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


Messages In This Thread
Swapping array elements - by PhilOfPerth - 11-18-2022, 12:06 AM
RE: Swapping array elements - by bplus - 11-18-2022, 12:22 AM
RE: Swapping array elements - by SMcNeill - 11-18-2022, 12:23 AM
RE: Swapping array elements - by bplus - 11-18-2022, 12:27 AM
RE: Swapping array elements - by SMcNeill - 11-18-2022, 12:36 AM
RE: Swapping array elements - by mnrvovrfc - 11-18-2022, 02:49 PM
RE: Swapping array elements - by JRace - 11-18-2022, 04:19 PM
RE: Swapping array elements - by PhilOfPerth - 11-18-2022, 12:46 AM
RE: Swapping array elements - by TerryRitchie - 11-18-2022, 01:09 AM
RE: Swapping array elements - by JRace - 11-18-2022, 01:40 AM
RE: Swapping array elements - by Pete - 11-18-2022, 02:24 AM
RE: Swapping array elements - by SMcNeill - 11-18-2022, 02:41 AM
RE: Swapping array elements - by Pete - 11-18-2022, 02:51 AM
RE: Swapping array elements - by JRace - 11-18-2022, 03:42 AM
RE: Swapping array elements - by Pete - 11-18-2022, 04:15 AM
RE: Swapping array elements - by PhilOfPerth - 11-18-2022, 05:45 AM
RE: Swapping array elements - by Pete - 11-18-2022, 05:57 AM
RE: Swapping array elements - by SMcNeill - 11-18-2022, 12:04 PM
RE: Swapping array elements - by bplus - 11-18-2022, 01:02 PM
RE: Swapping array elements - by mnrvovrfc - 11-18-2022, 02:40 PM
RE: Swapping array elements - by bplus - 11-18-2022, 03:08 PM
RE: Swapping array elements - by bplus - 11-18-2022, 04:21 PM
RE: Swapping array elements - by Pete - 11-18-2022, 06:54 PM
RE: Swapping array elements - by PhilOfPerth - 11-19-2022, 12:12 AM
RE: Swapping array elements - by Pete - 11-19-2022, 12:16 AM



Users browsing this thread: 1 Guest(s)