Is it possible to create an object inside a function

I am working on a class in VBA that encapsulates file loading using MSXML2.XmlHttp.

There are three possibilities for the return value: text, XML, and stream.

Should I create a function for each of them:

 aText=myDownloader.TextSynchronous(URL,formData,dlPost,....)
 aXml.load myDownloader.XmlSynchronous(URL,formData,dlPost,....)

Or I can just return the XmlHttpObject created inside the class and then

 aText=myDownloader.Synchronous(URL,formData,dlPost,.....).ResponseText
 aXML=myDownloader.Synchronous(URL,formData,dlPost,.....).ResponseXML

In the first case, I can set obj to nothing in the class, but I must write several functions that are more or less the same.

In the latter case, I pass in the "garbage collector", but has a more compact class.

Both should work, but which coding style is better?

+3
source share
2 answers

After a long search on the Internet (triggered by a comment by EmmadKareem), I found this:

, Dont do localObject=Nothing - . . , msdn

VBA , ADO, , ( ) , . , / .

: , fdeeling, , , , myDownloader.getSyncDLObj(...) .

, codestyle. , , , . , " : , ,

myDownloader.URL="..."
myDownloader.method=dlSync
myDownloader.download
aText=myDownloader.getXmlHttpObj.ResponseText
myDownloader.freeResources

, lineconsuming

aText=myDownloader.getSyncObj(...).ResponseText

, , . , xmlhttp , . ( ;)

, -

0

, , .

- - Java, , URL-, ( ) , , .

, myDownloader.Synchronous(URL,formData,dlPost,.....) , others . .

0

All Articles