Need help with simple problems

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 365
Reputation: NinjaLink is an unknown quantity at this point 
Solved Threads: 0
NinjaLink NinjaLink is offline Offline
Posting Whiz

Need help with simple problems

 
0
  #1
Nov 21st, 2008
Hello, I need help with a few things. Most of these things, I tried to do, but I need to know if I did them correctly, if not, how do I fix my problem? Thanks.

1) How do I make my MessageBox.Show say "The Sum of Array Numbers is ____ and the Average is _____" with the dashes filled in with the identifers Sum and Average.

2) For my For...Next Loop, how do I make it so I assign a value 10 larger than the index value to the variables. For example, MyArray (34) gets 44.. Another example is MyArray (89) gets 99 etc. The Loop should run only the number of times user entered in the text box. For example, if the user entered 90 then the loop should run 90 times without hard coding the index value in the loop.

3) I need to create a sum of the values contained in MyArray variable simultaneously while assigning the values in the same loop. Then I need to find the average of these numbers after the loop finishes. Did I do this correctly in my code?

4) How do I use If..Then to check for a blank value in the text box. Without using IsNumeric, FormatException is suppose to handle the problem.


  1. Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
  2. Dim MyArray As Integer()
  3.  
  4. MyArray = New Integer(200) {}
  5.  
  6. For I = 0 To MyArray.GetUpperBound(0)
  7. MyArray(0) = 10
  8. Next
  9.  
  10. Dim Sum As Integer
  11. Dim Average As Double
  12.  
  13. For I = 0 To MyArray.GetUpperBound(0)
  14.  
  15. Sum = Sum + MyArray(I)
  16. Next
  17.  
  18. Average = Sum / MyArray.GetUpperBound(0)
  19.  
  20. MessageBox.Show("The Sum of Array Numbers is" & Sum, "and the Average is" & Average)
  21.  
  22.  
  23. Dim bolFinished As Boolean
  24.  
  25. txtNumber.Text = ""
  26. bolFinished = False
  27.  
  28. Try
  29. Dim Num As Integer = Convert.ToInt32(txtNumber.Text)
  30.  
  31. Sum = Sum + Num
  32. txtNumber.Text = Sum.ToString()
  33. bolFinished = True
  34.  
  35.  
  36. Catch formatExceptionParameter As FormatException
  37. MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _
  38. MessageBoxButtons.OK, MessageBoxIcon.Error)
  39. Catch OtherEx As Exception
  40. MessageBox.Show(OtherEx.ToString, "Unknown Error", _
  41. MessageBoxButtons.OK, MessageBoxIcon.Error)
  42. Finally
  43.  
  44. If bolFinished = True Then
  45. MessageBox.Show("Divison operation finished")
  46. Else
  47. MessageBox.Show("Computation operation failed")
  48. End If
  49.  
  50. End Try
  51.  
  52.  
  53. End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 365
Reputation: NinjaLink is an unknown quantity at this point 
Solved Threads: 0
NinjaLink NinjaLink is offline Offline
Posting Whiz

Re: Need help with simple problems

 
0
  #2
Nov 21st, 2008
Someone please help! It's urgent.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Need help with simple problems

 
0
  #3
Nov 21st, 2008
to get the variables display in your meesage try somethig like:

  1. MsgBox("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)

to check and see if the text box is empty:

  1. if txtNumber.Text = string.empty then
  2. ''put action here if it is empty
  3.  
  4. Else
  5. ''put action here if contains text
  6.  
  7. End If


ill look at the other bits if i have time
Last edited by ninjaimp; Nov 21st, 2008 at 12:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 365
Reputation: NinjaLink is an unknown quantity at this point 
Solved Threads: 0
NinjaLink NinjaLink is offline Offline
Posting Whiz

Re: Need help with simple problems

 
0
  #4
Nov 21st, 2008
Here is an update for my program.


I still need help with:

1) For my For...Next Loop, how do I make it so I assign a value 10 larger than the index value to the variables. For example, MyArray (34) gets 44.. Another example is MyArray (89) gets 99 etc. The Loop should run only the number of times user entered in the text box. For example, if the user entered 90 then the loop should run 90 times without hard coding the index value in the loop.

2) I need to create a sum of the values contained in MyArray variable simultaneously while assigning the values in the same loop. Then I need to find the average of these numbers after the loop finishes. Did I do this correctly in my code?

