Solved

Removing elements from a Type array

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# combobox autocomplete behavior 6 92
VBA color chart bars 12 67
noX challenge 17 77
move one pixel 4 41
A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
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 …
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now