Array - delete and replace elements

K

kalle

Good day Group,

Need some help regarding 1 dimensional arrays. Are building an array
where
the elements are selections made in a multi listbox. Trying to find a
way to delete
an element in the array if it is deselected in the listbox then insert
a new
selection into the same place where the deselected element was.This
question
might be to inprecise to answer but are grateful for some hints. Or is
there a
better way to build a string by a listbox that can be manipultaed the
same way?

Bgds

CG Rosén
 
G

GS

kalle expressed precisely :
Good day Group,

Need some help regarding 1 dimensional arrays. Are building an array
where
the elements are selections made in a multi listbox. Trying to find a
way to delete
an element in the array if it is deselected in the listbox then insert
a new
selection into the same place where the deselected element was.This
question
might be to inprecise to answer but are grateful for some hints. Or is
there a
better way to build a string by a listbox that can be manipultaed the
same way?

Bgds

CG Rosén

Are you trying to assemble a longer string by selecting shorter string
components? If so, I'd rather use a textbox to display the result so
users can see it 'as they build'. In this case you need to query the
listbox selection (checked/unchecked) to determine whether to
add/remove/replace in the result string. I'd not go that way! Instead,
I would not use a checked list for reasons I'll explain below.

Also, there needs to be a way of delimiting each substring in the
result. I'd probably use a space character so the result builds like a
sentence or statement, though I wouldn't include the space at the end
of the substrings in the listbox. I'm thinking to add the space before
inserting new substrings.

Remove/replace can be handled easily so the delimiter spaces get
handled correctly. This precludes, then, that your Userform has
separate buttons for each action (Add>Remove>Replace>Cancel>Done>Exit).
I'd probably code it so the user could select where to add substrings
in the textbox, but that could create problems if they choose within an
existing substring. In any event, remove/replace could be handled by
selecting in the textbox, in the listbox, or a combination of the two
in the case of replace.

The Add>Remove>Replace buttons would merely set a 'Mode' variable so
the subsequent action will be processed accordingly. (This is why I
would not use a checked list) For example:

To Add a substring:
Select the position in the textbox AND/OR select the substring in the
listbox. Click the 'Add' button.

If the position is selected in the textbox then clicking the substring
in the listbox inserts the text at that position, Else it appends it to
the end of the assembled string.


To Remove a substring OR text from the textbox:
Select the substring in the listbox OR select the text in the textbox.
Click the 'Remove' button.

If there's a match for the listbox substring in the textbox then the
text is removed along with its leading space (..if there is one). If
text in the textbox is selected then that text is removed.


To replace text in the textbox with a substring from the listbox:
Select the text in the textbox, then click the 'Replace' button, then
select the substring in the listbox.


To edit directly in the textbox, just click the position to insert and
start typing.


The 'Cancel' button escapes the current action.

The 'Done' button processes the text in the textbox and clears all
action modes. Only click this button when you're done building your
result string. You could name it 'Process' if that term is more clear
to you or your users.

The 'Exit' button aborts all pending actions and unloads the userform.
If you want to process the textbox text before exiting then the 'Done'
button must be clicked.

HTH
 
K

kalle

kalle expressed precisely :







Are you trying to assemble a longer string by selecting shorter string
components? If so, I'd rather use a textbox to display the result so
users can see it 'as they build'. In this case you need to query the
listbox selection (checked/unchecked) to determine whether to
add/remove/replace in the result string. I'd not go that way! Instead,
I would not use a checked list for reasons I'll explain below.

Also, there needs to be a way of delimiting each substring in the
result. I'd probably use a space character so the result builds like a
sentence or statement, though I wouldn't include the space at the end
of the substrings in the listbox. I'm thinking to add the space before
inserting new substrings.

Remove/replace can be handled easily so the delimiter spaces get
handled correctly. This precludes, then, that your Userform has
separate buttons for each action (Add>Remove>Replace>Cancel>Done>Exit).
I'd probably code it so the user could select where to add substrings
in the textbox, but that could create problems if they choose within an
existing substring. In any event, remove/replace could be handled by
selecting in the textbox, in the listbox, or a combination of the two
in the case of replace.

The Add>Remove>Replace buttons would merely set a 'Mode' variable so
the subsequent action will be processed accordingly. (This is why I
would not use a checked list) For example:

To Add a substring:
Select the position in the textbox AND/OR select the substring in the
listbox. Click the 'Add' button.

If the position is selected in the textbox then clicking the substring
in the listbox inserts the text at that position, Else it appends it to
the end of the assembled string.

To Remove a substring OR text from the textbox:
Select the substring in the listbox OR select the text in the textbox.
Click the 'Remove' button.

If there's a match for the listbox substring in the textbox then the
text is removed along with its leading space (..if there is one). If
text in the textbox is selected then that text is removed.

To replace text in the textbox with a substring from the listbox:
Select the text in the textbox, then click the 'Replace' button, then
select the substring in the listbox.

To edit directly in the textbox, just click the position to insert and
start typing.

The 'Cancel' button escapes the current action.

The 'Done' button processes the text in the textbox and clears all
action modes. Only click this button when you're done building your
result string. You could name it 'Process' if that term is more clear
to you or your users.

The 'Exit' button aborts all pending actions and unloads the userform.
If you want to process the textbox text before exiting then the 'Done'
button must be clicked.

HTH

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc- Dölj citerad text-

- Visa citerad text -

Hi Garry,

Thanks for your detailed answer, I will work along your suggestions.

CG Rosén
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top