Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Jan 18, 2018 6:58 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Dictionary key/value pairs into ListBox?
PostPosted: Sat Dec 08, 2012 5:22 am 
Offline
User avatar

Joined: Sun Jul 15, 2007 3:12 am
Posts: 119
Location: Denmark, Europe
Hi all,

I'm creating an app that needs to read a PDF-file and use some if it's metadata like number of pages, author and so on. I'm using MonkeyBreads PDFDocumentMBS.documentAttributes to get that info, but my question is not related to the MBS plug-in.

It's related to the Dictionary that the documentAttributes method creates from the PDF-file. While developing the app, I need to see the values in that Dictionary, so I later can pick the ones I need to use.

Is there a quick-and-dirty way to pour all the key/value pairs from a Dictionary, into rows in a two-column ListBox? I don't even need the keys - I can guess those - if it's easier to just load the values into a one-column ListBox or even a TextArea ... or multiline Label for that matter?

I simply need to see what metadata the documentAttributes method reads from my various PDF's, but I haven't really worked with Dictionaries before, so this will be a great way to learn about them :)

Thank you all in advance, I hope you're all having a great weekend!

_________________
REAL Studio 2012 Pro (Release 1.2) on a 17" MacBook Pro running Mac OS X Mountain Lion.
ATTENTION Danish RS Devs - make sure you join our Facebook group at http://www.facebook.com/groups/danske.realstudio.udviklere/


Top
 Profile  
Reply with quote  
 Post subject: Re: Dictionary key/value pairs into ListBox?
PostPosted: Sat Dec 08, 2012 8:33 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
for each tDictKey As Variant in tDictionary.Keys
ListBox1.AddRow tDictKey // this is the key
ListBox1.Cell(ListBox1.LastIndex, 1) = tDictionary.Value(tDictKey) // this is the value
next

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: Dictionary key/value pairs into ListBox?
PostPosted: Sat Dec 08, 2012 11:55 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
It would faster to grab all the keys/values first.
dim k() as variant = dict.Keys
dim v() as variant = dict.Values
for i as integer = 0 to k.Ubound
lb.AddRow( k( i ), v( i ) )
next

This assumes that all keys and values can be converted to a string.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Dictionary key/value pairs into ListBox?
PostPosted: Sun Dec 09, 2012 3:36 am 
Offline
User avatar

Joined: Sun Jul 15, 2007 3:12 am
Posts: 119
Location: Denmark, Europe
Thank you so much both of you, for your fast and awesome help!

Below is the code I ended up using, and it's working just great - exactly as I hoped it would. The code is placed in a PushButton that let's you load a PDF-file, whose metadata is then displayed in ListBox1.

I ended up using ktekinay's solution, because I could not quite figure out how to adapt your example shaosean ... but that says more about my skill level, than your code :-)

Thank you both again, I learned a lot from this!

Sub Action()

Dim f As FolderItem
f = GetOpenFolderItem(FileTypes1.Pdf)

Dim dict As New PDFDocumentMBS(f)

// This is ktekinay's solution
dim k() as variant = dict.documentAttributes.Keys
dim v() as variant = dict.documentAttributes.Values
for i as integer = 0 to k.Ubound
Listbox1.AddRow( k( i ), v( i ) )
next

End Sub

_________________
REAL Studio 2012 Pro (Release 1.2) on a 17" MacBook Pro running Mac OS X Mountain Lion.
ATTENTION Danish RS Devs - make sure you join our Facebook group at http://www.facebook.com/groups/danske.realstudio.udviklere/


Top
 Profile  
Reply with quote  
 Post subject: Re: Dictionary key/value pairs into ListBox?
PostPosted: Mon Dec 10, 2012 1:18 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Actually, if I knew about ktekinay's solution, I would have posted that too, but I am just learning too :-)

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group