View Full Version : Visual Basic help!
HalloweenMan
07-05-2000, 08:47 AM
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
hardcore
07-05-2000, 10:02 AM
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.
HalloweenMan
07-05-2000, 10:10 AM
OK, so what should the code be changed to?
hardcore
07-05-2000, 12:04 PM
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.
sailor
07-05-2000, 01:07 PM
hardcore, can i fond online some introduction or tutorial to VB?
hardcore
07-05-2000, 01:42 PM
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 (http://visualbasic.about.com/compute/visualbasic/msubtutorialbeg.htm?IAM=vpn000194_4) page, plus another page for beginners (http://www.vbexplorer.com/). 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.
Lord Vega
07-05-2000, 03:02 PM
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.
sailor
07-05-2000, 03:57 PM
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.
hardcore
07-05-2000, 05:11 PM
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.
HalloweenMan
07-05-2000, 11:10 PM
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.
hardcore
07-06-2000, 02:38 AM
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.
HalloweenMan
07-06-2000, 02:40 AM
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
HalloweenMan
07-06-2000, 02:41 AM
Thanks hardcore, I'll try that out
HalloweenMan
07-06-2000, 02:47 AM
Hmmm
it said "Runtime error (9) Subscript out of range"
and it highlights the code:
Do While Student(i).lastname <> lstStudentID.Text
Any ideas?
hardcore
07-06-2000, 03:14 AM
Change the "Student(i).lastname" to "Student(i).id" !!
HalloweenMan
07-06-2000, 03:20 AM
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
hardcore
07-06-2000, 03:38 AM
I would wait until you have learned a little more about VB before you classify anyone as a legend. ;) 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.
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.