Page 1 of 1

Search MAP, List, Array value in runtime

Posted: Mon Jan 26, 2026 3:44 pm
by Kwai chang caine
Hello at all,,

I don't know if it's possible, i have often huge MAP and sometime when i try to debug my codes (So all the time :mrgreen:) i want to know if a value is correctly enter in the MAP, LIST, ARRAY

Code: Select all

ForEach MapStyles()
   
    If MapStyles()\IdStyle = "Kcc"
     Debug "I have found"
     Break
    EndIf
   
   Next
or

Code: Select all

ForEach MapStyles()
   
    If MapKey(MapStyles()) = "Kcc"
     Debug "I have found"
     Break
    EndIf
   
   Next
This code works only if the value is "Kcc", not "KCC", "kcc", not chr(10) + "kcc", etc ...
And when the loop not break, obviously it's that the MapKey or Map/Style not countain the good value
For sure i can all writing in UCASE or LCASE for help a bit, but if the "Kcc" have an extra characte , it's more difficult to know :|

Several time, i want to know why ? and want to search in the MAP but FRED not implemented this function in the Variable viewer :cry:
Just the Loooooooong list of all the MAP, and furthermore...not sorted :shock:

Believe you, it's possible to read the MAP, LIST, ARRAY in a tool in runtime, for searching inside a part of full value ?

Have a good day

Re: Search MAP, List, Array value in runtime

Posted: Mon Jan 26, 2026 5:24 pm
by ChrisR
Kwai chang caine wrote: Mon Jan 26, 2026 3:44 pm and sometime when i try to debug my codes (So all the time :mrgreen:)
:lol:
Kwai chang caine wrote: Mon Jan 26, 2026 3:44 pm but if the "Kcc" have an extra character, it's more difficult to know :|
Don't worry, Kcc, you're unique, there's no extra characters behind :lol:
Kwai chang caine wrote: Mon Jan 26, 2026 3:44 pm Just the Loooooooong list of all the MAP, and furthermore...not sorted :shock:
It should be sorted, in future versions, if Fred merges the PR #342

Re: Search MAP, List, Array value in runtime

Posted: Mon Jan 26, 2026 7:57 pm
by Kwai chang caine
Hello ChrisR :D
ChrisR wrote:Don't worry, Kcc, you're unique, there's no extra characters behind :lol:
Thanks :lol:
It should be sorted, in future versions,
Even if FRED sort the MAP a day (Good news :wink: ), it's when even a good idea i think to can rummage in the memory for reag the MAP
I have do that with an example found in the forum,

Code: Select all

NewMap MapBlackOfKccNumbers.i()
NewMap MapBlackOfKccBlabla.s()

For i = 1 To 10
 MapBlackOfKccNumbers("KccNumber" + Trim(Str(i))) = i
 MapBlackOfKccBlabla("KccBlaBla" + Trim(Str(i))) = "BlaBla" + Trim(Str(i))
Next

For i = 1 To 10
 
 *Ptr = @MapBlackOfKccNumbers("KccNumber" + Trim(Str(i)))
 
 If *Ptr
  Debug PeekI(*Ptr)
 EndIf
 
 *Ptr = @MapBlackOfKccBlabla("KccBlaBla" + Trim(Str(i)))
 
 If *Ptr
  Debug PeekS(PeekI(*Ptr))
 EndIf
 
Next
that works, but the problem is how an external EXE (Tool) can access to the memory of PB :?:
I remember somes codes talking about the shared memory, but i don't know if i'm not going to get my compiler blown up in my face. :mrgreen:

Image

Re: Search MAP, List, Array value in runtime

Posted: Mon Jan 26, 2026 8:26 pm
by Kwai chang caine
While searching through my bag, I saw that you had written some nice code in 2018, about embedding EXE :wink:
viewtopic.php?p=630959#p630959

Re: Search MAP, List, Array value in runtime

Posted: Mon Jan 26, 2026 11:48 pm
by normeus
KCC,
Since it is just for debuging, why not a simple findstring:

