March 1, 2021
Hot Topics:

Task Time

  • By Karl Moore
  • Send Email »
  • More Articles »

Creating a practical project.

Before you continue, I'd like to set you a little task. Try doing this - create a form and add a command button ("cmdStudentEntry") and list box ("lstStudents"). In the code behind the command button, prompt the user "How many students do you want to add?" - and then displays that number of input boxes to accept student names, adding each to the list box.

Now don't read below before you attempt the task. Oooh, I know it's tempting. But don't. No! NO!! Stop it. Stop right there, sonny. I've been around the world a bit and have got your number. Nudge, nudge, wink, wink. Ooh la la, folly de lay! Yah, boo, sucks to you.

Confused? You will be. Here's the code you need to add behind the specified command button:

Dim NoOfLoops as IntegerDim StudentName as String' Dim a couple of variables to hold informationNoOfLoops = InputBox("How many students do you want to add?")' Ask user how many times to loop aroundFor i = 1 to NoOfLoops' Tell Visual Basic how many times to loopStudentName = InputBox("Enter a student name:")' Put student name into StudentName variablelstStudents.AddItem (StudentName)' Add the name stored in StudentName to the list boxNext i

Page 4 of 7

This article was originally published on November 5, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date