# Libreoffice basic equivalent of VBA's "GET" url

Hello everybody, i've (very recently) swapped to open source world (linux & libreoffice 5) and i'm now looking to convert some very simple macros i did with VBA but even after quite a bit of hours passed to search on web i can't find the LO's basic equivalent of the VBA's "get" url fuction.

I need to fetch datas from a sever (the link is dynamical and i've alredy sorted it's creation in LO's basic) that replies with json format text. Now with VBA i used the following:

 Set query = CreateObject("WinHttp.WinHttpRequest.5.1")

query.send


Could anyone point me in the right direction?

Please note i've very basic knowledge of VBA too :P

edit retag close merge delete

(I suspect I didn't understand your question correctly.)
(1) Generally there are no "equivalents" in LibO BASIC as compared to VBA. EIther valid VBA code is running under the Option VBAsupport 1 or it must be redesigned from scratch.
(2) Any already created object actually having a location should support a service giving access to a method MyObject.GetURL, and, (as an abbreviation), to a property MyObject.URL.

( 2017-03-26 14:27:42 +0200 )edit

Sort by » oldest newest most voted

You might check out the Access2Base website to see it that macro library can help you do some VBA conversions.

It has been included in the LO distributions for some time now. I found it helpful converting some of my Access stuff.

more

You can find this in Andrew Pitonyak book- Open Office Macros Explained - chapter 8 - click here for PDF.

Edit:

more

This code isn't strictly "VBA". Actually, it uses WinHttpRequest COM object provided by Windows OS, not by MS Office. So, the code doesn't depend on the specific office suite it runs in, but rather on OS it runs on.

Please notice this important distinction! Neither Office suite, nor programming language provide this functionality in this case; OS does. So, if you continue using the language that doesn't provide this functionality, it's not sensible to expect that LO office suite would provide functionality not specific to office suites.

In this case, two approaches are possible. First is to continue using the OS function in the current way (and in this case, Option VBAsupport 1 is OK, or someone could suggest a way to call CreateObject without this support - I'm not a StarBASIC expert) - but it's Windows-only. Second is to go to a different language (like Python) that itself provides required functionality (via portable libraries) - see e.g. here, and so IMO it's a superior alternative.

@Ratslinger's answer is unfortunately not helpful, because there's no direct GET/POST functionality in the book, aside from one place in ch.12 where POST is used to open document (not data exchange).

more

@Mike Kaganski Thanks. I should have known better.

( 2017-03-27 14:28:17 +0200 )edit

Thx for the infos Mike! i've stumbled into that post yesterday while looking around for a solution, but even if tempting, learning another language (even in very basic form) has been placed as last resource. Guess anyway i will go towards it if can't make it work in couple days. (also the data fetched are in json format and for what i've read around python can handlke it easily) :P

( 2017-03-27 16:12:19 +0200 )edit

Essential to finding your way around the star object mesh are the following:

• mri (or I'm told xray is similar), and

• The OpenOffice Developer's Guide (which if you work at it you can download in a pdf which is much faster than their web site).

It is true that LO Basic and VBA are both Basic, but the objects are very different. That being said, I've gradually been able to find most of the functionality that I need to move from Access to Base. But it hasn't been easy.

You will have to really understand what the VBA code is trying to do first. In my case I wrote it so I had a pretty good idea.

I ran across two things that get URLs that might help you recently:

1) Some code for you to look at referred to here: link text

2) sDocURL = oDoc.getLocation()

more

Thanks to everyone for the replies, will deeply check the links as soon as i can!

@Lupp: yes adding "Option VBAsupport 1" to the macro make it run in LO too, but looking forward to further improvements i want a LO basic native code to avoid eventual not support VBA related trouble later.

Update 4rd april: it's first time i can touch the macro since last post... (RL is killing my freetime) and found some links very useful (expecially pityonak guide is awesome!) and after a bit of reading and googleing i came up with this:

oSimpleFileAccess = com.sun.star.ucb.SimpleFileAccess
n = freefile()
Do While not eof(n)     'execute while not at the end of file (eof)'
Numbers = "0123456789."    'tells to code what im seeking (#s including decimals)'
Value = ""
For i = 1 To l    'from first character till end of readed file chunk'

' of the file chunk (buyquery)...'

If instr(Numbers,ActChar)<>0 Then Value = Value & ActChar   '...and instr'
'function checks if Numbers contains then selected character, '
'if so adds it to Value variable'

position = seek(n) 'return position of cursor in opened file'
seek(n, position)

Next i
Loop
Close #n


Since json text uses commas to separate each data, i wrongly thought i could use the "input" function (that also stops reading at first comma) in conjunction with the "seek" function to move cursor within json and read next chunk of text :P Even if this is a failure i've learned a lot ! I didn't check all the links you gave me, hope to have time for that soon. Thx all again

more

Do yourself an favour, and stop this kind of basic-programming!
python as one of the scripting-languages available from LO, has matured capabilities to handle files in general, to get data from web-urls, and last not least read|write .json`

( 2017-04-04 12:36:41 +0200 )edit

Indeed Python way will be (as soon as i get time XD)! I've just posted code for any noob like me looking for something like this. Thanks again to everyone for trying to help a dumb guy ;)

( 2017-04-04 14:10:27 +0200 )edit