Blank Elements in Array - Programmers Heaven

Howdy, Stranger!

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

Categories

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.