[Solved] Option VBASupport1 & InStrRev()

Creating a macro - Writing a Script - Using the API

[Solved] Option VBASupport1 & InStrRev()

Postby Herb40 » Wed Mar 15, 2017 5:29 pm

I would like to use InStrRev() in a Basic macro, so I added the "Option VBASupport 1" line to my code in order to make InStrRev accessible. But now, the Basic compiler complains about every subroutine call that does not return a value; that is, it expects every subroutine to be a function that returns a value. I have narrowed things down to the following example, in a module by itself. Here, on the ABC() call, the compiler complains "BASIC syntax error; Expected: =." and hilites the ")" at the end of the ABC(). If I change the ABC() call to "i = ABC()" the compiler does not complain.

I have used InStrRev() in other modules without any problems. Any ideas about why this is occurring? Thanks

Code: Select all   Expand viewCollapse view
Option Explicit
Option Compatible
Option VBASupport 1

Sub Main
   ABC()   
End Sub
Last edited by Herb40 on Wed Mar 15, 2017 8:22 pm, edited 1 time in total.
OpenOffice 4.1.3 on Windows 10
Herb40
 
Posts: 134
Joined: Thu May 08, 2014 3:35 am

Re: Option VBASupport1 & InStrRev()

Postby Villeroy » Wed Mar 15, 2017 5:49 pm

Use VBA with Excel and Excel only.
If you want a full featured macro language for OpenOffice, I'd rather recommend Pyhton.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24404
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Option VBASupport1 & InStrRev()

Postby Herb40 » Wed Mar 15, 2017 8:22 pm

Oh, well, I'll just write my own InStrRev(). It won't be used often, won't have to search far, and only has to match one character.

Code: Select all   Expand viewCollapse view
Function InStrRev(s1 as String, s2 as String) as Integer
   ' Search s1 for the single character s2, going from right to left.
   ' Return the position of s2 in s1, or 0 if it is not found.
   Dim i as Integer
   for i = Len(s1) to 1 step -1
      if Mid(s1,i,1) = s2 then
         InStrRev() = i
         Exit Function
      end if
   next i
   InStrRev() = 0
End Function
OpenOffice 4.1.3 on Windows 10
Herb40
 
Posts: 134
Joined: Thu May 08, 2014 3:35 am

Re: [SOLVED] Option VBASupport1 & InStrRev()

Postby JeJe » Wed Mar 15, 2017 8:33 pm

There are some more InstrRev algorithms.

http://www.xbeat.net/vbspeed/c_InStrRev.htm

VB6 is almost identical to OOBasic. Except OOBasic doesn't support assignment for optional declares... so instead of

Functon BlahBlah(a as long, optional b as long = 6)

you'd have to put

Functon BlahBlah(a as long, optional b as long )
if ismissing(b) = true then b= 6

That's usually about the only adaptation you have to make.
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 122
Joined: Wed Mar 09, 2016 2:40 pm

Re: [SOLVED] Option VBASupport1 & InStrRev()

Postby karolus » Wed Mar 15, 2017 8:45 pm

Code: Select all   Expand viewCollapse view


sometext
.rfind(needle)

AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 843
Joined: Sat Jul 02, 2011 9:47 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests