Quick question about strings
Hi everybody. I'm having a stupid little problem with retrieving strings from a collection. I'm using the Web Browser Control and I'm trying to get all 'formatBlocks' (Heading 1, Heading 2, etc.).
I have working code for this from MSDN, in JavaScript. In a webpage it works like a charm, but when I convert it to VB I only get an empty string in return from the collection.
Check out the web example (IE only). Why, then, doesn't this work in VB?
VB Code:
For i = 1 To objHelper.BlockFormats.Count
MsgBox objHelper.BlockFormats.Item(i)
Next i
It probably just has to do with some string parsing, creating a buffer or something... The Count method returns the same value as in the web example, so I know the collection is correct. Can anyone shine some light on this? :)
Re: Quick question about strings
I get "16" then an error messagebox saying missing fields.
Re: Quick question about strings
With the web example? That's odd. The 16 box is correct, that's the number of format blocks on IE6. But the next messagebox should hold the names of all blocks, in my case (Dutch): Normaal Met opmaak Adres Kop 1 Kop 2 Kop 3 Kop 4 Kop 5 Kop 6 Genummerde lijst Lijst met opsommingstekens Inhoud Menulijst Definitieterm Definitie.
But, anyway, can you think of any reason why a string would appear in a page but not from within VB? :)
Re: Quick question about strings
G'Day Vadar,
1. Your IE example worked OK for me.
2. Possibly the MessageBox is full of preceeding characters and the message dosn't fit the MessageBox.
Does this help:
VB Code:
MsgBox Replace(objHelper.BlockFormats.Item(i), Chr(0), "")
'Or
MsgBox Trim$(objHelper.BlockFormats.Item(i))
Edit: The above assumption generaly relates to a large MessageBox... with noting in it.
If in your case if it's small (ie. would hold one line only), then the problem may be elsewhere.
Bruce.
Re: Quick question about strings
Thanks for your idea, Bruce. The messagebox is small and removing the Chr(0)'s or trimming it didn't help. The Len and LenB function both return 0 on the string. :(
Re: Quick question about strings
Do you need to return .Value or .Text?
Bruce.
Re: Quick question about strings
According to this page just item would do. :(