I have written a code where I need to get the number from a string like this: "3/1". I need to store those 2 numbers as integer in 2 different variables. I have written this code in 2 classes: This function is my split function in the class (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
In the main class I have a function calling to this function that splits the number to get the values that I want. However I am getting a "Type Mismatch error" I am not able to detect the reason of this type mismatch.
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
So, I am not able to see why it is not working correctly and I am getting the type mismatch error. Because, I believe that everywhere I am passing the same type.
SplitValues
returns a String array, and you are trying to assign it to a String. Try dimming values
as String()
instead.
You'll still have an issue when calling SplitValues
as you haven't created an instance of your class, just said that gen
will be one. After Dim gen As cBigOne
, you should have Set gen As New cBigOne
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With