Solved

Removing elements from a Type array

Posted on 2006-11-15
2
189 Views
Last Modified: 2010-04-16
I have a user defined Type in which I have defined it as an array. How can I remove an element from the array. Here is what my Data Type looks like.

Public Type typField
    strName As String
    strStartPoint As Integer
    strEndPoint As Integer
End Type

Public pfields(50) As typField


Thanks,
-blake
0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17953517
You can write a sub to reset all the fields in the structure:

Private Sub Form_Load()
    pfields(0).strName = "mike"
    pfields(0).strStartPoint = 1
    pfields(0).strEndPoint = 10
   
    Debug.Print pfields(0).strName
    Debug.Print pfields(0).strStartPoint
    Debug.Print pfields(0).strEndPoint
   
    ResetIndex 0
   
    Debug.Print pfields(0).strName
    Debug.Print pfields(0).strStartPoint
    Debug.Print pfields(0).strEndPoint
End Sub

Private Sub ResetIndex(ByVal index As Integer)
    If index >= LBound(pfields) And index <= UBound(pfields) Then
        With pfields(index)
            .strName = ""
            .strStartPoint = 0
            .strEndPoint = 0
        End With
    End If
End Sub
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 17953525
Or are you trying to "bubble down" all the other elements to fill the "hole" left when you remove and index?

Like...

Private Sub Form_Load()
    pfields(0).strName = "a"
    pfields(0).strStartPoint = 1
    pfields(0).strEndPoint = 10
   
    pfields(1).strName = "b"
    pfields(1).strStartPoint = 25
    pfields(1).strEndPoint = 50
   
    Debug.Print pfields(0).strName
    Debug.Print pfields(0).strStartPoint
    Debug.Print pfields(0).strEndPoint
   
    RemoveIndex 0
   
    Debug.Print pfields(0).strName
    Debug.Print pfields(0).strStartPoint
    Debug.Print pfields(0).strEndPoint
End Sub

Private Sub ResetIndex(ByVal index As Integer)
    If index >= LBound(pfields) And index <= UBound(pfields) Then
        With pfields(index)
            .strName = ""
            .strStartPoint = 0
            .strEndPoint = 0
        End With
    End If
End Sub

Private Sub RemoveIndex(ByVal index As Integer)
    If index >= LBound(pfields) And index <= UBound(pfields) Then
        Dim i As Integer
        For i = index To UBound(pfields) - 1
            With pfields(i)
                .strName = pfields(i + 1).strName
                .strStartPoint = pfields(i + 1).strStartPoint
                .strEndPoint = pfields(i + 1).strEndPoint
            End With
        Next i
        ResetIndex UBound(pfields)
    End If
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question