Help with this code - I'm Stuck

S

steve1040

All I have the following code from Ebay's Api sample coding.

Based on a keyword the call will return up to 10 suggested
categories.
With the highest percentage as first item.


How can I modify this code to return only the very top ranked
suggestion (1 record)


Thanks
Steve


***Start Code****


'Display the results
result = "COUNT: " & response.selectSingleNode
("GetSuggestedCategoriesResponse/CategoryCount").Text
result = result & vbCrLf & vbCrLf


Dim n, cn As IXMLDOMNode ' node and childnode
'go through each suggestedcategory
For Each n In response.selectSingleNode
("GetSuggestedCategoriesResponse/SuggestedCategoryArray").childNodes


If n.nodeName = "SuggestedCategory" Then
Dim catName, catID, catItems As String
Dim first As Integer


catID = n.selectSingleNode("Category/
CategoryID").Text
catName = n.selectSingleNode("Category/
CategoryName").Text
catItems = n.selectSingleNode
("PercentItemFound").Text
'output the suggested category
MsgBox n.nodeName
result = result & catName & " (" & catID & ") - "
& catItems & "%" & vbCrLf
End If
Next


lblResponse.Caption = result


*** End Code ***
 
S

Scott M.

This code looks like VB 6, is that what you want? This is a VB.NET
newsgroup.

Anyway, instead of looping through the resulting nodes, just take the first
one:

'Display the results
result = "COUNT: " &
response.selectSingleNode("GetSuggestedCategoriesResponse/CategoryCount").Text
result = result & vbCrLf & vbCrLf

Dim n, cn As IXMLDOMNode ' node and childnode
'go through each suggestedcategory
For Each n In
response.selectSingleNode("GetSuggestedCategoriesResponse/SuggestedCategoryArray").childNodes
If n.nodeName = "SuggestedCategory" Then
Dim catName, catID, catItems As String
Dim first As Integer

catID = n.selectSingleNode("Category/CategoryID").Text
catName =
n.selectSingleNode("Category/CategoryName").Text
catItems = n.selectSingleNode("PercentItemFound").Text

'output the suggested category
MsgBox n.nodeName
result = result & catName & " (" & catID & ") - " &
catItems & "%" & vbCrLf
Exit For ' <----- Once you've got what you want, exit
the loop
End If
Next

lblResponse.Caption = result
 
N

Nobody

Scott M. said:
This code looks like VB 6, is that what you want? This is a VB.NET
newsgroup.

It's dotnet code because of these 2 lines:
Dim n, cn As IXMLDOMNode ' node and childnode
Dim catName, catID, catItems As String

In VB6(classic VB), one has to add "As Type" after each variable, otherwise
it will be assumed "As Variant".
 
T

Tom Shelton

It's dotnet code because of these 2 lines:


In VB6(classic VB), one has to add "As Type" after each variable, otherwise
it will be assumed "As Variant".

And? Lot's of people made that mistake in VB6 all of the time. The fact that
the code is using IXMLDOMNode is a pretty good indication that this is indeed
VB6 code - sersioulsy, there aren't that many people that are going to use the
old COM XMLDom objects in VB.NET...
 
S

Scott M.

It was th vbCrLf's that tipped me off.


Tom Shelton said:
And? Lot's of people made that mistake in VB6 all of the time. The fact
that
the code is using IXMLDOMNode is a pretty good indication that this is
indeed
VB6 code - sersioulsy, there aren't that many people that are going to use
the
old COM XMLDom objects in VB.NET...
 
C

Cor Ligthert[MVP]

Steve,

Probably you got code from samples with COM objects (often called VB6) while
in this newsgroup we instance our own objects from Net classes.

Try to find an equivalent of the code that you use but then for Net. People
who are using still VB6 are often complaining that there are so few VB6
samples while there are so much Net samples so this should be a piece of
cake.

As you are using version 2008 (language version 9) then you can by instance
use this

http://www.microsoft.com/downloads/...53-563a-4204-a4eb-dddcae80b244&displaylang=en

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top