Code: Select all

  NewMap Country.s()
  Define x$=""
  Country("KCC") = "web"
  Country("kcc") = "pb"
  Country("kCCCC") = "France"

  ForEach Country()
     x$= MapKey(Country())
     If FindString(x$,"Kcc",1,#PB_String_NoCase)
        Debug x$
     EndIf
  Next

Good luck

Norm.

Re: Search MAP, List, Array value in runtime

Posted: Tue Jan 27, 2026 9:15 am
by Kwai chang caine
Hello Normeus :D

It's justly what i do since a longtime
Adding debugging code in the middle of my real code
Conditions with debug, and when i have found the problem, i delete the debug code

But the problem It's like i have a oyster QI, so i have always more bug than good code :oops: and i lost a big time to add, remove lines of code :oops:
And when i comment lines, there are so much green debug lines, i believe coding in a meadow :mrgreen: and that It's difficult for me to read the real code
Then i lost all my time to debug, writing debug loop, debug condition
There are a main option for me, It's to see value when i fly over the variable 8)
After, if i want see another variable value, the variable viewver is a splendid tool 8)
I see also MAP, LIST, ARRAY inside him, and It's cool too 8)
But for an array It's not difficult to found a value, because there are index, list are in the order than i have enter it
But MAP that i love, are really impossible to read if you are several thousand of elements not sorted :cry:

I wondering how the viewver do, for catch the MAP surely because it is inside PB
Because the viewer have the value of map, array, etc
But perhaps it ask a question to compiler ?

Re: Search MAP, List, Array value in runtime

Posted: Fri Jan 30, 2026 10:18 pm
by Kwai chang caine
So don't ask me how, but I found something amazing, after wasting my time clicking everywhere without knowing why. :shock:
I searched the source code of the PB editor and the entire forum, and nothing :|
DOBRO once asked the same question, and FRED's answer was that the protocol wasn't public. :?
viewtopic.php?t=56610&hilit=Communication
But me...I found a way to read its contents without upsetting FRED. :mrgreen:

i want to thanks a lot INFRATEC+NICO+AI for help me in this galley 8)
Read console [INFRATEC]viewtopic.php?p=560779#p560779
How use SendIntput_() [NICO]https://www.purebasic.fr/french/viewtop ... 19#p171419
Reduce command SendInput CTRL+C[AI]
I think everyone probably knows what I found by chance, but I'm amazed by my discovery. :shock:
I was trying to ask the debugger to give me its variables, but when I talked to the AI, he told me I wasn't looking in the right place, that the debugger had finished its work, it had created a modified executable with a ton of stuff in it :idea: , and that it was the keyholder (well, not exactly his exact words :mrgreen: ).
So I tackled this famous executable and discovered this.

Create a folder everywhere, and put this 2 codes inside, like this only this 2 files is here, to avoid another "PureBasic_Compilation0.exe" :wink:
Obviously your PB must be set for creating the temporary executable beside of the "source.pb"

Run this code first

Code: Select all

Global NewMap MapKccExample()
MapKccExample("MAP KCC 1") = 0
MapKccExample("MAP KCC 2") = 0
MapKccExample("MAP KCC 3") = 0
MapKccExample("MAP KCC 4") = 0
MapKccExample("MAP KCC 5") = 0
MapKccExample("MAP KCC 6") = 0
MapKccExample("MAP KCC 7") = 0

a$ = "VARIABLE KCC 1"
b$ = "VARIABLE KCC 2"

Dim ArrayOfKcc.s(2)
ArrayOfKcc(1) = "Element of KCC array 1"
ArrayOfKcc(2) = "Element of KCC array 2"

IdFenetre = OpenWindow(#PB_Any, x, y, 800, 400, "Try to read my variables", #PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

Repeat  
  
 Evenement = WaitWindowEvent()
 EvenementGadget = EventGadget()
 EvenementType = EventType()
  
 If Evenement = #PB_Event_Gadget
   
 EndIf
   
Until Evenement = #PB_Event_CloseWindow
A "PureBasic_Compilation0.exe" have be created in the folder 8)
Secondly run this code

Code: Select all

Structure RunProgramExtendedStructure
 ProgramID.i
 WindowHandle.i
EndStructure

