something strange is happening, $replace not working - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: something strange is happening, $replace not working (/showthread.php?tid=681) |
something strange is happening, $replace not working - madscijr - 07-25-2022 I could be having a brain misfire, but I could swear the $replace function worked in QB64, why am I getting an illegal string-number conversion on line 9? Code: (Select All) Dim sOld$ RE: something strange is happening, $replace not working - euklides - 07-25-2022 Somebody here gave this function (sorry who was it ???) Function strReplace$ (s$, replace$, new$) 'case sensitive strReplace$ = s$ p = InStr(s$, replace$) While p strReplace$ = Mid$(strReplace$, 1, p - 1) + new$ + Mid$(strReplace$, p + Len(replace$)) p = InStr(p + Len(new$), strReplace$, replace$) Wend End Function RE: something strange is happening, $replace not working - RhoSigma - 07-25-2022 As you don't show us the actual replace function, I can only make the best guess, that you misspelled the function name in the call in line 9. Hence, the compiler doesn't recognize Replace$ as a function and going to think its an un-DIMed array. But as you give strings in the paranthesis, where an array would expect index numbers, you get the "illegal string-number conversion" error. It's one of those errors, where the error doesn't really has a connection to the real mistake, but is just caused by a "symtom" of it. Check the function name, that's most probably the cause of it. (StrReplace$() maybe??) RE: something strange is happening, $replace not working - euklides - 07-25-2022 Have a glance also here https://qb64forum.alephc.xyz/index.php?topic=1986.msg112620#msg112620 https://qb64forum.alephc.xyz/index.php?topic=2858.msg121291#msg121291 RE: something strange is happening, $replace not working - RhoSigma - 07-25-2022 Oh, yes, StrReplace$ is part of the QB64 source (source\utilities\strings.bas). But you must of course $INCLUDE that file in your program to use it. RE: something strange is happening, $replace not working - madscijr - 07-25-2022 (07-25-2022, 03:15 PM)RhoSigma Wrote: Oh, yes, StrReplace$ is part of the QB64 source (source\utilities\strings.bas). But you must of course $INCLUDE that file in your program to use it. Thanks for your reply. So it ISN'T a built in function. I've been using it for so long, I can't remember - my coffee has not kicked in yet, and for some reason searching for the function didn't yield any results so I figured it must be a built in command. When back at my PC later I'll check to see if my notepad++ search settings were maybe stuck on "case sensitive" or something. I definitely got the function from "strings.bas". Thanks again for the sanity check. |