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
Solved

Removing elements from a Type array

Posted on 2006-11-15
2
187 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
  • 2
2 Comments
 
LVL 85

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 85

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export Table to CSV - Access to CSV - using python 18 168
printf performancy 11 70
backup program with robocopy 6 45
Using Third Party DLL with Access VBA 14 41
A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 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