Counting Items In Collection
Hi, I want to execute what should be a simple task, namly to count the number of items in a collection (a collection of custom document properties in Word) but i can't find any information on msdn on how to do that. Can anyone help me? Thanks a lot in that case.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Counting The Same Items!
i have been using search function but sometimes that is not enaugh, cause it is not functional for same items in a list box. Thats why i am looking for a filtering piece of code!
for ex, when i type "tiiii" it will display all the items that start with "tiiii".
any help please?
Counting Items
how do i count the items in a listview?
lets say got 10 items, how to display 10? .. i mean count as well.. and if there are no items.. prompt error msg
Counting Items In A List
Visual Basic 6.0 w/Excel 2000
I have a column of entries that are sorted alphabetically. Is there a function or a VB 6 routine that will allow me to count the number of each occurrence that starts with "a", "b", "c", etc.
Thanks
Sheldon S. Cantor
Counting Menu Items
anyone know how to count menu items?
i have this project & the menu items vary per form.
is there any way that the system could count them without doing the manual initialization stuff..?
Counting Items In A Listbox.
Hey guys, I have a label called List3Countlbl and I was wondering if it was possible so that when a form load event occurs, the items in a list3 listbox gets counted and the result goes in the List3Countlbl??
Thanks!
Counting The Items In A Text File
Hi,
Here is another novice post from me"8=>))..
There are 15 labels to show "the randomly selected numbers" between "0,1 and 2"
I need to know how many "0s,1s and 2s" there are in my text file where I appended
the results of each event...
I mean ,I want my "newLabel" to write "There are five..1,four..0,and six..2 " in the file
the sum of which should equal=15
I think this should be something like counting each character in an array..but.."
thanks
VB Code:
Dim a, b, c, d, e, f, g, h, i, k, l, m, n, o, p As LongPrivate Sub Command1_Click()Randomizea = Int(Rnd * 3)Label1.Caption = ab = Int(Rnd * 3)Label2.Caption = bc = Int(Rnd * 3)Label3.Caption = cd = Int(Rnd * 3)Label4.Caption = d e = Int(Rnd * 3)Label5.Caption = ef = Int(Rnd * 3)Label6.Caption = fg = Int(Rnd * 3)Label7.Caption = gh = Int(Rnd * 3)Label8.Caption = hi = Int(Rnd * 3)Label9.Caption = i k = Int(Rnd * 3)Label10.Caption = kl = Int(Rnd * 3)Label11.Caption = li = Int(Rnd * 3)Label12.Caption = im = Int(Rnd * 3)Label13.Caption = mn = Int(Rnd * 3)Label14.Caption = n o = Int(Rnd * 3)Label15.Caption = oDim yaz As IntegerDim ff As StringDim say As Longyaz = FreeFileOpen "C: oto.txt" For Append As #yaz Write #yaz, a, b, c, d, e, f, g, h, k, l, m, n, oClose #yazEnd SubPrivate Sub Command2_Click() Dim buffer As String, hFile As Long hFile = FreeFile() Open "c: oto.txt" For Binary Access Read Lock Write As #hFile buffer = Space(LOF(hFile)) Get #hFile, , buffer Close #hFile Text1.Text = buffernewLabel.caption=""End Sub
How To Get Certain Items Of A Collection
I developed an application which stores two types of objects as items of a collection. theBlockCollection which consists of a collection of pictures and theLineCollection consisting a collection of lines. There are additional properties in each of the objects as shown in the attached pictures (collectionofpicitem1.jpg and collectionoflineitem.jpg).
In this application I can draw a rectangle at runtime (shown in the attached picture: collectionofpicitem.jpg). I need to know if I want to dynamically load a 2D array the contents of collectionoflineitem.jpg but only those that are enclosed within the rectangle, how can I do that?
256 Max Items In A VB Collection?!
Where is this documented!?!? This is the first time that I have had collections that needed this much data, and now I find out I can't do it! Worst of all, there isn't even a VB runtime error generated when you try to go over it, it just doesn't add anymore items. Can someone please tell where I can find it documented from Microsoft that it is true, in fact, that you can only have 256 Items in a collection...
Items In A Collection
To referance an item in a collection this is what I do
Dim XItem
For Each XItem In colCountries
.........
next
Is there any way to referance the item , without declaring XItem as a variant ?
Key For Items In A Collection
Hi,
I have a problem.
Removing an item from a collection, and then adding a new object with a Key like the one of the deleted item, I get a message "This key is already associated with an element in this collection (error 457)".
What can I do to be able to reuse the deleted key ?
Help ! Before I go mad !
Thanks !
Oren.
Urgent - Counting Outlook Contact Items
Hi there... Long time reader, first time poster.
I'm creating an app using VB6 that interacts with the user's Outlook 2000 contact list. I have all of the coding done, but would like to be able to easily count how many Contacts are a part of a certain category (I.E. Suppliers). I am trying to do this without having to cycle through each contact and counting that way.
I have tried the command:
Dim myAddressEntries As AddressEntries
Set myAddressList = myNameSpace.AddressLists(1)
Set myAddressEntries = myAddressList.AddressEntries
lblEntryCount.Caption = myAddressEntries.Count
The myAdressEntries.Count command basically returns all of the contact items, regardless of category. I have not been able to find a way to get the command to only find items in the Suppliers category...
Any ideas welcome! I'm pulling my hair out here!
- Jibootie
Counting Distinct Number Of Items In A ListBox
Hello
I've populated a listBox with a load of country names. Each country can be included once, many times or not at all. I'm trying to work out how many distinct country names there are as wlel as counting how many times each country appears in the list. Here's an example of its contents:
Canada
Canada
USA
UK
France
UK
Canada
Italy
France
France
USA
USA
I aiming for the end result to be something like this
The original listbox contains this:
Canada
France
Italy
UK
USA
and another list box would hold the no. of times each Country appeared in the original list:
3
2
1
2
3
the numbers relate to the countries in alphabetical order.
I would use case statements or something like that if the list of countries was limited to a specific set however since the list can include any country it doesn't make much sense to do it this way.
So what other ways are there of doing this?
Thanks in advance!!
Counting Items In Listbox And Displaying Them (newbie)
Hello again
I've been trying to get this to work to no avail, and was hoping someone who actually knows what he or she is doing (ie not me) can look at..
What I'm trying to do is this... I have a hidden listbox of items.. I want to be able to go through each, split by ":" and look at the 2nd part of the array and tally up all the multiples in the rest of the list... and then in a 2nd listbox... list ONE instance of the item, with the total tabbed off to the side. It's a tally of how many "items" are needed, not who needs what.
So if the hidden Listbox has:
Joe:Beer
Jim:Beer
Bob:Beer
Bob:Oranges
The 2nd listbox would have
Beer3
Oranges1
But instead it has:
Beer1
Beer1
Beer1
oranges 1
I know this is something stupid/simple in my logic but I've been looking at it so long I can't figure it out... at this point my code is so bizarre from me trying things, well...
here's the offending bit of code:
Code:
For i = 0 To lstOrganize.ListCount - 1
theNameString = Split(lstOrganize.List(i), ":")
If lstOrganize.List(i) = "" Then
Else
For j = 0 To (i + 1) Step -1
theNameString2 = Split(lstOrganize.List(j), ":")
If theNameString (i) = theNameString2(i) Then
ItsThere = True
intTheCount = intTheCount + 1
Else
ItsThere = False
End If
Next j
If ItsThere = True Then
Call SendMessage(lstTotalNeeded.hWnd, LB_ADDSTRING, 0, ByVal theNameString(2) & vbTab & intTheCount)
Else
Call SendMessage(lstTotalNeeded.hWnd, LB_ADDSTRING, 0, ByVal theNameString(2) & vbTab & "1")
End If
End If
Next i
Any help that is provided is greatly appreciated.. it's driving me nuts
Gettting Items Out Of A Collection
Well after much searching and much reading I finally was able to implement my collection class. However I have a problem in that I can't get items out of it. I've looked at several Tutorials and did what they did to get items out but it doesn't work for me. If someone could give me some help on this I would appreciate it. Now I use the same method for storing items in my collection so what works for one should work for all. How it goes is that in the forms Load event I call a ClassHandler Sub which is housed Inside my GeneralInfo Module and will handle the various things needed to set the information I need in various places in the game. I store the routines by reading a text document so I have another Module Called TextReader which contains all code to store all Collection Classes. All of my routines that store my Collection Classes Start with Initialize and end With the name of the class. For example InitializeItem handles items, InitializeMonster handles Monsters, and so on. In the decleration section of the GeneralInfo module I create a new instance of the collection and class.
-----All this is in the declerations section of The GeneralInfo Module-----
Public MasterMonsters As Monsters
Public MasterItems As Items
Public MasterRaces As Races
Public MasterItem As Item
Public MasterMonster As Monster
----------------------
-------This is in the declerations section of the TextReader Module
Dim LeftBracket As Integer
Dim RightBracket As Integer
Dim Temp As String
Const ItemNumber As Integer = 8
Const MonstNumber As Integer = 4
Const RaceNumber As Integer = 1
Public TextCounter As Integer
---------------------------------------
Now I set the Collections and Classes in the Subs that read a them
--Each of these pairs are included in the Intialize event which reads their respective collection classes----------------
Set MasterItems = New Items
Set MasterItem = New Item
Set MasterMonsters = New Monsters
Set MasterMonster = New Monster
Set MasterRaces = New Races
Set MasterRace = New Race
--------------------------------------------
Now the TextHandler reads the Initialization subs in the order of Item, Monster, Race.
In the text file the information for each property of the class is closed in brackets to allow me to take out only the information I want. Each field is labeled in the text document to insure I don't change the wrong thing or add things in the wrong order(only when typing up the text file).
-------This is the InitializeItem Event---------
ItemPath = App.Path & "CollectionClassText.txt"
Open ItemPath For Input As #1
Line Input #1, Temp
Do Until TextCounter = ItemNumber
Line Input #1, Temp
LeftBracket = InStr(Temp, "[") + 1
RightBracket = (InStr(Temp, "]")) - LeftBracket
MasterItem.Key = Mid$(Temp, LeftBracket, RightBracket)
Line Input #1, Temp
LeftBracket = InStr(Temp, "[") + 1
RightBracket = (InStr(Temp, "]")) - LeftBracket
MasterItem.TypeofItem = Mid$(Temp, LeftBracket, RightBracket)
Line Input #1, Temp
LeftBracket = InStr(Temp, "[") + 1
RightBracket = (InStr(Temp, "]")) - LeftBracket
MasterItem.Weight = CInt(Mid$(Temp, LeftBracket, RightBracket))
......................
......................
TextCounter = TextCounter + 1
MasterItems.Add MasterItem, MasterItem.Key
Loop
--------------------------------------------------
I didn't include all of it because it is pretty much all the same thing with the difference that each reads a different field. As you can see ItemPath is set to the location of the text file which is opened with that string. The loop counter is used in all other procedures and always set to 0 at the beginning. I declare a constant for each class collections number of entrys. I'll change this constant as I add more. I seperate out the brackets with the InStr function. One for the left bracket and one for the right bracket and then use the Mid$ function to return the string between the brackets. Whenever the Field is a string I enclose the Mid$ function inside the conversion function. The textcounter is updated at the end and then I pass the class I Instanced earlier to the collection I instanced earlier. This allows me to skip declaring as many variables and makes it look neater. I don't know if this could be the problem with getting the information out. All the other Initialize routines do about the same thing with the exception of using their respective Collection and class. I also put a header in the text document before each different type of information. So in each other routine after this one I'll Use the Line Input before the loop to bump down the current line so no errors will be generated. Now I don't have a problem with storing at as I said earlier but I figured this would help let you know what I'm doing and if there was a problem in here that causes the problem with retrieving the information.
---------Declation in the GeneralInfo Module----------------
Public Type CharInfo
BaseHP As Integer
CurHP As Integer
BaseMP As Integer
CurMP As Integer
BaseDV As Integer
CurDV As Integer
BasePV As Integer
CurPV As Integer
BaseLuck As Integer
CurLuck As Integer
BaseDex As Integer
CurDex As Integer
BaseIntel As Integer
CurIntel As Integer
BaseMD As Integer
CurMD As Integer
BaseStr As Integer
CurStr As Integer
End Type
Public TempRaceA s Race
Public TempRaces As Races
--------------------------------------------------
-------Code in the Stats Sub------------
Dim CurChar As CharInfo
Set TempRace = New Race
Set MasterRaces = Races
Set TempRaces = New Races
Set TempRaces = MasterRaces
Set TempRaces = TempRaces.Item(1)
TempRace = MasterRaces.Item(1)
------------------------------------
The Declerations Creates A UDT to hold the characters stats. After that the Stats Routine is suppose to pull a Race out of the Races Collection and then I'll use that to fill in the Stats. This code up top started by looking at thinkers Tutorial and trying to use what he did to serve my purpose. However his method didn't work and I've tried every combination I can think of in the Stats Sub but nothing works. I've got two basic responses. It either runs through it but The collections are nothing or it gives me a runtime error "Object variable or With Block Variable not set". I've tried taking out set statements and putting them in and everything I can think of even if it didn't make sense due to running out of trying things that did make sense. I would very much appreciate help sense this is the last part of Collection classes that i have to understand.
Sorting Items In A Collection
Do you have any idea how I might sort a user defined collection. For example, I created my own class with certain properties that I would like to put in alphabetical or sequential order. I would rather not write the collection to a spreadsheet for sorting. Thought about writing my own sort routine but it might get a bit lengthy. Does excel possibly have anything built in?
Add Filtered Items To A Collection
Hello-
I am using John Walkenbach's code to add unique items to a list box. However, I want to go a step further so that when someone selects from one listbox, it filters the table where the data comes from and then populates a second listbox with the filtered unique items from a second column. Here is the portion of his code:
Code:
Set AllCells = Sheets("PART Table").Range(Cells(2, 2), Cells(Range("a65536").End(xlUp).Row, 2))
On Error Resume Next
For Each Cell In AllCells
'If Cell.SpecialCells(xlCellTypeVisible) Then
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be a string
'End If
Next Cell
As you can see, I was trying to do something with the SpecialCells property, but I don't quite understand how to do it. I thought the two options might be to either set the range to somehow only include visible cells, or as I was trying here, only add them to the collection if the cell was visible.
Any help would be appreciated.
Thanks!
Sorting Items In A Collection
I have a multidimensional array and I need the unique values from one column and I need them sorted. I am able to do this with text but when it comes to numbers it doesn't work. Once I get the unique values and they are sorted I add them to a combo box. How can I sort these unique values easily? Isn't there a way to sort a collection?
Here is some code:
Code:
On Error Resume Next
For i = 1 To UBound(fgarraydata, 2)
col.Add fgarraydata(grdColumnNames.col, i), fgarraydata(grdColumnNames.col, i)
Next
For i = 1 To col.count
cmbColumn(0).AddItem col.Item(i)
Next
Removing Items From A Collection??
I want to remove an item from my collection and It keeps bombing out. Can someone take a look at this.
I want to remove the first record in my collection
'heres my form*******
'this is my remove
Private Sub cmdremove_Click()
mproducts.remove ("1")
End Sub
' this is how I add the product***********
Private Sub cmdsave_Click()
product.productid = txtproductid.Text
product.productname = txtproductname.Text
product.productcost = txtcost.Text
product.productprice = txtprice.Text
product.unitsinstock = txtunits.Text
mproducts.add product
Set myproduct = mproducts.item("1")
cmdsave.Visible = False
cmdadd.Visible = True
cmdremove.Visible = True
cmdbuy.Visible = True
'outputs the productid fine*******************
MsgBox myproduct.productid
MsgBox mproducts.count
'Here's my collection***********************************
Private mproducts As Collection
Private Sub Class_Initialize()
Set mproducts = New Collection
End Sub
Private Function NextProductCode() As String
Static intCode As Integer
intCode = intCode + 1
NextProductCode = Trim(Str(intCode))
End Function
Public Sub add(prod As CProduct)
mproducts.add prod, NextProductCode
End Sub
Public Sub remove(ByVal strkey As String)
mproducts.remove strkey
End Sub
Public Function item(ByVal strkey As String)
Set item = mproducts.item(strkey)
End Function
Modifying Items In A Collection
What i'd like to do is change the value of an item in a collection, but i keep on getting an "object required" error.
If i've got a collection say:
Dim args As New Collection
dim backupvar as string
args.add (var1)
args.add (var2)
args.add (var3)
args.add (var4)
For n = 1 To args.Count
if len(args.item(n)) > 20 then
args.item(n) = backupvar
endif
Next
Is there a way to do this?
Multiple Items In A Collection
Hello all,
I've got a (simple?) question that has me flabberghasted.
I'm trying to program a simple pacman clone.
The 'Maze' object has a collection of ghosts, that get filled like this:
For col = 0 To 1 'create some ghosts for testing
For row = 0 To 1
Set Ghost = New clsGhost
Ghost.PosX = col * 14 * 48
Ghost.PosY = row * 8 * 48
Ghost.Speed = 20 * row + 40 * col
Ghosts.Add Ghost
Next row
Next col
If the ghost is to walk around in the maze, it has to know about possible
directions, so the ghost can raise an event to its parent (the maze):
RaiseEvent GetDirection( iPosX SQUARE_WIDTH + 1, _
iPosY SQUARE_HEIGHT, _
MazeDir)
Now, if I create only ONE ghost, then it will run happily around the maze
However, creating MORE ghosts causes the program to skip the 'RaiseEvent' instruction. ( detected during single stepping)
How can I make the 'RaiseEvent' instruction work for multiple instances of the ghost class?
TIA,
Alvatrus
Moving Collection Items
I've never used a Collection before and I was wondering how would I go about moving an item from one index to another?
I want to display the item that has an index of 0 and then remove it form the collection at a certain interval. Then I want to move all teh other items up a spot in the collection. (1 becomes 0, 2 becomes 1, etc.)
Thanks in advance.
Edit: Also, is there a fast way to clear a collection other than looping through it all and setting the values to null?
Maximum Items In A Collection
I got a problem with the collection object in Visual Basic 6.
A maximum of 256 items can be added in a collection. But, if you pass this limit, no more item are add in collection, but the count property continue to expand.
Example:
Dim colTest As New Collection
Dim iCpt As integer
For iCpt = 1 To 300
colTest.Add iCpt
Next
The collection contents 256 items, but the count property is 300.
Why?
Clear Collection Items ....,
Hai ,
I have a new collection RowE , i keep adding values to the collection and perform some string comparision, addition or whatever with them all, Now when i unload the form i need to clear all the contents in the collection .
That is i want, RowE.Count shld be = 0.
How can this be done.....,
Any comments/codes/ideas highly appreciated...,
ashky
Removing Items From A Collection
Can anyone give me any examples of how they would remove several items from a collection without getting a "subscript out of range " error.
I have a collection of maybe 60 items and most of them due to validation will be removed leaving me with around twenty, the thing is once I have removed about 30, I get the above error.
I am presuming this is because the key to each item is reassigned when you remove an item.
I have tried restarting my for each loop each time I delete an item but this doesn't seem to make any difference
Max No Items Can Be Added To A Collection?
After reading the help files and searching through a couple of text books, I could not find the max number if items that can be added to a collection. I have a feeling it is 256, is this correct?????
Cannot Modify Items In Collection (VB.NET)
I am running into a strange error when I try debugging my current application. A form loads up with a dynamically-populated textbox full of software titles. Upon selection of a software title and pressing 'GO' a checkboxlist is displayed with the users who use the current software. The checkboxlist is bound to a dataset named "DataTable" and has the DisplayMember set to "Employee" and the DataValue set to "ID", like the following:
Code:
Dim strSoftwareTitle As String = comboSoftwareTitles.Text()
Dim objConn As New OleDb.OleDbConnection
objConn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("strConnection")
Dim strSQL As String = "SELECT ID, EmployeeName FROM tblSoftware WHERE " & _
"(SoftwareTitle = '" & strSoftwareTitle & "') AND " & _
"(EmployeeName Is Not Null) ORDER BY EmployeeName ASC;"
Dim ds As New DataSet
Dim objCommand As New OleDb.OleDbCommand(strSQL, objConn)
Dim myCommand As New OleDb.OleDbDataAdapter(strSQL, objConn)
myCommand.Fill(ds, "DataTable")
Me.clBox.DataSource = ds.Tables("DataTable")
Me.clBox.MultiColumn = False
Me.clBox.DisplayMember = "EmployeeName"
Me.clBox.ValueMember = "ID"
When I run the application the first software title in the list happens to be "Adobe Acrobat 6.01 Professional." When I hit 'go' I get the error below:
Code:
Additional information: Cannot modify the Items collection
when the DataSource property is set.
The line that is highlighted in debug mode is the following:
Code:
Me.clBox.ValueMember = "ID"
If I quit and run the program again and scroll down and select "Visual .NET 2003 Enterprise" and press 'GO', the checkboxlist displays flawlessly. What could cause my application to error upon selection of the first selection, but not another one in the list. In the subroutine that errors I am not modifying the Items collection. If this isn't clear enough I can provide more information.
Any suggestions?
?collection - Order Of Items
Hello,
I have this problem of getting the exact/original order of fields from a table.
For example:
Student Table:
Fields:
student_id
first_name
last_name
initial
birthday
Above is the exact order of the fields from student table. When I retrieve this info using Adox.Catalog, it is sorted alphabetically. So what I get is birthday,first_name,initial,last_name,student_id. But I don't want this. I want it sorted the way it is on my table definition. Is there a way that will not sort this info? After getting the field info, I add it to a collection.
Thanks you!
Maximum Items In A Collection
Hi Guys,
Just out of curiosity, what is the maximum no. of items in a collection? Or how many items can a collection can store? I tried google already but I can't find any answer from there.
Also, is it possible to limit the usage of memory my own program? If possible, pls. tell me how to do it.
TIA!
Changing Items In A Collection
I have a collection where I store Data from a database. I then parse the collection into an array and then put the array in a listview with a function that is in a dll that is used.
In this collection i store the screens and the access permissions for those screens for a specific group.
For example the output to a list view for the administrator would be
Job Maintainence Full Access
Scheduling Full Access
If i wanted to parse the collection into an array how could i then change a "full accesss" to a "read Only access" or "No Access" When the user clicks the appropriate button?
Linking Items In Listbox With Collection
In my program I have a collection class and a listbox. The items in the collection class have a string value (a name if you like, which can be the same for multiple items in the collection) and a unique identification number (never the same for more than one item). Because the number is always unique I’m using this as the Key for each item in the collection.
I’m using the listbox to display each item in the collection so the user can click the list to bring up all the stored properties of the clicked item. However I need to display the string value of each collection item in the list, as displaying the unique id number would not be very useful to the user. As I said the string can be the same for different items, so what I need to know is how to link together the items in the listbox with the items in the collection.
At the moment I’m using the fact that the index property of an item in the listbox is 1 less than the index of the item in the collection (since the collection runs from 1 to max and the list runs from 0 to max). This is a little restrictive however, for instance if I wanted to rearrange the items in the listbox, to sort them alphabetically, the indexes would change and I wouldn’t be able to link the listbox items to the collection items. Unfortunately the listbox control doesn’t seem to let you specify a key for each item added to it or I would just use the unique ID as the key for this too, then you could link them.
Is there a way to solve this problem? Or am I going to have to look at using a different control than the listbox.
Displaying Items From Collection In A Listbox
how is it possible to display all items in my collection in a listbox
here is my code
Dim Employees As New Collection
Private Sub Form_Load()
Employees.Add 5400, "Neville Kalebi"
Employees.Add 3300, "Andrew Denousse"
Employees.Add 3300, "Dean Delcy"
Employees.Add 3500, "Mervin Albert"
For Each Employees.Count In Employees
lstCollection.AddItem Employees.Count
Next
appreciate the help
thks
Maximum Collection Object Items
Hello
I am interested if anyone knows the maximum number of items that can be held be one collection object.
Any help would be appreciated.
Kevin
Deleting Duplicate Items From Collection?
how to delete or find out duplicate items from a collection. i mean looking for a fast alogorithm which can do this.. or do you know how to catch the error when a duplicate key is added to a collection?
Sorting MS Outlook's Folder.Items Collection
I’d like to sort mail items from an Outlook folder before I populate a grid,
So, I’ve invoked the Sort method of Items collection of that folder:
oFolder.Items.Sort "ReceivedTime", True
(The result should have been a descending list of mail items sorted by ReceivedTime property)
But here’s the actual result (just Received times):
18.04.2003 22:03:29
15.07.2003 10:03:31
18.07.2003 12:42:46
25.07.2003 17:23:12
17.07.2003 10:34:01
20.07.2003 15:17:47
28.07.2003 16:59:54
01.08.2003 13:00:59
25.08.2003 10:45:08
29.08.2003 10:25:15
03.09.2003 13:43:34
09.09.2003 11:41:14
Only month order is correct but it’s ascending!
What went wrong? Any ideas?
Need To Identify Connectivity Among A Set Of Items In A Collection Object
I need some help
I have a collection object mCol whose items consists of the following in which sFrom and sTo are string while index is an integer. In this example the mCol consists of 6 items but it can be more (or less). The input for this problem is starting and ending point. For example the input for the example below is id1 and id6.
sFrom sTo Index
item1: id1 id2 1
item2: id1 id3 2
item3: id1 id4 3
item4: id2 id5 4
item5: id4 id5 5
item6: id5 id6 6
I need to find the number of ways id1 is connected to id6, i.e. the output will be displayed as follows:
id1 id2 id5 id6
id1 id3 id5 id6
id1 id4 id5 id6
The output will be stored in a variable dynamic two dimensional array. Can anyone suggest me a good approach? Please note that the approach have to general and should work for any starting and ending point given a certain set of items.
3265 Items Cannot Be Found In Collection - Sometimes Works?
Stumped on this one. I keep getting the 3265 error "Item cannot be found in the collection".
What is weird is that all my other executions of the stored proc work except for this one.
cn.Open "Provider=sqloledb;Data Source=LAPTOP;Initial Catalog=Production;User Id=sa;Password=sa;"
' Get the next key
SQL = "spGetNextKey('grp')"
Trace (SQL)
Rs.CursorType = adOpenKeyset
Rs.LockType = adLockOptimistic
Rs.Open SQL, cn, , , adCmdStoredProc
grpId = Rs("keyId")
Rs.Close
it bombs on the grpdId = rs("keyId") line. 3265 item cannot be found in the collection
the weird thing is that if I execute this code:
' Load the group type combo
SQL = "spGetType(12)"
Set Rs = cn.Execute(SQL)
frmMain.lstgrpType.Clear
Do While Not Rs.EOF
frmMain.lstgrpType.AddItem Rs("typTypeDesc")
frmMain.lstgrpType.ItemData(frmMain.lstgrpType.NewIndex) = Rs("typTypeId")
Rs.MoveNext
Loop
Rs.Close
it works fine.
The only difference is that the second (the one that works) returns values right from the table itself.
But the first (the one that does not work) calcs a value then returns it.
I'm finding bits and pieces about CAT? on the net but not sure what it does or if it'll help.
----------------------
Update... I got it to work by first returning the table value, then updated my next count, blah, blah.
Anyways it has got something to do with this 'catalog' value in ADO.. what does it do? WIll I be able to create stored procs that do strict calculations (no table stuff) and get the value back?
Easy (???) Swap Items In A Collection Question
Hi there, I have this ridiculous problem that I just can,t resolve!
I have a collection, and I wish to swap two elements. I tried this:
Code:
Set pCol.Item(lngFirst) = pCol.Item(lngLast)
but it just won't work.
How should I do this?
Find Method Of Items MAPIFolder Collection
hi all...
i'm trying to open an Outlook email using the Find method of Items collection from an Outlook.MAPIFolder
VB Code:
Set oApp = New Outlook.Application Set oNS = oApp.GetNamespace("MAPI") Set oInbox = oNS.GetDefaultFolder(olFolderInbox) strFilter = "[EntryID] = '00000000A11992B52436EE47A7D2CD13200DE9910700B36B58C5B04BD511A1DA00E018C46C90000000543FCC0000B46B58C5B04BD511A1DA00E018C46C900000027A05100000'" Set myItem = oInbox.Items.Find(strFilter) myItem.Display
but vb sends me the following error :
The property "EntryID" in the condition is not valid.
when removing the single quotes ( ' )
VB Code:
strFilter = "[EntryID] = 00000000A11992B52436EE47A7D2CD13200DE9910700B36B58C5B04BD511A1DA00E018C46C90000000543FCC0000B46B58C5B04BD511A1DA00E018C46C900000027A05100000"
the error is :
Unable to parse condition.Error at A11992B52436EE47A7D2CD13200DE9910700B36B58C5B04BD511A1DA00E018C46C90000000543FCC0000B46B58C5B04BD511 A1DA00E018C46C900000027A05100000.
pls note that when using
[Subject] field in search criteria (e.g. strFilter = "[Subject] = 'Info'" )
works great ...
what am i doing wrong ? ... any help .?
Adding Items To A Collection, Properties Are Changing On The Fly
I have the following code in a module:
Code:Dim SearchTypes As New clsFindParams
Dim AllSearchTypes As New Collection
Sub InitSearchTypes()
With SearchTypes
.BaseText = "C"
.NumLeftChars = 0
.NumRightChars = 6
.ReplString = "CXXXXXXXX"
End With
AllSearchTypes.Add Item:=SearchTypes, key:=SearchTypes.BaseText
With SearchTypes
.BaseText = ".txt"
.NumLeftChars = 24
.NumRightChars = 0
.ReplString = "XXXXXXXX.TXT"
End With
AllSearchTypes.Add Item:=SearchTypes, key:=SearchTypes.BaseText
End Sub
and the following in a class (clsFindParams):
Code:Public NumLeftChars As Byte
Public NumRightChars As Byte
Public BaseText As String
Public ReplString As String
My objective is to make a collection of "SearchTypes". I find that after the first "ADD", there appears an item in AllSearchTypes with, in this case, the property "BaseText" = "C". As the next set of code executes, setting the values of "SearchTypes" to the next item's specifications, I can see the properties of the first item changing to these new values.
What do I have to do to add a NEW value (the second item in my code above) without the first item changing?
|
+--JDMils
|
+--VB6
+--VB Dot Net
|
+-- Navman GPS Forums @ http://forum.jdmils.com
|
Sorting MS Outlook's Folder.Items Collection
I’d like to sort mail items from an Outlook folder before I populate a grid,
So, I’ve invoked the Sort method of Items collection of that folder:
oFolder.Items.Sort "ReceivedTime", True
(The result should have been a descending list of mail items sorted by ReceivedTime property)
But here’s the actual result (just Received times):
18.04.2003 22:03:29
15.07.2003 10:03:31
18.07.2003 12:42:46
25.07.2003 17:23:12
17.07.2003 10:34:01
20.07.2003 15:17:47
28.07.2003 16:59:54
01.08.2003 13:00:59
25.08.2003 10:45:08
29.08.2003 10:25:15
03.09.2003 13:43:34
09.09.2003 11:41:14
Only month order is correct but it’s ascending!
What went wrong? Any ideas?
My Collection Object Is Repeating Its Items Like A Bad Burrito
The parts of my program that are relevant to my problem are: a ListView control and 2 Collection Objects. Collection one holds objects (weapons, specifically) created upon running the program. Collection two is the player's personal inventory of weapons and hold what is taken out of C1. The ListView displays the contents of C2.
As I'm testing the program, I use 2 different weapons (knife and gun), but the ListView displays 2 guns (the 2nd object created and transferred). With no desire to list all the code, here is a short idea of what I've done:
1. create knife and add it to C1
2. transfer knife from C1 to C2
3. remove knife from C1
4. create gun and add it to C1
5. transfer gun from C1 to C2
6. remove gun from C1
7. display C1's objects in ListView
(btw, I'm using a Colection as C1 because later in the program there will be more than 1 object at a time for the player to choose from)
Now, why is it that I'm seeing 2 guns listed in my ListView? When coding the display, I iterate through the objects in C2. Can someone help me? Either ask me for more detail if you need it or if there is a simpler way to handle this, just tell me. Thanks in advance for any help given.
Disabling Menu Items When Using Collection Array
I have a parent form with a menu, and I want some of the menu items disabled when a child form is opened. The book I am learning from only gives an example for unique named menu items, not arrays. Is there a way to disable one menu item when an array was used. Thank you in advance.
Catrina
VB 6.0/Outlook 2000 - Adding Items To A Pst File Collection
I am trying to add Outlook contact items to a pst file. I am using the Outlook object model. I have created a pst file programmatically using the AddStore method. This appears to create an empty file. I have a folder of Outlook contact items that I need to add/save/move to the pst file. I read a post here that says you need to walk thru the contact items collection and add them to the pst file items collection. Can anyone provide an example of how to do this?
I know how to loop thru the contact items but cannot find a method that adds items to the pst file
TIA
KT
Collection, String, Listbox? Want To Add Only Unique Items Constantly To An Array
Basically heres what my program does.
Every 10 seconds a file is generated (by another program) that contains a list of items.
I need to make a program that opens this file, and takes all the items and add each to an array - making sure that only unique items are added to this array.
For example - my program's array contains 'hello, test, vb, google'. It opens up the generated file which contains 'television, hotmail, radio, toaster, hello, calendar'. It needs to append this list, so the array now contains 'hello, test, vb, google','television, hotmail, radio, toaster, calendar' (note hote 'hello' was not added twice). It then removes the generated file so the next time its opened it has (somewhat) fresh new items.
But the array will be very big and my program needs to save its array to a file every few minutes.
What would be the best way to do this? using a listbox? (setitng it to visible = false, and using API (LB_FINDSTRINGEXACT) to add unique items) a collection (but its very large and memory intensive)? a string (but i dont know if there are quick ways of adding unique items to a string array, and i really dont think looping through thousands of items all the time will be efficeint)
Any help would be appreciated
Vb Error No. 3265 "Items Cannot Be Found In This Collection"
Whenever l select a record from the database l get the above error of 3265. I am using access database and l have four databases hence my four select statements. The error only occurs when records are read from the database. Below is my code.
SQLStr = "Select PlannerManager1.[LM_Fore_Name], PlannerManager1.[LM_Initial], PlannerManager1.[LM_Last_Name], PlannerManager1.[LM_OUC] from UnrecordedEstimates, PlannerManager1 where UnrecordedEstimates.[SentMailStatus] = 2 and UnrecordedEstimates.[Status] = 'K' and UnrecordedEstimates.[FIRST_NAME]= PlannerManager1.[Forename] and UnrecordedEstimates.[SURNAME_PLANNING]= PlannerManager1.[Surname] and UnrecordedEstimates.[JOB_PLNG_ETG_OUC]= PlannerManager1.[OUC]" 'Louise"
Dim dbs As Database
Dim Rs As Recordset
Dim Finalstr As String
Select Case mDBName
Case LASERDB_B 'this is the Bromley database
Set dbs = OpenDatabase("C:LaserBromleyLaser(b).mdb")
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.ManagerList.Clear
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.Frame2.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
Rs.MoveNext
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
Case LASERDB_C
Set dbs = OpenDatabase("C:LaserCroydonLaser(c).mdb") 'this is the Croydon database
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.ManagerList.Clear
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.Frame2.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
Rs.MoveNext
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
Case LASERDB_P
Set dbs = OpenDatabase("C:LaserPortsmouthLaser(p).mdb") 'this is the Croydon database
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
frmMail.lstMailPlanners.Clear
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.ManagerList.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
frmMail.Frame2.ZOrder
Rs.MoveNext
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
Case LASERDB_S
Set dbs = OpenDatabase("C:LaserCroydonLaser(c).mdb") 'this is the Croydon database
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.ManagerList.Clear
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.Frame2.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
End Select
Vb Error No. 3265 "Items Cannot Be Found In This Collection"
Whenever l select a record from the database l get the above error of 3265. I am using access database and l have four databases hence my four select statements. The error only occurs when records are read from the database. Below is my code.
SQLStr = "Select PlannerManager1.[LM_Fore_Name], PlannerManager1.[LM_Initial], PlannerManager1.[LM_Last_Name], PlannerManager1.[LM_OUC] from UnrecordedEstimates, PlannerManager1 where UnrecordedEstimates.[SentMailStatus] = 2 and UnrecordedEstimates.[Status] = 'K' and UnrecordedEstimates.[FIRST_NAME]= PlannerManager1.[Forename] and UnrecordedEstimates.[SURNAME_PLANNING]= PlannerManager1.[Surname] and UnrecordedEstimates.[JOB_PLNG_ETG_OUC]= PlannerManager1.[OUC]" 'Louise"
Dim dbs As Database
Dim Rs As Recordset
Dim Finalstr As String
Select Case mDBName
Case LASERDB_B 'this is the Bromley database
Set dbs = OpenDatabase("C:LaserBromleyLaser(b).mdb")
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.ManagerList.Clear
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.Frame2.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
Rs.MoveNext
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
Case LASERDB_C
Set dbs = OpenDatabase("C:LaserCroydonLaser(c).mdb") 'this is the Croydon database
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.ManagerList.Clear
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.Frame2.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
Rs.MoveNext
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
Case LASERDB_P
Set dbs = OpenDatabase("C:LaserPortsmouthLaser(p).mdb") 'this is the Croydon database
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
frmMail.lstMailPlanners.Clear
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.ManagerList.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
frmMail.Frame2.ZOrder
Rs.MoveNext
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
Case LASERDB_S
Set dbs = OpenDatabase("C:LaserCroydonLaser(c).mdb") 'this is the Croydon database
Set Rs = dbs.OpenRecordset(SQLStr, dbOpenSnapshot, dbReadOnly)
If Rs.RecordCount > 0 Then
Rs.MoveFirst
frmMail.ManagerList.Clear
While Not Rs.EOF
Finalstr = ""
Finalstr = Finalstr & Rs!LM_Last_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Initial
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_Fore_Name
Finalstr = Finalstr & ","
Finalstr = Finalstr & Rs!LM_OUC
frmMail.ManagerList.Clear
frmMail.tbsProcess.Tabs(2).Selected = True
frmMail.Frame2.ZOrder
frmMail.ManagerList.AddItem (Finalstr)
Wend
Else
MsgBox "No records found."
End If
Rs.Close
dbs.Close
Set Rs = Nothing
Set dbs = Nothing
End Select
Character Counting, Line Counting And Saving RTB Files Without Formatting
Hi,
I quickly need to get a bit of help with the 3 things mentioned in the topic title:
Character Counting
When the RichTextBox is changed I want a label's caption to be changed so it counts all characters in the RTB. Not just words, I mean as in each and every letter, space, etc. I searched and search, and found nothing.
Line Counting
I also want, when the RTB is changed, for another label's caption is changed and now says how many lines are in the RTB. I tried doing this myself with getting the label's caption to be +1 for every time enter (vbCrLf) is clicked or used, but that didn't work and properly wouldn't do what I need it to do anyway.
Saving through a RTB without formatting
Basically, when you use the "SaveFile()" Protocol in a RTB it saves, yes, but it has formatting, like so:
Code:
{
tf1ansideff0{fonttbl{f0fnilfcharset0 MS Sans Serif;}}
viewkind4uc1pardlang1033f0fs17 [b]|<b>
par line 2
par line 2
par line3
par
par }
Which isn't what I want it to do, I just want it to save it like a normal text file, no formatting, just text, is there a way to override it's default action to do the above formatting?
Thanks in advanced.
Sort Data From An Existing Collection And Save It Into Another 2nd Collection
Hi,
have a huge problem. I have an existing collection and would like to use this collection to save some data from it into another collection.
The Problem is: in the 2nd collection I only have e.g. 5 times the same number. I'm using an if-loop for that, maybe the reason for it...
But before, I just try to explain a little of the structure (otherwise maybe my words doesn't make much sense to you).
My already working 1st collection has some properties which I fulfilled via an SQL-recordset.
I just want to use this information to 'sort' it in order to allow a correct graphical and hierarchical presentation (via an algorithm) on the screen -> like an organigram.
My 1st, working collection looks like:
Code:
dim x as my_object
Dim records As ADODB.Recordset
Dim sql1 As String
Dim strCnn As String
Dim my_collection As New Collection
Set records = New ADODB.Recordset
strCnn = "Provider=some;User ID=one_user;Password=one_password;Persist Security Info=True;Initial Catalog=server;Data Source=server"
sql1 = "SELECT ...................."
rs_app.CursorLocation = adUseClient
rs_app.Open sql1, strCnn, adOpenKeyset, adLockOptimistic, adCmdText
While Not records.EOF
Set x = New my_object
If IsNull(x) = False Then
x.my_key = records("my_key").Value 'ist eine Eigenschaft
x.my_overkey = records("overkey").Value
my_collection.Add x
records.MoveNext
Else
End If
Wend
-> So far so good, that works!!
HOWEVER, if I furthermore would like to sort that after a special criteria (e.g. just save all "my_key's" in another collecton, which have the "my_overkey" number "0815" then won't work.
If I have 5 numbers (which belong to 0815) then I get 5x the same my_key - number. I guess the reason for that error is the if-loop.
Does anybody know an solution/a better way for that? ?
my solution looks like:
Code:
dim collection2 as new collection ' defined via class-builder
set collection2 = new collecton
For i = 1 To my_collection.Count
'type_app habe ich dann als "0815" definiert
If my_collection.Item(i).my_overkey = type_app Then
y.my_key = my_collection.Item(i).my_key
y.my_overkey = my_collection.item(i).my_overkey
collection2.Add y
end if
next
Would be very grateful for any suggestion!!
Thanks
new_one
|