Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Blank Elements in Array

charrigancharrigan Posts: 1Member
Hi,
I have some code that assigns text to the elements in my array if certain things are met.

e.g
Array(0) will equal "Fail 1" - if it fails the check
Array(1) "" - will be blank if it passed the check
Array(2) will equal "Fail 3" - if it fails the check

I then use join function to get "Fail 1,,Fail 3"

How do I get it to ignore the blank value in the 2nd element.

Would really appreciate any help!

Comments

  • dokken2dokken2 Posts: 532Member
    : Hi,
    : I have some code that assigns text to the elements in my array if
    : certain things are met.
    :
    : e.g
    : Array(0) will equal "Fail 1" - if it fails the check
    : Array(1) "" - will be blank if it passed the check
    : Array(2) will equal "Fail 3" - if it fails the check
    :
    : I then use join function to get "Fail 1,,Fail 3"
    :
    : How do I get it to ignore the blank value in the 2nd element.
    :
    : Would really appreciate any help!
    :
    :


    write a custom join function-

    [code]
    Dim myArray(1 To 5) As String

    Sub InitArray()
    myArray(1) = "fail 1"
    myArray(2) = ""
    myArray(3) = "fail 3"
    myArray(4) = "fail 4"
    myArray(5) = ""

    Dim result As String

    result = myJoin(myArray())
    MsgBox result
    End Sub

    Function myJoin(ByRef myAR() As String) As String
    Dim i As Integer
    Dim tmp As String

    For i = 1 To UBound(myAR())
    'not empty/null string
    If myAR(i) <> "" Then
    'append array item, comma
    tmp = tmp & myAR(i) & ","
    End If
    Next i

    'trim last comma from string
    tmp = Left(tmp, Len(tmp) - 1)
    myJoin = tmp
    End Function
    [/code]
Sign In or Register to comment.