[Solved] Option VBASupport1 & InStrRev()

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Herb40
Posts: 134
Joined: Thu May 08, 2014 3:35 am

[Solved] Option VBASupport1 & InStrRev()

Post by Herb40 »

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

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
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Option VBASupport1 & InStrRev()

Post by Villeroy »

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 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Herb40
Posts: 134
Joined: Thu May 08, 2014 3:35 am

Re: Option VBASupport1 & InStrRev()

Post by Herb40 »

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

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
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [SOLVED] Option VBASupport1 & InStrRev()

Post by JeJe »

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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: [SOLVED] Option VBASupport1 & InStrRev()

Post by karolus »

Code: Select all

…

sometext.rfind(needle)
…
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply