Results 1 to 6 of 6

Thread: Need help on a Visual Basic programming problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    1

    Need help on a Visual Basic programming problem

    I just need to know how to set up this array within the program to allow 10 values to be entered then later be shown into separate labels as a largest and smallest value.

    The question reads.

    Largest/Smallest Array Values

    Create an application that lets the user enter 10 values into an array. The application should display the largest and smallest values stored in the array. Figure 8-45 shows an example of the application's form after all 10 values have been entered, with the largest and smallest values displayed.

    The form basically shows a large label box where your values will show up. Then two regular labels next to the boxed label that determines the largest and smallest values. There are four buttons, a clear, exit, Display Min & Max, and Input Values.

    I have the actual program layout already made and the initial buttons already declared, being the exit and clear buttons. I just need to know how to setup the array's for the other two buttons.

    If you can help it would be much appreciated.

    Thanks


  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Need help on a Visual Basic programming problem

    Quote Originally Posted by jokers View Post
    I just need to know how to set up this array within the program to allow 10 values to be entered then later be shown into separate labels as a largest and smallest value.

    The question reads.

    Largest/Smallest Array Values

    Create an application that lets the user enter 10 values into an array. The application should display the largest and smallest values stored in the array. Figure 8-45 shows an example of the application's form after all 10 values have been entered, with the largest and smallest values displayed.

    The form basically shows a large label box where your values will show up. Then two regular labels next to the boxed label that determines the largest and smallest values. There are four buttons, a clear, exit, Display Min & Max, and Input Values.

    I have the actual program layout already made and the initial buttons already declared, being the exit and clear buttons. I just need to know how to setup the array's for the other two buttons.

    If you can help it would be much appreciated.

    Thanks


    Normally, I wouldn't do it using an InputBox, but if this is required then here it is:

    Add this handler to the InputValues buton click event:
    vb Code:
    1. Private Sub btnInputValues_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnInputValues.Click
    2.         Dim userinput As String
    3.         Dim intvalues(9) As Integer
    4.  
    5.         Do
    6.             userinput = InputBox("Enter 10 values (comma separated) in the field below:")
    7.             If userinput = "" Then Exit Sub ' Cancel was pressed.
    8.  
    9.             Dim stringvalues() As String = userinput.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
    10.            
    11.             ' Possibly not necessary. It checks the input to be exactly 10 elements:
    12.             If stringvalues.Length <> 10 Then
    13.                 MsgBox("Enter exactly 10 numbers.")
    14.                 Continue Do
    15.             End If
    16.  
    17.             ' Checks each element to be an integer number:
    18.             For x As Integer = 0 To stringvalues.Length - 1
    19.                 If Not Integer.TryParse(stringvalues(x), intvalues(x)) Then
    20.                     MsgBox("Enter valid integer numbers.")
    21.                     Continue Do
    22.                 End If
    23.             Next
    24.             Exit Do
    25.         Loop
    26.  
    27.         lblMaxNumber.Text = intvalues.Max.ToString
    28.         lblMinNumber.Text = intvalues.Min.ToString
    29. End Sub

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help on a Visual Basic programming problem

    Quote Originally Posted by cicatrix View Post
    Normally, I wouldn't do it using an InputBox, but if this is required then here it is:
    If using InputBox is a requirement then it could only be because this is homework, so is writing the code for the OP really appropriate? Using web resources is one thing but having someone else do your work for you is straight up cheating, even if that's not what the OP intended. Maybe helping people to think for themselves rather than thinking for them would be more appropriate.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Need help on a Visual Basic programming problem

    Quote Originally Posted by jmcilhinney View Post
    If using InputBox is a requirement then it could only be because this is homework, so is writing the code for the OP really appropriate? Using web resources is one thing but having someone else do your work for you is straight up cheating, even if that's not what the OP intended. Maybe helping people to think for themselves rather than thinking for them would be more appropriate.
    Quoted the whole OP's message just to be on the safe side.

  5. #5
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Need help on a Visual Basic programming problem

    I would agree that posting the entire code really isn't all that appropriate. Also, i'm pretty sure that the point of the exercise is not to use the LINQ array extensions to get the maximum and minimum. I have a strong feeling that he is supposed to use more basic programming concepts to figure it out.

    This is why .Net really isn't a good language to teach basic programming. It's a little too high-level.

  6. #6
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Need help on a Visual Basic programming problem

    Using LINQ directly is not allowed also?
    vb Code:
    1. (Aggregate intval As Integer In intvalues Into Max()).ToString

    I didn't learn how to write programs at school so I have no idea about how they teach it. Looking back, I see that in order to understand how machine works it would be better to start from the assembly language.
    But since it's platform dependent I think Pascal has the best balance between complexity and simplicity.

Posting Permissions

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



Click Here to Expand Forum to Full Width