Solved

Does there exist a Standard Library for VB?

Posted on 1998-09-18
14
235 Views
Last Modified: 2010-04-30
In most programming languages there is some support for standard datastructures (Classes) such as lists, queues, trees, b-trees, hash tables, etc. Examples of such support is the STL library for C++. Does such libraries exist for free for VB? Only answer if your know where to get them. It is ok if you made them yourselves so long they are fairly fast & flexible.
0
Comment
Question by:felonius
  • 8
  • 6
14 Comments
 
LVL 1

Author Comment

by:felonius
Comment Utility
Adjusted points to 80
0
 
LVL 1

Author Comment

by:felonius
Comment Utility
Adjusted points to 100
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
You could find some librairies on the internet. But the best is creating you own librairy with the functions you could find on Internet.
I suggest you my site :
  http://www.geocities.com/ResearchTriangle/6311/
You will find a lot of useful code.


0
 
LVL 1

Author Comment

by:felonius
Comment Utility
I have been browsing your links and the only code that gets even close is a "general" stack. First of all, i would prefer if it was written as a class and not as funktions. The second problem is that it is not general. It uses the Variant type as argument, but Variants cannot contain userdefined objects.
I think that it should accept arguments of type Object.

Thanks for the feedback, though. I have used a lot of time on the web looking for these routines and have begun to write them myself now. If nothing comes up soon this question will be deleted.

felonius
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
What kind of functions do you want? I have classes for stack, linked list...

But I can't release them all (for the moment) they represent 5 years of work and experiences. But I can send you some classes or code if you give me more informations.
0
 
LVL 1

Author Comment

by:felonius
Comment Utility
Thanks for your response waty,

The classes I think are essential for every programmer is the following:
Single-linked list (functions: next, data, head, insert, delete, clear, copy)
Double-linked list (functions: next, prev, head, tail, insert, delete, clear, copy, data)
Stack (empty, pop, push, top)
Queue (enqueue, dequeue, empty)
Map (find, insert, delete, retrieve, Merge) A map is a associative container in which each element is attached af Key which they are sorted after. By delievering the key, the data can retrieved fast. The usual structure of this container class is that of an AVL-tree.
Hash_Map - a variation of a map in which you also supply a hash function to be able to make speedier retrievals, but at a higher cost of space.
Set (find, subset, union, insert, delete, retrieve, intersection)
A set is a collection of data with no ordering. It is not very unlike the collection concept in VB.

They should be able to contain any type of object. I do not have so much expierience with VB, having written my first VB program only 2 weeks ago. My experience comes primarily from C++. But I think that if you create user-defined objects containing for instance only an Integer, that should be the way to handle Integers as Objects. Maybe some of these classes are impossible to make in VB and so must it be.
If you can supply at least 3 of the above I will accept the answer (the grade depending the quality of the code). If you can give more I will give more points.
If you do not want to give away your code easily I could maybe see one of the classes first and see if I like it. If I do, I can maybe make those classes of the above that you do not have and we could exchange code.

felonius... send to felonius@diku.dk


0
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
Comment Utility
' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 25/09/98
' * Time             : 13:11
' * Module Name      : class_LinkedList
' * Module Filename  : LinkedList.cls
' **********************************************************************
' * Comments         : A simple doublely linked list class
' *
' *
' **********************************************************************

Option Explicit

Private m_head As class_ListItem
Private m_tail As class_ListItem
Private m_cur  As class_ListItem

Private m_count As Long

Public Sub AddFirst(ItemData As Variant)
   '
   '  Adds ItemData to the head of the linked list
   '
   Dim ITem As New class_ListItem

   If VarType(ItemData) = vbObject Then
      Set ITem.ItemData = ItemData
   Else
      ITem.ItemData = ItemData
   End If

   If (m_head Is Nothing) Then
      Set m_head = ITem
      Set m_tail = ITem
      Set m_cur = ITem
   Else
      Set ITem.NextItem = m_head
      Set ITem.PrevItem = Nothing
      Set ITem.NextItem.PrevItem = ITem
      Set m_head = ITem
   End If

   m_count = m_count + 1

End Sub

Public Sub AddLast(ItemData As Variant)
   '
   '  Adds ItemData to the end of the linked list.
   '
   
   Dim ITem As New class_ListItem

   If VarType(ItemData) = vbObject Then
      Set ITem.ItemData = ItemData
   Else
      ITem.ItemData = ItemData
   End If

   If (m_tail Is Nothing) Then
      Set m_head = ITem
      Set m_tail = ITem
      Set m_cur = ITem
   Else
      Set ITem.PrevItem = m_tail
      Set ITem.NextItem = Nothing
      Set ITem.PrevItem.NextItem = ITem
      Set m_tail = ITem
   End If

   m_count = m_count + 1

End Sub

Property Get count() As Long
   '
   '  Returns the number of items in the linked list.
   '
   
   count = m_count

End Property

Property Get CurrentItem() As Variant
   '
   '  Returns the current item.
   '
   
   If m_cur Is Nothing Then
      CurrentItem = Null
   Else
      If VarType(m_cur.ItemData) = vbObject Then
         Set CurrentItem = m_cur.ItemData
      Else
         CurrentItem = m_cur.ItemData
      End If
   End If

End Property

Property Let CurrentItem(ItemData As Variant)
   '
   '  Sets the current item.
   '
   
   If Not m_cur Is Nothing Then
      m_cur.ItemData = ItemData
   End If

End Property

Property Set CurrentItem(ItemData As Variant)
   
   If Not m_cur Is Nothing Then
      Set m_cur.ItemData = ItemData
   End If

End Property

Public Sub InsertAfter(ItemData As Variant)
   '
   '  Inserts ItemData after the current item in the list.
   '
   
   Dim ITem As New class_ListItem

   If VarType(ItemData) = vbObject Then
      Set ITem.ItemData = ItemData
   Else
      ITem.ItemData = ItemData
   End If

   If (m_cur Is Nothing) Then
      Set m_head = ITem
      Set m_tail = ITem
      Set m_cur = ITem
   Else
      Set ITem.NextItem = m_cur.NextItem
      Set ITem.PrevItem = m_cur
      Set m_cur.NextItem = ITem
      'Add the following line.
      Set m_cur.NextItem.PrevItem = ITem

      If (m_cur.NextItem Is Nothing) Then
         Set m_tail = m_cur
      End If
   End If

   m_count = m_count + 1

End Sub

Public Sub DeleteAll()
   '
   '  Delete all
   '
   
   Dim M As class_ListItem
   Dim m2 As class_ListItem

   M = m_head

   Do While Not (M Is Nothing)
      Set m2 = M.NextItem
      Set M.NextItem = Nothing
      Set M.PrevItem = Nothing
      Set M = m2
   Loop

   m_head = Nothing
   m_tail = Nothing
   m_cur = Nothing
   m_count = 0
   
End Sub

Public Sub DeleteCurrent()
   
   Dim tmp As class_ListItem

   If (m_cur Is Nothing) Then
      Exit Sub
   End If

   If (m_cur.PrevItem Is Nothing) Then
      '
      ' Delete head of list
      '
      Set m_head = m_cur.NextItem
      If (m_head Is Nothing) Then
         '
         ' Also deleting tail, list becomes empty
         '
         Set m_tail = Nothing
         Set m_cur = Nothing
      Else
         Set m_head.PrevItem = Nothing
         Set m_cur = m_head
      End If
   ElseIf (m_cur.NextItem Is Nothing) Then
      '
      ' Deleting end of list
      '
      Set m_tail = m_cur.PrevItem
      If (m_tail Is Nothing) Then
         '
         ' Also deleting head, list becomes empty
         '
         Set m_head = Nothing
         Set m_cur = Nothing
      Else
         Set m_cur = m_tail
         Set m_cur.NextItem = Nothing
      End If
   Else
      '
      ' Delete somewhere inside of list
      '
      Set tmp = m_cur.NextItem
      Set m_cur.PrevItem.NextItem = m_cur.NextItem
      Set m_cur.NextItem.PrevItem = m_cur.PrevItem
      Set m_cur = tmp
   End If

   m_count = m_count - 1
   
End Sub

Public Function FirstItem() As Variant
   '
   '  Return's the first item in the list.
   '
   
   If (m_head Is Nothing) Then
      FirstItem = Null
   Else
      If (VarType(m_head.ItemData) = vbObject) Then
         Set FirstItem = m_head.ItemData
      Else
         FirstItem = m_head.ItemData
      End If
      Set m_cur = m_head
   End If

End Function

Public Function NextItem() As Variant
   '
   '  Returns the next item in the list.
   '
   
   If (m_cur Is Nothing) Then
      NextItem = Null
      Debug.Print "First Null"
   Else
      If (m_cur Is Nothing) Then
         NextItem = Null
      Else
         Set m_cur = m_cur.NextItem
         If (VarType(m_cur.ItemData) = vbObject) Then
            Set NextItem = m_cur.ItemData
         Else
            NextItem = m_cur.ItemData
         End If
      End If
   End If

End Function

Public Function LastItem() As Variant
   '
   ' Returns the last item in the list.
   '
   
   If (m_tail Is Nothing) Then
      LastItem = Null
   Else
      Set m_cur = m_tail
      If (VarType(m_cur.ItemData) = vbObject) Then
         Set LastItem = m_cur.ItemData
      Else
         LastItem = m_cur.ItemData
      End If
   End If

End Function

Public Function PrevItem() As Variant
   '
   '  Returns the previous item in the list.
   '
   
   If (m_cur Is Nothing) Then
      PrevItem = Null
   Else
      If (m_cur.PrevItem Is Nothing) Then
         PrevItem = Null
      Else
         Set m_cur = m_cur.PrevItem
         If (VarType(m_cur.ItemData) = vbObject) Then
            Set PrevItem = m_cur.ItemData
         Else
            PrevItem = m_cur.ItemData
         End If
      End If
   End If

End Function

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 14

Expert Comment

by:waty
Comment Utility
I forgot to add the class_ListItem to use with the linked list

Option Explicit

'  Used with the class_LinkedList class.

Private m_next As class_ListItem
Private m_prev As class_ListItem
Private m_data As Variant

Public Property Set ItemData(v As Variant)
   Set m_data = v
End Property

Public Property Get NextItem() As class_ListItem
   Set NextItem = m_next
End Property

Public Property Set NextItem(ITem As class_ListItem)
   Set m_next = ITem
End Property

Public Property Get PrevItem() As class_ListItem
   Set PrevItem = m_prev
End Property

Public Property Set PrevItem(ITem As class_ListItem)
   Set m_prev = ITem
End Property

Public Property Get ItemData() As Variant
   If (VarType(m_data) = vbObject) Then
      Set ItemData = m_data
   Else
      ItemData = m_data
   End If
End Property

Public Property Let ItemData(v As Variant)
   If (VarType(v) = vbObject) Then
      Set m_data = v
   Else
      m_data = v
   End If
End Property

0
 
LVL 14

Expert Comment

by:waty
Comment Utility
' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 25/09/98
' * Time             : 13:14
' * Module Name      : class_Stack
' * Module Filename  : Stack.cls
' **********************************************************************
' * Comments         : A simple Stack class.
' *
' *
' **********************************************************************

Option Explicit

' Private Data
Private vData As New Collection

Public Sub Clear()
   
   Set vData = New Collection

End Sub

Property Get count() As Long
   '
   ' Returns the number of items in the stack.
   '
   
   count = vData.count

End Property

Public Function Peek() As Variant
   '
   '  Returns the value of the next item on the
   '  stack without removing the item from the
   '  stack.
   '
   
   If vData.count = 0 Then
      Peek = Null
   Else
      If VarType(vData.ITem(1)) = vbObject Then
         Set Peek = vData(1)
      Else
         Peek = vData(1)
      End If
   End If

End Function

Public Function Pop() As Variant
   '
   '  Removes and returns the next item from
   '  the stack.
   '
   
   If vData.count = 0 Then
      Pop = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Set Pop = vData(1)
      Else
         Pop = vData(1)
      End If
      vData.Remove 1
   End If

End Function

Public Sub Push(v As Variant)
   '
   '  Adds an item to the Stack
   '
   
   If vData.count = 0 Then
      vData.Add v
   Else
      vData.Add v, , 1
   End If

End Sub

0
 
LVL 14

Expert Comment

by:waty
Comment Utility
' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 25/09/98
' * Time             : 13:15
' * Module Name      : class_Fifo
' * Module Filename  : FIFO.cls
' **********************************************************************
' * Comments         : A FIFO (First In First Out) buffer.
' *
' *
' **********************************************************************

Option Explicit

Private vData As New Collection

Public Sub Push(v As Variant)
   '
   '  Adds an item to the FIFO
   '
   
   If vData.count = 0 Then
      vData.Add v
   Else
      vData.Add v, , , vData.count
   End If

End Sub

Public Sub Clear()
   '
   '  Clears all items from the FIFO
   '
   
   Set vData = New Collection

End Sub

Public Property Get count() As Integer
   '
   ' Returns the number of items in the FIFO
   '
   
   count = vData.count

End Property

Public Function Pop() As Variant
   '
   '  Returns an item from the FIFO
   '
   
   If vData.count = 0 Then
      Pop = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Set Pop = vData(1)
      Else
         Pop = vData(1)
      End If
      vData.Remove 1
   End If

End Function

Public Function Peek() As Variant
   '
   '  Returns the next item in the FIFO but does
   '  not remove it from the FIFO
   '
   
   If vData.count = 0 Then
      Peek = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Peek = vData(1)
      Else
         Peek = vData(1)
      End If
   End If
End Function

0
 
LVL 14

Expert Comment

by:waty
Comment Utility
I have added previously some classes that you need (eventually, you could modify them for specific uses). If you enhance them, send them back to me : waty.thierry@usa.net

>Map (find, insert, delete, retrieve, Merge) A map is a >associative container in which each element is attached af Key >which they are sorted after. By delievering the key, the data >can retrieved fast. The usual structure of this container class >is that of an AVL-tree.
It seems as a typical collection in VB excepting the sort.

If you add some more points, I could also give you routines to sort, search, shuffle, compare array, collections. I use them in my Print Preview OCX (see my web site)
0
 
LVL 1

Author Comment

by:felonius
Comment Utility
The code you have sent is structurally fine. The only problem is that the data they can contain is of type Variant. It was the same problem a saw with the Stack class at your site (as I commented earlier. The stack you posted now is the same as on your site, isn't it?). Is there any way I can insert user defined types into these? Or should I rewrite the classes?

felonius
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
You can modify the classes to use with UDT instead ov variant.

I don't remember if it is the same class than on my website, but probably.
0
 
LVL 1

Author Comment

by:felonius
Comment Utility
The grade is based on the fact that I have to rewrite a lot of the code. I is not truely general either. General containers support similar interfaces, so algrorithms can be written for several of them at once.

I will post you a web-site where new version can be found when they are done. I expect it to be at http://www.image.dk/~lisjac/. Currently that site only contains a danish guide to my students at the university, but that will change.

If any code are reused you will be listed in the the "based upon/acknowledgement" section of the code.

I have come to the conclusion that the community does not have a truly general library of code and I thnk that I will make one at distribute it freely. Stay tuned.

felonius
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

7 Experts available now in Live!

Get 1:1 Help Now