【问题标题】:Mismatched parenthesis不匹配的括号
【发布时间】:2018-03-30 13:00:11
【问题描述】:

我为 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 语句中缺少 Then。有什么想法吗?

【问题讨论】:

  • 这是vba 还是vb.net?? .IndexOf 看起来是 vb.net...
  • 虽然应该是If ("’āēīōū".Indexof(inputstr(i))) > 0 Then,但将括号从> 0 的外部移到内部。
  • @OrenBochman 我认为 VBA 中不存在 .IndexOf。虽然我可能错了。
  • 字符串不是 VBA 中的对象。您不能在字符串文字上调用方法。此外,EndIf 应该是 End If。在 Excel 中,VBA 编辑器会自动插入空格,但无论您使用什么,情况都可能不是这样。
  • @QHarr 这只是意味着您可以创建具有 IndexOf() 作为方法的 some 对象——这并不意味着它是有效的 VBA这个上下文。这里是语法错误。

标签: vba libreoffice


【解决方案1】:

因此,感谢大家的帮助 - 将 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

【讨论】:

  • LibreOffice使用 Microsoft VBA。该语言称为LibreOffice Basic。它也可以称为 StarBasic(旧名称)、OpenOffice Basic 或简称为 Basic。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
  • 2014-07-20
  • 2014-06-17
  • 1970-01-01
相关资源
最近更新 更多