# Visual Basic help!

**URL:** <https://boards.straightdope.com/t/visual-basic-help/24636>\
**Category:** Factual Questions\
**Created:** [July 5, 2000, 1:47pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636 "2000-07-05T13:47:53Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 5, 2000, 1:47pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/1 "2000-07-05T13:47:53Z")

</div>

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](http://www.angelfire.com/sd/ptsoz/vb.htm)

Download the program and have a look.

Thankyou very much for your assistance.

-HalloweenMan

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 5, 2000, 3:02pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/2 "2000-07-05T15:02:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 5, 2000, 3:10pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/3 "2000-07-05T15:10:26Z")

</div>

OK, so what should the code be changed to?

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 5, 2000, 5:04pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/4 "2000-07-05T17:04:26Z")

</div>

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/](http://www.planet-source-code.com/vb/) and [http://www.devx.com/](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.

---

<div class="post-metadata">

**Author:** ![sailor](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@sailor](https://boards.straightdope.com/u/sailor)\
**Post date:** [July 5, 2000, 6:07pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/5 "2000-07-05T18:07:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 5, 2000, 6:42pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/6 "2000-07-05T18:42:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lord\_Vega](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@Lord\_Vega](https://boards.straightdope.com/u/Lord_Vega)\
**Post date:** [July 5, 2000, 8:02pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/7 "2000-07-05T20:02:27Z")

</div>

[http://www.planet-source-code.com](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.

---

<div class="post-metadata">

**Author:** ![sailor](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@sailor](https://boards.straightdope.com/u/sailor)\
**Post date:** [July 5, 2000, 8:57pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/8 "2000-07-05T20:57:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 5, 2000, 10:11pm UTC](https://boards.straightdope.com/t/visual-basic-help/24636/9 "2000-07-05T22:11:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 6, 2000, 4:10am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/10 "2000-07-06T04:10:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 6, 2000, 7:38am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/11 "2000-07-06T07:38:26Z")

</div>

Try changing this line in your original code:

```auto

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

```

to this:

```auto

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

```

and then change this line:

```auto

If Student(i).lastname = lstStudentID.Text

```

to this:

```auto

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.

---

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 6, 2000, 7:40am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/12 "2000-07-06T07:40:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 6, 2000, 7:41am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/13 "2000-07-06T07:41:40Z")

</div>

Thanks hardcore, I’ll try that out

---

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 6, 2000, 7:47am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/14 "2000-07-06T07:47:05Z")

</div>

Hmmm

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

and it highlights the code:

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

Any ideas?

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 6, 2000, 8:14am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/15 "2000-07-06T08:14:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HalloweenMan](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HalloweenMan](https://boards.straightdope.com/u/HalloweenMan)\
**Post date:** [July 6, 2000, 8:20am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/16 "2000-07-06T08:20:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hardcore](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hardcore](https://boards.straightdope.com/u/hardcore)\
**Post date:** [July 6, 2000, 8:38am UTC](https://boards.straightdope.com/t/visual-basic-help/24636/17 "2000-07-06T08:38:57Z")

</div>

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._
