Need help understanding Sub procedures
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Need help understanding Sub procedures

  1. #1
    Join Date
    May 2013
    Posts
    2

    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.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,812

    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

    Code:
    Private Sub MySub(SomeString As String)
       ' some code
    End Sub
    This would be called from somewhere using something like
    Code:
    MySub ("Some String of Text")
    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.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center