ReplaceString() inside a macro : Bug or not ?

Just starting out? Need help? Post your questions and find answers here.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

ReplaceString() inside a macro : Bug or not ?

Post by boddhi »

In your opinion, is the behavior of ReplaceString() placed inside a macro normal or a bug?
I've got some exe (codes too long to post them for test) where the function, into the same macro code, returns a correct result and others where it doesn't.

Code: Select all

Macro Mc_FormatMsg(ArgChaine)
  ReplaceString(ArgChaine,"e","a")
EndMacro

a.s="Text text text"
Debug a
Debug Mc_FormatMsg(a)
Debug a
Debug "------"

b.s="Text text text"
Mc_FormatMsg(b)
Debug b
Debug Mc_FormatMsg(b)
Debug b
Last edited by boddhi on Mon Jan 15, 2024 4:00 am, edited 1 time in total.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

ReplaceString() inside a macro : Bug or not ?

Post by boddhi »

To illustrate my first post, here are 2 examples with two exe created with exactly the same code (the first under PB6.03, the second under PB610b2) running under exactly the same conditions.

Example 1:
Image

Example 2:
Image

Note that the message in the 2nd example is not at all the same as in the 1st (it corresponds to the content of a global variable used in other procedures :shock: ).

The source of the macro and procedure (the ';ResultMSG' lines correspond to tests to understand the source of the problem):

Code: Select all

Macro Mc_FormatageMsg(ArgChaine)
  ReplaceString(ArgChaine,Chr(32),Chr(160),#PB_String_InPlace)
EndMacro
Procedure   Pc_Traitement_BtFPArreter()
  Debug #PB_Compiler_Procedure+"()",5
  Protected.a ResultatMSG
  Protected.s TitreMsg,TexteMsg
  
  If IsThread(*DonneesThread\IDThread)
    Pc_Thread_Pause(*DonneesThread)
    Select *DonneesThread\TypeTraitement
      Case 1:TitreMsg="Analyse de dossiers":TexteMsg="Confirmer l'arrêt de l'analyse du dossier ?"
      Case 2:TitreMsg="Création des galeries":TexteMsg="Confirmer l'arrêt de la création des galeries ?"
    EndSelect
    ;ResultatMSG=MessageRequester(TitreMsg+" 1",TexteMsg,#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
    ;ResultatMSG=MessageRequester(TitreMsg+" 2",UnescapeString(TexteMsg),#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
    ResultatMSG=MessageRequester(TitreMsg+" 3",Mc_FormatageMsg(UnescapeString(TexteMsg)),#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
    ;ResultatMSG=MessageRequester(TitreMsg+" 4",ReplaceString(TexteMsg,Chr(32),Chr(160),#PB_String_InPlace),#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
    Pc_Thread_Reprise(*DonneesThread)
    If ResultatMSG=#PB_MessageRequester_Yes
      Pc_Thread_Arret(*DonneesThread)
    EndIf
  EndIf
EndProcedure
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: ReplaceString() inside a macro : Bug or not ?

Post by breeze4me »

There seems to be a bug in the UnescapeString function.
See:
https://www.purebasic.fr/english/viewtopic.php?t=83341
infratec
Always Here
Always Here
Posts: 7664
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ReplaceString() inside a macro : Bug or not ?

Post by infratec »

Read the help for ReplaceString() with the option #PB_String_InPlace :!:

In this case the return value has to be ignored and it is not valid.
At least in the german help this is documented.

For a test: remove the option #PB_String_InPlace
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: ReplaceString() inside a macro : Bug or not ?

Post by boddhi »

infratec wrote: Mon Jan 15, 2024 7:30 am Read the help for ReplaceString() with the option #PB_String_InPlace :!:
I know that the #PB_String_InPlace option causes ReplaceString() to replace one string with another of exactly the same length, and that it doesn't return any result, which is directly assigned to the variable used.
However, I still don't understand why there are two different behaviors between versions 6.03 (which is ok, but bug ?) and 6.10bX.

I'm going to do it differently to avoid this problem.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ReplaceString() inside a macro : Bug or not ?

Post by jacdelad »

The code in the first post works as expected for me, Windows 10 x64, 6.10 Beta 2. However, I don't understand the question and the problem of the second post...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: ReplaceString() inside a macro : Bug or not ?

Post by boddhi »

jacdelad wrote: However, I don't understand the question and the problem of the second post...
boddhi wrote: here are 2 examples with two exe created with exactly the same code (the first under PB6.03, the second under PB610b2) running under exactly the same conditions.
Note that the message in the 2nd example is not at all the same as in the 1st (it corresponds to the content of a global variable used in other procedures :shock: ).
I should have the same message in example 2 as in example 1, but no...
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply