Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Array Handling, Adding Item, Deleting Item


Hello,

I was going to build a "buffer" and thought array would be a suitable way.
when the form loads the ArrayStart is set to 0

when data is coming in it is added to the array:

MyArray(ArrayStart)= data
ArrayStart= ArrayStart + 1


Now i would like to find out whether there is any data in this array
if there is im doing something with that data

but then i would like to simply delete that data from the array

how do do this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Menu Item Deleting (Control Array)
Hi there,

I'm a bit stumped.

As you can see below i've built a procedure to add items to my control arrayed menu, but the problem is how do I delete 1/all the items when i need to, but I must be able to add to this arrayed menu again, this is because if a client disconnects the menu item for it should be deleted also.


Code:
Private Sub CreateMenu()
Dim A As Long
Dim B As Long
Dim EnabledStatus As Boolean

For A = 0 To BuddyList.BuddiesMax - 1
info = Split(BuddyList.RetreiveBuddy(A + 1), "::")
For B = LBound(Chat) To UBound(Chat)
EnabledStatus = False
If Chat(B).BuddyEmailAddress = info(1) Then
EnabledStatus = True
Exit For
End If
Next B

If A = 0 Then
mnuBuddy(0).Caption = info(2)
Else
Load mnuBuddy(A)
mnuBuddy(A).Caption = info(2)
End If

If EnabledStatus = True Then
mnuBuddy(A).Enabled = False
Else
mnuBuddy(A).Enabled = True
End If

Erase info
Next A

End Sub

the pig..

Adding One Item To An Array (like A Stack)
Say I make an array called myArray by saying:

Code:
Dim myArray() as Variant


Now, if I want to just add an entry at a time (kinda like a stack in other languages) should I say:

Code:
Redim Preserve myArray(Ubound(myArray) + 1)

myArray(Ubound(myArray)) = SomeNewValue


A few questions:

Is there an equaivalent to a STACK in VB? Then I can just push a value onto the stack.

Is redimming the array everytime a waste of resources? My array will only contain about 300 items at most.

Should I just dimension the array to something like Dim myArray(1000) and use another global varaible (like myArrayLastRecord) to keep track of the current record? This seems kinda like a ghetto way of doing this though.

Thanks, Dave.

How To Search Listbox For Item If Item Not Found Add Item?
Hi, lol man I cant find nothing today when I search the forum.

This my latest problem, How do I search a listbox for an item lets say "Game Over" And if the item is found the program does nothing, but if the item is not found it will add "Game Over"

Thanks Again

Handling The First Item In A Listbox
Hey guys,

Just got a quick question as to how I work around this.

The easy part I've got down ... that of putting the value ListIndex of a Combo Box. The issue I've got here is that the user can quite legitimately not select an item from the list. The problem is that the ListIndex will then become zero - and when brought back up on screen, will automatically display the first item in the list.

What's the best way of setting it up so that if the user doesn't select an item, it actually puts a null value in instead?

Deleting An Item From A Range
Hello I will try and explain my problem.
I need a way of deleting an item from a list direct from a current userform. The list is a range on a worksheet that is copied to a listbox to amend and update.
I would like a button to delete the item selected in the listbox and the worksheet list Range would then be sorted the gap removed and renamed to suit. Thanks

Deleting A Listview Item
Hey all, it's me again I'm having a very frustrating problem. I have a listview and a commnd button (For the sake of this question). In the list view I have a bunch of items, one of which I want to delete. So I select the unwanted item, click on my command button containing this code:

Code:
If ListView1.SelectedItem.key > "" Then
ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
End if
And a item is gone.....one small catch is the item that gets deleted isn't the one I selected. It looks like it deletes the item after it, but I don't know why I would have to make it selectedItem.index + 1. Can anyone tell me what i'm doing wrong here? This is driving me nuts.

Deleting ListBox Item By Name
How?

How do I delete a listbox item by name?

Deleting An Item From A Combo Box
Can anyone tell me how to delete a selected item from a combo box? Say I have a name, let's say Howie in a combo box.....How can I tell it to delete it out of the list instead of just deleting the text from the text box portion of it? Whatever is selected in the combo box, I want to be able to delete it from the list.

Thank you!

Deleting An Item From A List
Hi all,

I'm currently writing a program where you can add items to a listbox, and there is a button to delete the highlighted item. I have tried to do it similar to:


