Solved

Removing elements from a Type array

Posted on 2006-11-15
2
185 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now