3) How do I use If..Then to check for a blank value in the text box. Without using IsNumeric, FormatException is suppose to handle the problem.

  1.  
  2. Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
  3.  
  4. Dim MyArray As Integer()
  5.  
  6. MyArray = New Integer(200) {}
  7.  
  8.  
  9. For I = 0 To MyArray.GetUpperBound(0)
  10. MyArray(I) = I * 2
  11. Next
  12.  
  13. Dim Sum As Integer
  14. Dim Average As Double
  15.  
  16. For I = 0 To MyArray.GetUpperBound(0)
  17.  
  18. Sum = Sum + I
  19. Next
  20.  
  21. Average = Sum / MyArray.GetUpperBound(0)
  22.  
  23.  
  24. MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
  25.  
  26.  
  27. Dim bolFinished As Boolean
  28.  
  29. txtNumber.Text = ""
  30. bolFinished = False
  31.  
  32. Try
  33. Dim Num As Integer = Convert.ToInt32(txtNumber.Text)
  34.  
  35. Sum = Sum + Num
  36. txtNumber.Text = Sum.ToString()
  37. bolFinished = True
  38.  
  39.  
  40. Catch formatExceptionParameter As FormatException
  41. If txtNumber.Text = String.Empty Then
  42. MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _
  43. MessageBoxButtons.OK, MessageBoxIcon.Error)
  44. Else
  45. MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
  46. End If
  47.  
  48.  
  49. Catch OtherEx As Exception
  50. If txtNumber.Text = String.Empty Then
  51. MessageBox.Show(OtherEx.ToString, "Unknown Error", _
  52. MessageBoxButtons.OK, MessageBoxIcon.Error)
  53. Else
  54. MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
  55. End If
  56.  
  57. End Try
  58.  
  59.  
  60. End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 365
Reputation: NinjaLink is an unknown quantity at this point 
Solved Threads: 0
NinjaLink NinjaLink is offline Offline
Posting Whiz

Re: Need help with simple problems

 
0
  #5
Nov 21st, 2008
Can someone please point out if my code is correct so far according to what I need to do? I really need help because some of the instructions, I'm not clearly understanding..
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 365
Reputation: NinjaLink is an unknown quantity at this point 
Solved Threads: 0
NinjaLink NinjaLink is offline Offline
Posting Whiz

Re: Need help with simple problems

 
0
  #6
Nov 21st, 2008
I need help on a couple of things.

1) Is my MyArray set up correctly? I am suppose to use a For..Next loop to assign a value 10 larger than the index value to these variables. For example: MyArray(34) gets 33, MyArray (89) gets 99 etc. The loop should run only the number of times the user entered in the textbox.

2) Is my sum and average being calculated correctly? I'm creating a sum of the values contained in Myarray variable simultaneously while assigning the values in the same loop.


3) Is my IF..THEN checking for a blank value in the text? If not, how do I implement is correctly?

Thanks..

Here is my updated code:


  1. Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
  2.  
  3.  
  4.  
  5.  
  6. Dim bolFinished As Boolean
  7.  
  8. Try
  9.  
  10. Dim Number As Integer = Convert.ToInt32(txtNumber.Text)
  11. Dim MyArray As Integer()
  12. Dim Sum As Integer
  13. Dim Average As Double
  14.  
  15. MyArray = New Integer(200) {}
  16.  
  17.  
  18. For I = 0 To MyArray.GetUpperBound(0)
  19.  
  20.  
  21. MyArray(I) = I * 2
  22.  
  23. Next
  24.  
  25. For I = 0 To MyArray.GetUpperBound(0)
  26.  
  27. Sum = Sum + MyArray(I)
  28.  
  29. Next
  30.  
  31.  
  32. Average = Sum / MyArray.GetUpperBound(0)
  33.  
  34.  
  35. MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
  36.  
  37.  
  38.  
  39. bolFinished = True
  40.  
  41.  
  42. Catch formatExceptionParameter As FormatException
  43. MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _
  44. MessageBoxButtons.OK, MessageBoxIcon.Error)
  45.  
  46. Catch OtherEx As Exception
  47. MessageBox.Show("There was a problem...Please email customer service", "Unknown Error", _
  48. MessageBoxButtons.OK, MessageBoxIcon.Error)
  49.  
  50. If txtNumber.Text = String.Empty Then
  51. MessageBox.Show("You must enter a numberl ess than 200")
  52. End If
  53.  
  54.  
  55. End Try
  56.  
  57.  
  58. End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 365
Reputation: NinjaLink is an unknown quantity at this point 
Solved Threads: 0
NinjaLink NinjaLink is offline Offline
Posting Whiz

Re: Need help with simple problems

 
0
  #7
Nov 22nd, 2008
Anyone available to help me with my above post?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC