括号不匹配

时间:2018-03-30 13:00:11

标签: vba libreoffice

我为calc编写了一个函数,用于在包含某些字符的单词之前拆分单元格:

Function sidx(inputstr) As Integer
    Dim newString As String
    newString = ""
    Dim last_space_idx As String
    last_space_idx = 0
    Dim l As Integer
    'l = (inputstr.Length - 1) was ported from js on google sheets
    l = Len(inputstr) - 1
    For i = 0 To l
       If inputstr(i) = " " Then
            last_space_idx = i
       End If
       If ("’aeiou".Indexof( inputstr(i) ) > 0) Then
            sidx = last_space_idx
       End If
    Next i
    sidx = last_space_idx
End Function

由于某种原因,libreoffice在解析这个并且抱怨不匹配的括号或丢失然后在最后的If语句时遇到了问题。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

非常感谢所有人的帮助 - 有很多陷阱将javascript移植到libreoffice vba并且解释器没那么有用......你发现了大部分问题! 字母提取也被打破了,因为我原本认为括号不是真正的问题!

关闭,这里是工作版

Function sidx (inputstr As String) As Integer
    Dim newString as String 
    newString = ""
    Dim last_space_idx as String
    last_space_idx = 0
    Dim l as Integer
    l = Len(inputstr) -1
    For i = 0 to l
       letter = Mid(cstr(inputstr),i+1,1)
       If letter =  " " Then 
            last_space_idx = i
       End If
       'If ("’āēīōū".Indexof(inputstr(i))) > 0 Then
       If InStr("\’āēīōū",letter) > 0 Then 
            sidx = last_space_idx
       End If
    Next i
    sidx = last_space_idx
End Function