×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

AGH cant find Item under Collection, nor can I find index # for curent

AGH cant find Item under Collection, nor can I find index # for curent

AGH cant find Item under Collection, nor can I find index # for curent

(OP)
I got a collection, I got a listbox keeping track of it, I cannot do Collection("Name To Find") nor Collection.Item("Name to Find")
I cant search those
and I Cant figure out how to get the Index once I find the Item I want to remove. or even work with

Karl
kb244@kb244.8m.com

Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)

RE: AGH cant find Item under Collection, nor can I find index # for curent

(OP)
Update: so far this seems to work

Public Sub SicShape(Name As String, ShapeType As String, SIC As String, Desc As String, employers As String)
On Error GoTo SError
Dim NewSh As New Shapes
Dim NewS2 As New Sic2
Dim NewS4 As New Sic4
Dim idx As Integer
Dim sicid As String
Dim bExists As Boolean
Dim objSicStuff As Object
Set objSicStuff = CreateObject("wiDataAccess.Dataconnection")

objSicStuff.ConnectionString = "dsn=siccode;uid=sa;pwd;"
objSicStuff.Connect

If Desc = "" Then
Desc = objSicStuff.GetSicTitle(SIC)
End If

'Dont know if this next line will work
bExists = True
Set NewSh = Shapes.Item(Name)
sicid = Trim(SIC)
If Len(sicid) = 2 Then
NewS2.SicDesc = Desc
NewS2.SicCode = sicid
NewS2.total = 0

Set rs = objSicStuff.GetSic4Titles(sicid)
Do While Not rs.EOF
NewS4.SicCode = rs!SicCode
NewS4.SicDesc = rs!sictitle
NewS2.Sic4.Add NewS4, rs!SicCode
NewS2.total = NewS2.total + 1
Set NewS4 = New Sic4
rs.movenext
Loop
NewSh.Sic2.Add NewS2, sicid

Else
NewS4.SicCode = sicid
NewS4.SicDesc = Desc
NewSh.Sic4.Add NewS4, sicid
End If
If bExists = False Then
NewSh.Name = Name
Shapes.Add NewSh, Name
End If

Exit Sub
SError:
If Err.Number = 5 Then
bExists = False
End If
Err.Clear
Resume Next
Exit Sub

End Sub

Karl
kb244@kb244.8m.com

Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)

RE: AGH cant find Item under Collection, nor can I find index # for curent


Karl,

The basic problem is that you must know the index to each item that you add to the collection -- you have 2 options:

Option 1:

When you add a name to the collection, use the same name as the key to that item. For example,

col.Add "Name 1", "Name 1"

Then when you can use col(List1) or col.Item(List1) to retrieve the collection item.

Option 2:

As you add an item to the collection, add the same item to the list box. Then when the user selects an item from the listbox, use the index of the listbox item that was selected to retrieve the collection item. For example,

c.Add "Item 1"
List1.AddItem "Item 1"

Then you can use c.Item(list1.ListIndex + 1) to retrieve the collection item.

Hope this helps!

RE: AGH cant find Item under Collection, nor can I find index # for curent

Here's another approach:
Use the itemdata property to store the index for each item you've added to the collection, and the newindex property to get the index of the last item added.

Dim itemname as string
Dim c as collection
Dim i as integer

for i = 1 to 10
    itemname = <assign your itemname values here>
    c.add Itemname
    list1.additem Itemname
    list1.itemdata(list1.newindex) = i
next


then you can retrieve the values by doing

c.item(list1.itemdata(list1.listindex))

the benefit of doing it this way is that it will work with a sorted list box.


nick bulka
nick@bulka.com

RE: AGH cant find Item under Collection, nor can I find index # for curent

(OP)
Thanks for your responces tho, but I've already figured out you have to assing the key as well, and btw heres the code so far in SicCodes.cls, with the exception that some properties has been added to other collections.
(also i cant have Lists involded in my code, must be completely self contained, now just to figure out how to export the collection)

Public Shapes As New Collection

Public Sub SicShape(Name As String, ShapeType As String, Sic As String, Desc As String, employers As String)
' Add entire Shape's Sic code tree, if Sic2 was added under shape, then all Sic4s that follow it are added too
On Error GoTo SError
Dim NewSh As New Shapes
Dim NewS2 As New Sic2
Dim NewS4 As New Sic4
Dim idx As Integer
Dim sicid As String
Dim bExists As Boolean
Dim objSicStuff As Object
Set objSicStuff = CreateObject("wiDataAccess.Dataconnection")

objSicStuff.ConnectionString = "dsn=siccode;uid=sa;pwd;"
objSicStuff.Connect

If Desc = "" Then
Desc = objSicStuff.GetSicTitle(Sic)
End If

'Dont know if this next line will work
bExists = True
Set NewSh = Shapes.Item(Name)
sicid = Trim(Sic)
If Len(sicid) = 2 Then
NewS2.SicDesc = Desc
NewS2.SicCode = sicid
NewS2.total = 0

Set rs = objSicStuff.GetSic4Titles(sicid)
Do While Not rs.EOF
NewS4.SicCode = rs!SicCode
NewS4.SicDesc = rs!sictitle
NewS2.Sic4.Add NewS4, rs!SicCode
NewS2.total = NewS2.total + 1
Set NewS4 = New Sic4
rs.movenext
Loop
NewS2.SEmploy = employers
NewSh.Sic2.Add NewS2, sicid

Else
NewS4.SicCode = sicid
NewS4.SicDesc = Desc
NewS4.SEmploy = employer
NewSh.Sic4.Add NewS4, sicid
End If
If bExists = False Then
NewSh.Name = Name
NewSh.SType = ShapeType
NewSh.SDesc = Desc
Shapes.Add NewSh, Name
End If

Exit Sub
SError:
If Err.Number = 5 Then
Debug.Print Err.Description + " occured in SicShape"
bExists = False
End If
Err.Clear
Resume Next
Exit Sub

End Sub

Public Sub ShapeRemove(Name As String)
On Error GoTo DError
Shapes.Remove (Name)
Exit Sub
DError:
If Err.Number = 5 Then
Debug.Print Err.Description + " Occured in Shape Remove"
Err.Clear
Resume Next
End If
Debug.Print "Unknown Error: " + Err.Number + " " + Err.Description + " in Shape Remove"
End Sub

Public Sub ShapeClear()
Dim Num As Integer
For Num = 1 To Shapes.Count
Shapes.Remove 1
Next Num

End Sub

Public Sub ShapeChange(OldName As String, NewName As String, SicCode As String)
On Error GoTo CError
Dim OldSH As Shapes
Dim OldS2 As Sic2
Dim OldS4 As Sic4
Dim NewSh As New Shapes
Dim Exists As Boolean

Exists = True
Set OldSH = Shapes.Item(OldName)
If Exists = False Then
Exit Sub
End If
For Each OldS2 In OldSH.Sic2
NewSh.Sic2.Add OldS2
Next
For Each OldS4 In OldSH.Sic4
NewSh.Sic4.Add OldS4
Next
NewSh.Name = NewName
Shapes.Add NewSh, NewName
Shapes.Remove OldName
Exit Sub
CError:
Debug.Print Err.Description + " occured in ShapeChange"
Exists = False
Err.Clear
Resume Next
End Sub

Sub SRemoveSic(Shape As String, Sic As String)
On Error GoTo SRError
Dim SicSH As Shapes
Sic = Trim(Sic)
Dim Exists As Boolean
Exists = True
Set SicSH = Shapes.Item(Shape)
If Exists = False Then Exit Sub
If Len(Sic) = 2 Then
SicSH.Sic2.Remove Sic
Else
SicSH.Sic4.Remove Sic
End If

SRError:
Debug.Print Err.Description + " occured in SicRemove"
Exists = False
Err.Clear
Resume Next
End Sub

Karl
kb244@kb244.8m.com

Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close