拆分功能中的VBA类型不匹配

TMi*_*nos 3 excel vba excel-vba

我写了一个代码,需要从这样的字符串中获取数字:“ 3/1”。我需要将这两个数字存储为2个不同变量中的整数。我已经在2个类中编写了此代码:此函数是我在班级(BigOne)中的拆分函数

Public Function SplitValues(pInput As String, pdelim As String) As String()
'Declaration of variables
Dim strSplit() As String
Dim countDelim As Integer

'Initialization of variables

countDelim = countCharacter(pInput, pdelim)
If countDelim > 0 Then
    ReDim strSplit(countDelim)
    strSplit = Split(pInput, pdelim)
    SplitValues = strSplit
End If
End Function
Run Code Online (Sandbox Code Playgroud)

在主类中,我有一个函数调用此函数,该函数将数字拆分以获取所需的值。但是,我收到“类型不匹配错误”,我无法检测到此类型不匹配的原因。

Public Function get_MaxChars(pInput As String) As Integer
'declaration of variables
    Dim gen As cBigOne
    Dim values As String

   'Main code
    pInput = CStr(pInput)
    Debug.Print (pInput)
    values = gen.SplitValues(pInput, "/")
    get_MaxChars = CInt(values(0))

End Function
Run Code Online (Sandbox Code Playgroud)

因此,我看不到为什么它无法正常工作,并且出现类型不匹配错误。因为,我相信我到处都传递相同的类型。

bob*_*job 5

SplitValues返回String数组,而您尝试将其分配给String。尝试调暗valuesString()

调用时仍然会有问题,SplitValues因为您还没有创建类的实例,只是说那gen将是一个。之后Dim gen As cBigOne,您应该有Set gen As New cBigOne