Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Removing elements from a Type array

Posted on 2006-11-15
2
Medium Priority
?
193 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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Make the most of your online learning experience.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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

636 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