FindMapElement() need a simple pointer example

Just starting out? Need help? Post your questions and find answers here.
normeus
Enthusiast
Enthusiast
Posts: 475
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

FindMapElement() need a simple pointer example

Post by normeus »

The example for FindMapElement() should also show the state of the current map element after the command:

Code: Select all

 NewMap Country.s()

  Country("US") = "United States"
  Country("FR") = "France"
  Country("GE") = "Germany"

  If FindMapElement(Country(), "US")
    Debug "'US' is in the country list."
    Debug country()
  Else
    Debug "'US' is NOT in the country list !"
    Debug Country()  
  EndIf

  If FindMapElement(Country(), "UK")
    Debug "'UK' is in the country list."
  Debug Country()    
  Else
    Debug "'UK' is NOT in the country list !"
  Debug Country()    
  EndIf
    If FindMapElement(Country(), "FR")
    Debug "'FR' is in the country list."
  Debug Country()  
  Else
    Debug "'FR' is NOT in the country list !"
  Debug Country()    
EndIf
My question is about the pointer it returns when it finds an element. Is it a pointer to a pointer? I've never used it. I was wondering if anyone has an example without using a map of structures just a plain simple map.

Code: Select all

*ptr=FindMapElement(Country(), "US")
If *ptr
  ShowMemoryViewer(@*ptr,1000)
EndIf

Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
idle
Always Here
Always Here
Posts: 6031
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: FindMapElement() need a simple pointer example

Post by idle »

it sets the current element to the found element and returns the address of the found element

it returns the pointer and the map is a string so

Code: Select all

*ptr.string =FindMapElement(Country(), "US")
If *ptr
  Debug *ptr\s 
  ShowMemoryViewer(@*ptr\s,1000)
EndIf
normeus
Enthusiast
Enthusiast
Posts: 475
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: FindMapElement() need a simple pointer example

Post by normeus »

Thank you idle!
So this would be an example of the element changing and the usage of the pointer returned by FindMapElement()

Code: Select all

NewMap Country.s()

  Country("US") = "United States"
  Country("FR") = "France"
  Country("GE") = "Germany"

  If FindMapElement(Country(), "US")
    Debug "'US' is in the country list."
    Debug country()
  Else
    Debug "'US' is NOT in the country list !"
    Debug Country()  
  EndIf

  If FindMapElement(Country(), "UK")
    Debug "'UK' is in the country list."
  Debug Country()    
  Else
    Debug "'UK' is NOT in the country list !"
  Debug Country()    
  EndIf
    If FindMapElement(Country(), "FR")
    Debug "'FR' is in the country list."
  Debug Country()  
  Else
    Debug "'FR' is NOT in the country list !"
  Debug Country()    
EndIf

*ptr.string =FindMapElement(Country(), "US")
If *ptr
   Debug *ptr\s
   Debug Country() 
EndIf
I was overthinking the object situation. No more coffee for me.
Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
idle
Always Here
Always Here
Posts: 6031
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: FindMapElement() need a simple pointer example

Post by idle »

normeus wrote: Thu Mar 14, 2024 11:28 pm Thank you idle!
So this would be an example of the element changing and the usage of the pointer returned by FindMapElement()

Code: Select all

NewMap Country.s()

  Country("US") = "United States"
  Country("FR") = "France"
  Country("GE") = "Germany"

  If FindMapElement(Country(), "US")
    Debug "'US' is in the country list."
    Debug country()
  Else
    Debug "'US' is NOT in the country list !"
    Debug Country()  
  EndIf

  If FindMapElement(Country(), "UK")
    Debug "'UK' is in the country list."
  Debug Country()    
  Else
    Debug "'UK' is NOT in the country list !"
  Debug Country()    
  EndIf
    If FindMapElement(Country(), "FR")
    Debug "'FR' is in the country list."
  Debug Country()  
  Else
    Debug "'FR' is NOT in the country list !"
  Debug Country()    
EndIf

*ptr.string =FindMapElement(Country(), "US")
If *ptr
   Debug *ptr\s
   Debug Country() 
EndIf
I was overthinking the object situation. No more coffee for me.
Thank you.
Norm.
I need coffee today or maybe I skip and straight to the wine! :lol:
morosh
Enthusiast
Enthusiast
Posts: 335
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: FindMapElement() need a simple pointer example

Post by morosh »

where the type .string is documented?
PureBasic: Surprisingly simple, diabolically powerful
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FindMapElement() need a simple pointer example

Post by infratec »

.String is a structure like .Integer .Ascii ...

You can find them in ... 'Tools'->'Structure directory' (or similar, since I use the german IDE)
morosh
Enthusiast
Enthusiast
Posts: 335
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: FindMapElement() need a simple pointer example

Post by morosh »

Thank you Infratec
PureBasic: Surprisingly simple, diabolically powerful
Post Reply