Code:
Private Sub Delete_Click()
Dim DelMe as string

DelMe = List1.selected
List1.remove(DelMe)
End Sub


Well, that's really the pseudocode for what I'm trying to do. Obviously it won't work, since I must specify an index. However, I will not know the index, since it depends on which item the user clicks.

How do I do this?

Thanks

Deleting An Item In A Listbox...
hello,

I have a listbox in my project.
I want to delete items from it, so that the other items, that were below
the item I have deleted will go up and take the place of the deleted item.
how can I do that?

thanks

Deleting Item From Flexgrid
I have two columns in a flexgrid, i need it so that when i click on an item, it will remove just that item, not the row or column. Because there is two column, it needs to be able to tell which to delete from

Heres what i have thus far:

VB Code:
Private Sub cmdRemove_Click()    Dim currentRow As Long    Dim currentCol As Long    currentRow = grdFields.Row    currentCol = grdFields.Col    RemItem = grdFields.TextMatrix(currentRow, currentCol)    grdFields.RemoveItem RemRowEnd Sub


when i try ths, it always removes the first row. I dont think that the textmatrix control is used in the right context when doing this, but anything else i tried didnt work either.

Deleting Item In Listbox
hi there

another noobish question of me. I am trying to delete a value in my listbox when i have selected it.

My code:
Code:if list1 = "" then
    msgbox "Nothing selected"
else
    list1.removeitem()
end if

I've tried already so many thing but nothing seems to work.

Can anyone help me please? THanks!!!

REALLY Deleting A Mail Item
Hi,

I'm writing some VB to delete junk mail from my Inbox. I go through all the items, and if one of them meets my criteria, I do:

        f.Items(i).Delete

where "f" is the MAPIFolder I'm looking through. However, what this code seems to do is to move the mailitem to my Deleted Items folder. What's the easiest way to make it actually delete the item? Thanks.

Ernie

Deleting Item From Combobox When Selected
Hey all,

When I select an item in a combobox I want to delete that item from the combobox so that it can't be selected twice.

Cam.

Deleting A Selected Item From A Listbox
Hi there,
I`ve just joined this forum. I was wondering if anyone could help me?

I`ve made a listbox, populated with data from a table in access, with the column heading test.

I want to be able to select an item from the listbox, click on a button and then delete the item from the listbox and database. I have managed to do this, however the item deleted from the database is the first item and not the selected.

Any ideas?

Heres my code....


Private Sub CommandButtonDelete_Click()

Dim vConnection As New ADODB.Connection
Dim vRecordSetTest As New ADODB.Recordset
Dim vConnectionState As Integer

Set vRecordSetTest = New ADODB.Recordset

vConnection.ConnectionString = "data source=G:FilingLabel.mdb;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;"

vConnection.Open

vRecordSetTest.Open "TableTest", vConnection, adOpenKeyset, adLockOptimistic

vRecordSetTest.Delete
ListBox1.RemoveItem ListBox1.ListIndex

End Sub

Help... Deleting Item From Listbox & Database
Hi,

How can I delete an item from the listbox and database at the same time? For example: If I delete apple from the listbox, it should also be deleted from my database.

Selectin And Deleting Item From Listbox
Can someone help?

I cant remember how to select an item from a list box with the mouse and then click on a button to delete it.

I know its a simple procedure but it has lsippedmy mind!!!

Cheers!!

Deleting A Selected Item From A Listbox
what's up fellow programmers! i wanted to know if there's a way to delete a selected item from a listbox. can anyone help me here? thanks!

Help... Deleting Item From Listbox & Recordset
Hi,

How can I delete an item from the listbox and database at the same time? For example: If I delete apple from the listbox, it should also be deleted from my database.

Deleting Selected Item From A Listview
Hi,

I want to delete selected items from a list view.

Please help me with this.

thanks

Help... Deleting Item From Listbox & Database
Hi,

How can I delete an item from the listbox and database at the same time? For example: If I delete apple from the listbox, it should also be deleted from my database.

Thanks...



Edited by - gen23 on 4/22/2004 10:19:42 PM

Outlook 2000 Deleting More Than One Item
Let's say:

I loop thru the Inbox and put items in a ListView.
e.g. I find 100 items that I want to process.
I delete item # 50
Can I still acccess (.Display, .Delete, etc.) any item in list that was below the deleted item or have they been renumbered by Outlook?

I remember reading something about the item numbers being renumbered after a delete.
Can I delete more than one item without refreshing the list again?
Obviously I do not want to delete item 99 only to have Outlook delete item 98.

Here's what I'm doing:
Code:Private Sub ProcessOutlookInbox()
  Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
  oitems = 0
  mItems = 0
  ListView1.Sorted = False
  Items = oFolder.Items.Count
  Label1.Caption = mItems & " of " & Items
  ProgressBar1.Max = Items
  ProgressBar1.Visible = True
  For Each oMsg In oFolder.Items
    With oMsg
      oItems = oItems + 1
      ProgressBar1.Value = oitems
      If InStr(1, .Categories, "Adv") > 0 Or _
         InStr(1, .SenderName, "Adv") > 0 Then
        mItems = mItems + 1
        Label1.Caption = mItems & " of " & Items
        ListView1.ListItems.Add , "k" & oitems, oitems
        ListView1.ListItems.Item(mItems).SubItems(1) = .Subject
        ListView1.ListItems.Item(mItems).SubItems(2) = .SentOn
        ListView1.ListItems.Item(mItems).SubItems(3) = .To
      End If
    End With
  Next
  ProgressBar1.Visible = False
  ListView1.Sorted = true
End Sub

John

Edited by - o1sowise on 4/21/2004 8:15:56 AM

Deleting A Selected Item From A ListView And Access Database
I have the following code:

VB Code:
Private Sub cmdDelete_Click() Set rst = New ADODB.Recordset Dim sKey As String sKey = ListView1.SelectedItem.Key Sql = "DELETE FROM producer Where producerId=" & Val(sKey)db.Execute Sql, sKey If sKey = 0 Then'Do NothingElseMsgBox "Item Deleted"End If End Sub


I have been trying to use it but no results. The code gets executed but no deletions are made from both the ListView and the databse. What could be wrong? Can you offer me an alternative code?

Click Item In Listview Then Show That Item In Combo As Index = 0
Hi guys,

I have a listview (lvwUserPunchedOut) that is populated with records in a database (persons first name in one column and last name in the second column), what I am looking to do is if I select a persons name by clicking on it in the listview on frmMain, and then bring up frmSearchCriteria, i would like to show that selected name in the combobox as default (cboEmployee.ListIndex = 0) on frmSearchCriteria (the combobox is sorted = True and is also populated with first name and last name of the person)

How would this be done? Hope I make sense. Thanks in advance.

Adding Item In VB
Hi,
what command to additem and its index into my combo box?





Programmers are the laziest people around.

ComboBox List/add Item, If Item Exists, Dont Add It Again!
Dudes and Dudeesses I need help!

I have a problem with a combobox within a form. I'm scanning down the spreadsheet for values and asking a combobox to .additem, however, the same value may appear twice whilst scanning down. Is there an if statement that will look and check the combobox to see if it is already added, if so dont add it again, if not, add it?

as below,

Code:
combobox.AddItem "Hotmail"
combobox.AddItem "Yahoo"
combobox.AddItem "Hotmail"
Hotmail will be added twice, how can I stop that?

If worst comes to the worst, I can sort it out with a long winded method, but I'm hoping theres a quicker way.

Thanks for all your help

Pointing Mouse At Some Item On Form Causes Info About This Item To Appear???can This
my question is that when you point the mouse at some item on the form you get some info about this item to appear, like on html page or for example when you point to the message icons in vbforum page like the lightbulb symbol it tells you that it is a lightbulb...can this be done in visual basic....

Select Item In ListBox1 And Corresponding Item In ListBox2 Is Also Selected
Hi,
Hi I have two Listboxes list1 has lets say Firstname in List1 and List2 has surnames.
How do I select an item in List1 and have it's corresponding item in List2 selected as well?

So if I select Item 6 in List1, I want item6 in List2 to be selected too.

Ken

Adding An Item To A List Box
I am currently working on a project with college and want to add items chosen from a combo box to a listbox along side it. I am using Access to create the Database.

However, when I come to enter the following code, the syntax isn't correct. I have a feeling it may be because i'm using VBA as opposed to VB6 and I know that some of the coding is slightly different. Below is the code I am using to add them.


Code:
lstCoursesTaught.AddItem "Computing"
However, the VB Editor doesn't recognise the .AddItem section. It only displays .AddColon. Can anybody help me with this problem?

Thank you

Adding An Item To The Combobox At The Top
I guess that answered the original question, but lets add a twist.

I need to add to a list box where the newest data it put on top. When the newest data is on top, the exisiting info gets shifted down one space(index).

I am recording baseball scoring events. When something happens, that event is at the top of the list box, then previous events will be listed below it. [Sort by newest event] I do not have items for the list box al at once, they will be added periodically.

I was hoping I could just set the list box behavior to somehow display it that way. Otherwise, I was going to add the newest event to the top with additem and a index of zero, then loop through all of the items of the listbox and add one to the index so they would shift down.

**************MORON ALERT*********************
When you add an item to index 0, all of the other items will be moved down. See what happens when you read? M S D N!

Adding Item To ListView
Is it possable to add items to a listbox on new lines? Below is what I've set up but it doesn't work. Any suggestions?

Line 1 would have Date Of Party and Line 2 would have Time Of Party.

Code:
List1.AddItem rsInformation.Fields("Date Of Party") & "vbCrLf" & rsInformation.Fields("Time Of Party")

Adding An Item To The Combobox At The Top
Hi all,

When I am adding items to a combo box, it adds them to the bottom of the list. Is there a way to add the items at the top of the list instead? So instead of:

Code:
1
2
3
4
5
I would have:

Code:
5
4
3
3
2
1
Thanks!

Adding Item To FlexGrid
I am using the following code but it tells me Run-time error '424': Object Required. Can any one tell me what I'm doing wrong?


Private Sub cmdAdd_Click()
FlexGrid.AddItem txtSymbol & vbTab & txtAccount & vbTab & txtName
End Sub

Speed Up Adding Item
i have noticed that when you add an item to the listbox it is slower the bigger the string is. is there any way of speeding this up. i have tried sendmessage but still no difference.

thank you.
casey.

Adding An Item To A Listbox.
I want to add an item to a list box from within the program. i though this code would work.

Private Sub Command2_Click()
List1.AddItem = textbox1

End Sub

The idea was to add whatever was in textbox1 to the list

ADO Problem~when Adding Item!
Code:
Dim MyConn As ADODB.Connection

Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:program fileslibrary managerand1.mdb;"
MyConn.Open
MyConn.Execute "INSERT INTO books(number) VALUES ('123')"
MyConn.Close
database is ok, i can read but i get Syntax error in INSERT INTO statement when i want to add item from this code!

please help,
the field type is ok as well!

Ado Error When Adding Second Item
I am writing a simple data input utility with ado dateenvironment, and I can delete items repeatedly, but if I add one item I can no longer delete or add without getting this message. Please help me.

Current recordset does not support updating. This may be a limitation of the provider, or the selected locktype.

Tom

Adding Item Into Combo_box
hihi..

i am currently adding item from my MySQL database into the combo box. however, its keep adding the item without refreshing it when the search change.

e.g

if fruit is selected, all variety of fruits will be added into the combo box. however, if i decided to choose food instead, the food variety should be added into the combo_box and cleared the previous fruits items in the combo box which left only the food variety.

i have tried to insert this at the combo box text change--->

[vb code]combo1.additems.clear [/vb code]

at the beginning of the function before executing the adding process. The result was, i cant type on the combo box.

???
ocw?

Adding LisTview Item..
in adding item on listview, can i select that the first item forecolor is red and the remaining item(s) is black?

Adding An Item To A Listbox
I have a listbox with items in it. I want to add another item to it but I want it to slot in at index position 3 in the list. There are already 8 items in the list. How can I do this?
Thanking you in advance
PORRASTAR

Adding Item To A Combo
It is possible to add item to a combobox at running time and keep that item forever?

Listview - Adding An Item
Help....why won't this work?

Dim itemAdd as ListItem
Set itmAdd = ListView1.ListItems.Add(Text:=sNext)

I get a type mismatch. sNext is a string

Adding Item From One Table To Another
‘Microsoft.Jet.OLEDB.4.0

Private Sub cmdadd_Click()


Adodc1.Recordset.MoveFirst
If Adodc1.Recordset.BOF = True Then
Adodc1.Recordset.MoveFirst
End If
If list1.ListCount < 4 Then
Adodc1.Recordset.Find ("assigned ='n'")

list1.AddItem projectnumber + " " + priority + " " + difficulty + " " + employee ‘I have a txt box named employee
assigned = "y" ‘ this changes the database field


It does populate the list showing the fields I want and changes the access table assigned to "y".

I am trying to get just those assigned projects into a new table within the same access database as the list populates but I can’t.

I’ve tried using adodc2 attached to the other table for employee2

I’m sure its easy but just learning. Can someone give me a hand?
Thanks.

Removing An Item From A ListBox By Clicking The Item
Hi, How do you remove an item from a ListBox by simply clicking the item u want to be removed?

This is the code i tried but it doesnt work:

Private Sub list1_Click()
Dim n As Long
Dim ncount As Long

ncount = List1.ListCount - 0
For n = 0 To ncount
List1.RemoveItem (n)
Next
End Sub

Any ideas?


-Flaw

Single Item List Box (item Not Really Selecting)
Application=Access2002

The following code has worked for me in the past but won't now for some reason.
I have a private function and/or subs that performs a few simple operations such as setting listbox rowsources and simple math functions on a form. The queries set as rowsource use criteria from other single item listboxes.
Now, for some reason, the queries won't return values until the previously .selected(0) = true (single item) list boxes have been clicked on.
Problem has only been in creating a new form. Perhaps the problem did not occur in older created forms due to compatibility?


Private Sub fraEWTo_AfterUpdate()

[Edited]
    lstRotorHoursPriorTo.RowSource = "qryRotorSwapHoursTotTo" 'gets hoursprior from tblRotors
    lstRotorHoursPriorTo.Selected(0) = True ' This is one place where the problem seems to exist, the control does not function until it has been clicked on via mouse.

    LstClockInTo.RowSource = "qryRotorSwapRAHoursIPTo"
    LstClockInTo.Selected(0) = True

    txtRACHIPTo.Locked = False
    txtRACHIPTo.Value = txtClockHoursTo.Value - lstClockInTo.Value 'nor will this until the lstClockInTo box has been manually selected


A Mechanic in a Programmers shoes
Thanks




Edited by - greenfch on 12/7/2005 11:22:52 AM

Making The First Combo Box Item Always The Selected Item
Hi.

I have a combo box with a Dropdown list Style and which is invoked several times in different parts of my form. How can I make the first item in this combo box the selected item or the default item everytime I select it? Currently, what's happening is that the last item that I selected becomes the selected item the next time the combo box is invoked. Thanks for any suggestions in advance!

Listview Adding Under An Item Question
Hey all i have a listview and i am in need of adding another subitem to an item already on the list. I can do this with the following code:

Code:
Name = " +Deluxe"
Price = "$" & "0.99"
QTY = 1
thePlus = "no"

Set ListObj = LV1.FindItem(Name, lvwSubItem)
If ListObj Is Nothing Then
Set ListObj = LV1.ListItems.Add(, , QTY)
Else
ListObj.Text = Val(ListObj.Text) + QTY
End If
ListObj.SubItems(1) = Name
ListObj.SubItems(2) = Price
ListObj.SubItems(3) = Format(ListObj.Text * Right(ListObj.SubItems(2), Len(ListObj.SubItems(2)) - 1), "#.00")

Private Sub LV1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
theSelcted = LV1.ListItems.Count
End Sub
However if i have more than 1 item roll in the list it just puts the " +delexe" at the end of the list INSTEAD of putting it under where i selected the item.

How can i add the " +deluxe" under an item i've already highlighted on the list?

Any help would be great!
David

Adding An Item To The Taskbar (right Side)
I would like to know how to add an item to the rightside of the taskbar like norton 2006. Here's a pic:

http://img239.imageshack.us/img239/7193/taskbar7zx.jpg



I looked around but I couldnt find anything.

Database Adding Item To Combo Box
hi all(again) recently i've been trying to tamper with the combox.additem thing...this is wat ihave typed

Private Sub cmbMake_Click()




Select Case (cmbMake.Text)
Case "Honda"

Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "CarReg.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select CarModel from Car WHERE CarMake = Honda"


Do While Not Adodc1.Recordset.EOF

cmbModel.AddItem Adodc1.Recordset!CarModel
Adodc1.Recordset.MoveNext

Loop
cmbModel.AddItem "Other"



End Select

End Sub


what i get is a error runtime91,

may i know wwat is the problem?

Copyright © 2005-08 www.BigResource.com, All rights reserved