1

I am trying to split a string into an array in VB6.

The string is stored in a database and looks like this:

"By Value : "

Sometimes it may include something more at the end after the colon, this is why I want to split it as I am comparing it in an if statement, as shown below.

Overall my code goes like this:

Dim deliveryType(2) As String

deliveryType = Split(vaGoodsInLine.FieldValue("Comment"), ":")

If deliveryType(0) = "By Value " Then
 'Do Something
End IF

I am getting the following error

enter image description here

I also tried defining the array as a variant with no size like this:

Public deliveryType() As Variant

But then I get this error deliveryType

5
  • 1
    Does this answer your question? Public Array Compile Error - Can't assign to array Commented Jul 21, 2021 at 18:06
  • @GSerg unfortunately not, I am getting a Run-time error '13' Type mismatch Commented Jul 21, 2021 at 18:13
  • If you have redeclared deliveryType as Variant, then you should have not done that. You should have removed the fixed size. Commented Jul 21, 2021 at 18:17
  • So many errors here. This is only the beginning. Commented Jul 21, 2021 at 22:09
  • 1
    Don't set the size on the array... Dim deliveryType(2) As String should just be Dim deliveryType() As String. Then, the original should be fine. For the second, you could try Dim deliveryType As Variant, without ()s, as Variant can already accept both arrays and non arrays. Commented Jul 22, 2021 at 13:08

1 Answer 1

1
Dim deliveryType() As String
deliveryType = Split(vaGoodsInLine.FieldValue("Comment"), ":")
Dim deliveryTypeValue As String

If Not UBound(deliveryType) = 0 Then
    deliveryTypeValue = NullStr(deliveryType(0))
End If
    
If deliveryTypeValue = "By Value" Then
    'Do Something
End IF

This worked for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Did your first 2 lines get combined into one?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.