Question

Locked

Visual Basic 2010 Express

By ROYBONBON ·
I created a ListView in VB2010 Express. I have four buttons on Form1 to add an item, delete an item, edit an item and print the list. Before I can edit or delete an item, the item must first be selected. If I forget to first select and item before clicking either the edit or delete button, I get an error message.

What code do I need to add so that when I forget to select before clicking the edit or delete button a message box will remind to first select. I added the message box but after clicking OK on the message box, the code continues and I still get the error message. I need something to pause the code long enough for me to select the item and re-click.

Thank you very much.

RoyBonBon

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Visual Basic 2010 Express

by ROYBONBON In reply to Visual Basic 2010 Express

on the line before where the code is reporting an error enter:
On error goto Handler

On the last line of the Sub routine just before End Sub enter:
Handler: msgbox ("Please Select an item before Clicking the Edit Button")

type Exit Sub on the last line of code before typing the Handler: info

Collapse -

Test for it

by Tony Hopkinson In reply to Visual Basic 2010 Express

Usually something like
If (MyListBox.Selected != null).
Or nothing or whatever it is in VB.

You should not be using On error goto, that's a VB6 holdover.

VB.net has exceptions
http://www.homeandlearn.co.uk/NET/nets5p4.html

Back to Software Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums