May 28th, 2013, 11:27 AM
Need help understanding Sub procedures
I've been trying to learn Visual Basic from online tutorials and searches and am stuck on a group of problems...
For each problem write a program that displays the output shown in a list box. The last two lines of the output should be displayed by one or more Sub procedures using data passed by variables from an event procedure.
1. (Assume that the following is displayed.)
According to a 2008 survey of college freshmen taken by the Higher
Education Research Institute:
16.7 percent said they intend to major in business.
1 percent said they intend to major in computer science.
2. (Assume that the current date is 12/31/2010, the label for txtBox reads “What is your date
of birth?”, and the user enters 2/3/1984 into txtBox before btnDisplay is clicked.)
You are now 26 years old.
You have lived for 9824 days.
3. (Assume that the label for txtBox reads “What is your favorite number?”, and the user types
7 into txtBox before btnDisplay is clicked.)
The sum of your favorite number with itself is 14.
The product of your favorite number with itself is 49.
4. (Assume that the following is displayed.)
In a recent year,
823 thousand college students took a course in Spanish
206 thousand college students took a course in French
I know from the above directions that I will need a ListBox to display the output but I'm having a hard time understanding sub precedures and as such I'm not sure how to go about creating these programs... Any help is greatly apprecated.
May 29th, 2013, 01:38 AM
Re: Need help understanding Sub procedures
A sub procedure is simply a block of code that performs some function and is called from somewhere else, typically this procedure may be needed more than once within the program and may be called from multiple places
This would be called from somewhere using something like
Private Sub MySub(SomeString As String)
' some code
Of course there could be more than one parameter or no parameters, they could be string or any other valid data type, just depends on what the Sub should do. If it needs to return a value then you would use a Function instead of a sub.
MySub ("Some String of Text")
Always use [code][/code] tags when posting code.
Click Here to Expand Forum to Full Width