Visual Basic help!

Can you help me with some Visual Basic code?

I am writing a program for school but there is one part I am having a problem with.

The program consists of 2 forms. On the ‘frmaddstudent’ form, when a STUDENT ID is selected and the ‘Delete’ button is pressed, it doesn’t delete the selected ID, but it deletes the bottom ID. (The ID’s are in a listbox)

You will understand what that means when you see the program. So if you are a bit of a guru at Visual Basic, or think you know what’s wrong, please visit this link:

http://www.angelfire.com/sd/ptsoz/vb.htm

Download the program and have a look.

Thankyou very much for your assistance.

-HalloweenMan

HalloweenMan, your problem is in the Delete button code. A couple of times you write:

Do While Student(i).lastname = lstStudentID.Text
If Student(i).lastname = lstStudentID.Text

The student lastname is never going to equal the student id, so the code in the Do loop and the If block never executes.

OK, so what should the code be changed to?

I wouldn’t feel right doing the code for you. This is obviously an assignment for school.

Change the statements to check for the ID, not lastname. Also, your Do loop likely should be “<>” (not equal to), not “=”

Learn how to set breakpoints and step through your code one statement at a time. Use your Immediate window to print the current values. Use resources like http://www.planet-source-code.com/vb/ and http://www.devx.com/ to do research and learn new things.

Above all, keep writing code daily and you will be amazed how much you will progress.

hardcore, can i fond online some introduction or tutorial to VB?

sailor, the best thing about VB is its accessibility to the masses. As such, there are literally hundreds of websites devoted to it. Besides the links mentioned above, try this tutorial page, plus another page for beginners. The online documentation that comes with vb is also quite good.

I respond well to books, so I keep an eye on my local CompUSA. They regularly put on sale for $15 older vb books that originally sold for >$45.

Beyond that, simply type “Visual Basic” into Google and explore until you find something that meets your needs.

http://www.planet-source-code.com

This is a real good place to get code snippets. You can also get on thier mailing list to get the top 10 code snips of the day.
V.

Thanks for the tips hardcore. I used to program in (jurassic) BASIC but I see that has disappeared and I’ve been thinking of learning VB. I’ll start looking around.

jurassic BASIC… that’s funny!

If you were able to do anything of significance in BASIC, you will find the latest versions of VB to be easier and more powerful. Drop about $200 and get VB6 – you will be amazed at the difference.

hardcore,

I have tried to change it but I keep getting an error when I run it. Can you please give me the code for it.

Don’t worry about the ‘it’s a school assignment’ thing, because we are doing it next term and our tutor has just given us some sheets to see if we can solve them, merely as practice, and this one has got me stumped.

So if you could post the code, it would be much appreciated.

Try changing this line in your original code:


Do While Student(i).lastname = lstStudentID.Text

to this:


Do While Student(i).id <> lstStudentID.Text

and then change this line:


If Student(i).lastname = lstStudentID.Text

to this:


If Student(i).id = lstStudentID.Text

If you make both of these changes and still receive an error, let me know the exact error message text.

You may want to add a statement to exit the Delete routine if no student is currently selected.

Pleeeeeeeease can somebody help me.

If you visit the link you can download the program and have a look. Read the Original post.

Thanks.

-HalloweenMan

Thanks hardcore, I’ll try that out

Hmmm

it said “Runtime error (9) Subscript out of range”

and it highlights the code:

Do While Student(i).lastname <> lstStudentID.Text

Any ideas?

Change the “Student(i).lastname” to “Student(i).id” !!

Hardcore, you are an absolute LEGEND.

I can’t thank you enough for helping me, next time I need help with VB, I’ll know who to turn to. It worked like a charm. Thnaks again, it was much appreciated.

-HalloweenMan

I would wait until you have learned a little more about VB before you classify anyone as a legend. :wink: Thanks for the props though.

Seriously, spend some time with the VB help and learn how to debug a program by entering break mode and single-stepping through the code. Learn to rest your cursor on a variable while debugging to obtain its current value. Download lots of code and step through it to see what is happening. In short, have fun and learn!
God, I am a freakin’ nerd.