[Gambas-user] Return an array in a function

Caveat Gambas at ...1950...
Sun Aug 8 13:03:03 CEST 2010


Hello again Mato

I don't really get this code.  Why do you set xml8tracks to new
XMLReader, then immediately set it to the return from urlDownload?

Where is urlDownload defined?  What does it return?  Where do you define
xml8tracks? What is smix?  Why is smix defined as String [10, 4]?  Is
that something you know upfront?  In the "name" case, your debug could
be confusing as you print that you're showing smix[id, 0] but you
actually show smix[0, 0].

Please send us enough of the code that we can see what's going on and
help a little more...

My first tentative thought is that the odd, seemingly contradictory
message "I wanted an Array but I got an Array" could be complaining
because it's expecting one type of Array but getting another (so looking
for a one-dimensional String Array but getting a 2-D one, or looking
forRegards,classes a String Array but getting a kind of Variant one or
so... ).

But all that aside... I think that you need to start thinking in a more
object-oriented way, so I've started you off with the changes to
TestProject3 (see attached) to make it more oo.  You'll notice I've
added 3 classes, Response, MixUser, and Mix.  The Response class holds a
Collection of Mixes, the Mix class has a MixUser ... look at the
procedure UseClasses on the Form to start to get an idea of how you'd
need to use the classes.

Create a new instance of the Response class when you get your XML, as
you go through the XML and hit a new mix, create a new Mix object, when
you get to a User, create a new MixUser object... when you hit the end
of a Mix object, add that to the Response object... etc. etc. 

Sorry, I really have to go... let me know if you're still stuck!!

Regards,
Caveat


On Sat, 2010-08-07 at 13:25 -0300, Matías Manuel Grandi wrote:
> Sorry, hi goes again!!!
> -----------------------------------------------------------------
> 
> Hi Guys!w
> I have a problem when calling a function, which receive an xmlreader
> and returns an array.
> The function is geturl and the error gambas give me is "Type Mismatch:
> Wanted an Array, got an Array instead"
> The code is (a bit simplified):
> 
> PUBLIC SUB btnPopular_Click()
>   DIM GetUrlFromXml AS Array
>   xml8tracks = NEW XmlReader
>   xml8tracks = urlDownload("http://8tracks.com/mixes.xml?sort=popular")
>   GetUrlFromXml = GetUrl(xml8tracks)
> END
> 
> PUBLIC FUNCTION GetUrl(reader AS XmlReader) AS Array
>   DIM smix[10, 4] AS String
>   DIM id AS Integer
> 
>   DO WHILE TRUE
>     TRY reader.Read()
>     IF reader.Eof THEN BREAK
>     IF reader.Node.Type = XmlReaderNodeType.Element THEN
>       SELECT CASE reader.Node.Name
>         CASE "name"
>             id = id + 1
>             reader.Read()
>             smix[id, 0] = reader.Node.Value
>             PRINT id & "Nombre: " & smix[0, 0]
>         CASE "restful-url"
>             reader.Read()
>             smix[id, 1] = reader.Node.Value
>             PRINT id & "restful-url: " & smix[id, 1]
>        END SELECT
>     ENDIF
>   LOOP
>  reader.Close()
>  IF ERROR THEN
>    Message.Error("Error when trying to open the Heroes.XML file!")
>    RETURN
>  ENDIF
>  RETURN smix
> END
> 
> Thanks!
> Mato.-
> 
> 
> 2010/8/7 M. Cs. <mohareve at ...626...>
> >
> > It's not readable! Can you resend it without weblinks?
> > ------------------------------------------------------------------------------
> > This SF.net email is sponsored by
> >
> > Make an app they can't live without
> > Enter the BlackBerry Developer Challenge
> > http://p.sf.net/sfu/RIM-dev2dev
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by 
> 
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev 
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestProject3.tar.gz
Type: application/x-compressed-tar
Size: 16006 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20100808/eb130557/attachment.bin>


More information about the User mailing list