Debug "=============================================="
Debug " PureBasic Console Debugger"
Debug "=============================================="
Debug ""
Debug "Type 'help' for command options."
Debug "DEBUGGER:: help"
Debug "Type 'help <command>' for more detailed help."
Debug ""
Debug "arrayshow   print parts of arrays"
Debug "mapshow     print parts of maps"
Debug "arrays      print all array names"
Debug "memory      print a memory dump"
Debug "breakclear  remove all breakpoints"
Debug "memoryraw   output raw memory"
Debug "breakpoints list all breakpoints"
Debug "saveconfig  saves debugger settings"
Debug "breakremove remove a breakpoint"
Debug "set         set a variable value"
Debug "breakset    set a breakpoint"
Debug "shell       open a command shell"
Debug "databreak   set a data breakpoint"
Debug "show        show Array, List Or Map"
Debug "dec         decimal output"
Debug "stack       print a stack trace"
Debug "debug       print variable value"
Debug "step        execute one code step"
Debug "exit        end the program"
Debug "redirect    redirect debugger output"
Debug "errors      set error action"
Debug "report      print a detailed report"
Debug "file        redirect console command"
Debug "registers   print processor registers"
Debug "files       list included sources"
Debug "registerset set a register value"
Debug "help        print available commands"
Debug "run         continue the program"
Debug "hex         hexadecimal output"
Debug "variables   print variables"
Debug "history     print procedure history"
Debug "warnings    set warning action"
Debug "line        print current line & file"
Debug "linkedlists print all linkedlist names"
Debug "listshow    print parts of linkedlists"
Debug "maps        print all map names" + #CRLF$ + #CRLF$

