Page 1 of 1

[Solved] Option VBASupport1 & InStrRev()

Posted: Wed Mar 15, 2017 5:29 pm
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

Re: Option VBASupport1 & InStrRev()

Posted: Wed Mar 15, 2017 5:49 pm
by Villeroy
Use VBA with Excel and Excel only.
If you want a full featured macro language for OpenOffice, I'd rather recommend Pyhton.

Re: Option VBASupport1 & InStrRev()

Posted: Wed Mar 15, 2017 8:22 pm
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

Re: [SOLVED] Option VBASupport1 & InStrRev()

Posted: Wed Mar 15, 2017 8:33 pm
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.

Re: [SOLVED] Option VBASupport1 & InStrRev()

Posted: Wed Mar 15, 2017 8:45 pm
by karolus

Code: Select all

…

sometext.rfind(needle)
…