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")

 RESTlink = "Dynamic link"

 query.Open "GET", RESTlink
 query.send

Could anyone point me in the right direction?

Please note i’ve very basic knowledge of VBA too :stuck_out_tongue:

(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.

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.

The link is: Access2Base

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

Edit:

Please note this does not answer question but will leave for access to document.

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).

@mikekaganski Thanks. I should have known better.

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) :stuck_out_tongue:

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()
Open CRESTlinkBuy For input As #n
    Do While not eof(n)     'execute while not at the end of file (eof)'
        input #n, buyquery 
        l = len(buyquery) 
        Numbers = "0123456789."    'tells to code what i`m seeking (#s including decimals)'
        Value = ""
        For i = 1 To l    'from first character till end of readed file chunk'  

            ActChar = mid(buyquery,i,1)   'mid function read each character'
                 ' 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 :stuck_out_tongue:
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

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

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 :wink:

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()