Procedure SendCommand(Command.s)
 
 hwndConsole =  FindWindow_(0,"PureBasic Console Debugger (press Ctrl+C to stop program)")
 
 For i = 1 To Len(Command)
  
  Carac$ = Mid(Command, i,1)
  SendMessage_(hwndConsole, #WM_CHAR, Asc(Carac$), 0)
  Delay(10)
  
 Next 
 
 Delay(10)
 SendMessage_(hwndConsole, #WM_CHAR, 13, 0)
 SendMessage_(hwndConsole, #WM_CHAR, 10, 0)
 
EndProcedure

Procedure Command(*Value)
 
 MessageRequester("Read variables", "Ask for the array") 
 SendCommand("arrayshow ArrayOfKcc")
 MessageRequester("Read variables", "Ask for the MAP") 
 SendCommand("arrayshow ArrayOfKcc")
 MessageRequester("Read variables", "Ask for the variable a$") 
 SendCommand("debug a$") 
 
 Repeat
  
  Command$ = InputRequester("Talk to runtime", "What you want to know ?", "")
  SendCommand(Command$)
  
 ForEver 
 
EndProcedure

Procedure.i EnumWindowsCallBack(hwnd.i, param.l)
 
 Protected Result.i, PID.l, Length.i, *RunProgramExtended.RunProgramExtendedStructure
 
 Result = #True
 *RunProgramExtended = param
 
 If GetWindowThreadProcessId_(hwnd, @PID)
  
  If PID = *RunProgramExtended\ProgramID
   *RunProgramExtended\WindowHandle = hwnd
   Result = #False
  EndIf
  
 EndIf
 
 ProcedureReturn Result
 
EndProcedure

Define Compiler.i, *Buffer, Length.i, Title$, NewTitle$
Define RunProgramExtended.RunProgramExtendedStructure

Compiler = RunProgram("PureBasic_Compilation0.exe", "", GetPathPart(ProgramFilename()), #PB_Program_Open|#PB_Program_Read)
Delay(300)

If Compiler
 
 CreateThread(@Command(), 0)
 *Buffer = AllocateMemory(1000, #PB_Memory_NoClear)
 
 If *Buffer
  
  hwndConsole = FindWindow_(0,"PureBasic Console Debugger (press Ctrl+C to stop program)")
  SetForegroundWindow_(hwndConsole)
  
  #INPUT_KEYBOARD = 1
  #KEYEVENTF_KEYUP = 2
  #VK_CONTROL = $11
  #VK_C = $43
  
  Dim IN.INPUT(3)
  
  in(0)\type = #INPUT_KEYBOARD : in(0)\ki\wVk = #VK_CONTROL
  in(1)\type = #INPUT_KEYBOARD : in(1)\ki\wVk = #VK_C
  in(2)\type = #INPUT_KEYBOARD : in(2)\ki\wVk = #VK_C : in(2)\ki\dwFlags = #KEYEVENTF_KEYUP
  in(3)\type = #INPUT_KEYBOARD : in(3)\ki\wVk = #VK_CONTROL : in(3)\ki\dwFlags = #KEYEVENTF_KEYUP
  
  SendInput_(4, @in(0), SizeOf(INPUT))
  RunProgramExtended\ProgramID = ProgramID(Compiler)
  Delay(500)
  
  While ProgramRunning(Compiler)
   
   If RunProgramExtended\WindowHandle = 0
    
    EnumWindows_(@EnumWindowsCallBack(), @RunProgramExtended)
    
   Else
    
    Length = GetWindowText_(RunProgramExtended\WindowHandle, *Buffer, 1000)
    
    If Length
     
     NewTitle$ = PeekS(*Buffer, Length)
     
     If Title$ <> NewTitle$
      
      Title$ = NewTitle$
      Debug "Title: " + Title$
      
     EndIf
     
    EndIf
    
   EndIf
   
   Length = AvailableProgramOutput(Compiler)
   
   If Length
    
    If ReadProgramData(Compiler,*Buffer, Length)
     Debug PeekS(*Buffer, Length, #PB_UTF8|#PB_ByteLength) + #CRLF$
    EndIf
    
   EndIf
   
  Wend
  
  FreeMemory(*Buffer)
  
 EndIf
 
 CloseProgram(Compiler) ; Close the connection to the program
 
EndIf
At the begining three msgbox ask for reading MAP/Array/a$ in the RUNTIME "MyProgram.exe"
But after you can enter all the commands that FRED have created

ATTENTION !!!, like it's KCC the creator, this code is really buggy (It's KCC quality :mrgreen: )
But it's mainly for show the method :wink:
Then if a MASTER, want help me to improve it, he is WELCOME :mrgreen:

It just goes to show, even donkeys can find amazing things with Purebasic.
That's what we call the ...
"FRED" effect.
8)

Re: Search MAP, List, Array value in runtime

Posted: Sat Jan 31, 2026 12:12 pm
by boddhi
Hello KCC,

param.i instead of param.l otherwise memory address error on x64 systems.

Code: Select all

Procedure.i EnumWindowsCallBack(hwnd.i,param.i)

Re: Search MAP, List, Array value in runtime

Posted: Sat Jan 31, 2026 3:54 pm
by SMaag
why don't you transfer your Map Keys into a List, then you can sort it.

If you want to search Kcc with additional character like Kccc, you can use phonetic functions like soundex.

If you put your individual debug functions in a seperate module, it do not blow up your functional code that much.

Re: Search MAP, List, Array value in runtime

Posted: Sat Jan 31, 2026 5:20 pm
by Kwai chang caine
boddhi wrote: Sat Jan 31, 2026 12:12 pm Hello KCC,
param.i instead of param.l otherwise memory address error on x64 systems.
Thanks for the tips, i modify that immediately 8)
This part is INFRATEC code, it's surely because his code is old, but i love and use it since several years 8)
I believe FRED change a day of L to I, but i'm not sure :wink:

@SMAAG
Thanks a lot 8) for you interest to my poor case :cry:
In fact, i play with a really too big toy for me :|

Image

And not really understand all what i write :mrgreen:
I'm already also surprised to have this result :shock:
Never forget KCC not have your high level that I admire so much in your codes :wink:

It's the first method i have found, perhaps the're another and more simple method for read value in runtime :?:
In fact, my goal is to read it without adding something i my code :idea:

This morning, i have found a second method 8)
I finally understood how the IDE's source code works, I can't believe it myself :shock: , i'm the most happy computer dunce of the world :D

Image

I've tried at least 10 times, since Fred was kind enough to open it up, without ever succeeding. :oops:

And I've almost finished coding this additional function. :shock:

Image

By the way, the TEAM code is truly splendid, structured, perfect, quite the opposite of mine :mrgreen:
Perhaps except for the indentations and formatting, which isn't mine. :|
I've fallen even more in love with Fred and his team. 8)

I sometimes wonder... if people like you, ...some others on the forum, and of course the team, realize the value they have in the eyes of
Image
"ham and butter" types like me.... :oops: