Remove element from arrays

Shreef

New Member
Joined
Jun 7, 2012
Messages
3
Hi everyone. I could use some help because I'm kind of a newbie with VBA. Im designing this application were you enter a barcode to text box and search a sheet for an identical match then display info in a list box and populates two text boxes "txtbox' & i and "txtbox0" & i to enter the passenger weight and bag weight. So I created an array of textboxes. The problem is with the removing a selection. The logic is based on that I name my textboxes in sequential order to be able to remove them by referring to (i) as following<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Code:
 <o:p></o:p>
Code:
[COLOR=black][FONT=Verdana]'adding row to listbox<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]v = ListBox1.ListCount<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Set tbarray(v) = Frame2.Controls.Add("Forms.TextBox.1", "txtbox" & v)<o:p></o:p>[/FONT][/COLOR]
<o:p></o:p>
Removal code<o:p></o:p>
ListBox1.RemoveItem ListBox1.ListIndex<o:p></o:p>
'because my txtboxes start at 1 I add 1 to the list index which starts at 0<o:p></o:p>
i = ListBox1.ListIndex + 1<o:p></o:p>
Code:
 <o:p></o:p>
Code:
[COLOR=black][FONT=Verdana] If i > 0 And i < 13 Then[/FONT][/COLOR]
[FONT=Verdana][COLOR=black]'remove the textboxs[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                  Frame2.Remove ("txtbox" & i )[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                  Frame2.Remove ("txtbox0" & )[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                  For f = i + 1 To 11[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                      If (Not tbarray(f) Is Nothing) And (Not TBarray2(f) Is Nothing) Then[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                          Mytop = tbarray(f).Top[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                          tbarray(f).Top = Mytop - 12[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                          TBarray2(f).Top = Mytop - 12[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                      End If[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]                  Next f[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      End If[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  End If[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]End Sub<o:p></o:p>[/COLOR][/FONT]
<o:p></o:p>
<o:p></o:p>
My problem is I can't get the code to repeat for a second removal. the row is deleted but the textboxes index are all messed up. I tried renaming the textbox but failed miserably. I also tried re-index the array but also failed. I have been googling this matter for three days now and can't find a solution. Maybe I’m doing it wrong. Really any help here would be marvelously appreciate. I hope I explained my problem clearly.<o:p></o:p>

Thanks in advance

Shreef
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Why have are you creating/removing the textboxes?

Do you want the user to enter the passenger and bag weight for each item in the listbox?

You could do that with 2 textboxes and a command button, storing the weights in the listbox in columns next to the related item.
 
Upvote 0
Hi Norie and thanks for your reply.
That would be a good idea, but I'm trying to limit the user to a few command btns so I was trying to get the textboxs to be creatwd and removed with the row. The user would have the passenger details in the list bix and would enter passanger weight directly in the corresponding textbox.
 
Upvote 0
What I suggested would only require one command button and 2 textboxes.

The user selects a passenger from the list, fills in the weights and clicks the button.

The button transfers the weights the user has entered to the columns next to the selected passenger.

The textboxes are then cleared ready for the user to select another passenger, enter the weights etc.

No need for multiple buttons or textboxes.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,404
Members
449,156
Latest member
LSchleppi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top