VBA ByRef参数类型将字符串不匹配到字符串中

时间:2016-05-03 07:50:18

标签: vba excel-vba excel

这是我尝试运行的代码,我找不到它有什么问题,为什么我不能用String参数将String传递给函数?它一直告诉我ByRef Argument Type Mismatch。

一直在尝试其他答案,我仍然找不到解决方案。希望可以在这里得到一些帮助。

主要程序:

Sub Macro()
Dim test As String
Dim arr() As String
Dim CompiledText As String
Dim temporary As String
Dim i As Long
Dim ab As String
Dim marker As Long
market = 0
test = Range("A1").Value
arr = Split(test, Chr(10))
test = ""
CompiledText = ""
For i = 0 To UBound(arr)
If (Left(arr(i), 1) <> "#") Then
    If (Trim(test) <> "") Then
        test = test & vbCrLf
    End If
    test = test & arr(i)
    If (InStr(arr(i), "ATTRS(") <> 0) Then
        If (CompiledText <> "") Then
            CompiledText = CompiledText & vbCrLf
        End If
        temporary = arr(i)
        CompiledText = CompiledText & GrabATTRS(CStr(temporary))
    ElseIf (InStr(arr(i), "ATTRN(") <> 0) Then
        If (CompiledText <> "") Then
            CompiledText = CompiledText & vbCrLf
        End If
        temporary = arr(i)
        CompiledText = CompiledText & GrabATTRN(CStr(temporary))
    ElseIf (InStr(arr(i), "DB(") <> 0) Then
        If (CompiledText <> "") Then
            CompiledText = CompiledText & vbCrLf
        End If
        temporary = arr(i)
        CompiledText = CompiledText & GrabDB(CStr(temporary))
    End If
Else
    If (marker <> i - 1) Then
        arr(marker) = arr(marker) & vbCrLf & CompiledText
        CompiledText = ""
    End If
    marker = i
End If
Next i
test = ""
For i = 0 To UBound(arr)
If (i > 0) Then
test = test & vbCrLf
End If
test = test & arr(i)
Next i

Range("B1").Value = test
End Sub

调用的函数无法正常工作:

Function GrabATTRS(ab As String) As String
Dim temp As String
Dim dimension As String
Dim attrib As String
temp = Split(Split(ab, "ATTRS(")(1), ")")(0)
dimension = onlyChars(Split(temp, ",")(0))
attib = onlyChar(Split(temp, ",")(UBound(Split(temp, ",")) - 1))
GrabATTRS = "#From dimension " & dimension & " pointing to " & attrib
End Function

Function GrabATTRN(ab As String) As String
Dim temp As String
Dim dimension As String
Dim attrib As String
temp = Split(Split(ab, "ATTRN(")(1), ")")(0)
dimension = onlyChars(Split(temp, ",")(0))
attib = onlyChar(Split(temp, ",")(UBound(Split(temp, ",")) - 1))
GrabATTRN = "#From dimension " & dimension & " pointing to " & attrib
End Function

Function GrabDB(ab As String) As String
Dim temp As String
Dim dimension As String
Dim attrib As String
temp = Split(Split(ab, "DB(")(1), ")")(0)
dimension = onlyChars(Split(temp, ",")(0))
GrabDB = "#From " & dimension & " Cube"
End Function

这个功能可以跳过检查,因为它运作良好

Function onlyChars(S As String) As String
    Dim i As Integer
    retval = ""
    For i = 1 To Len(S)
        If Mid(S, i, 1) <> "'" Then
            retval = retval + Mid(S, i, 1)
        End If
    Next i
    onlyChars = retval
End Function


Option Explicit

1 个答案:

答案 0 :(得分:1)

var onode = childNode.selectAll(".outer_node") .data(data.outer) .enter().append("g") .attr("class", "outer_node") .attr("transform", function(d) { return "rotate(-86)translate(340)"; }); 函数返回Split。示例例如来自函数Varaint

GrabATTRS的结果可以放入字符串变量中,然后将Split传递给ByRef

  

调用导致ByRef错误:

onlyChars
  

使用字符串结果示例:

dimension = onlyChars(Split(temp, ",")(0))