| | |
Need help with simple problems
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 365
Reputation:
Solved Threads: 0
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) 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.
VB Syntax (Toggle Plain Text)
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click Dim MyArray As Integer() MyArray = New Integer(200) {} For I = 0 To MyArray.GetUpperBound(0) MyArray(0) = 10 Next Dim Sum As Integer Dim Average As Double For I = 0 To MyArray.GetUpperBound(0) Sum = Sum + MyArray(I) Next Average = Sum / MyArray.GetUpperBound(0) MessageBox.Show("The Sum of Array Numbers is" & Sum, "and the Average is" & Average) Dim bolFinished As Boolean txtNumber.Text = "" bolFinished = False Try Dim Num As Integer = Convert.ToInt32(txtNumber.Text) Sum = Sum + Num txtNumber.Text = Sum.ToString() bolFinished = True Catch formatExceptionParameter As FormatException MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _ MessageBoxButtons.OK, MessageBoxIcon.Error) Catch OtherEx As Exception MessageBox.Show(OtherEx.ToString, "Unknown Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If bolFinished = True Then MessageBox.Show("Divison operation finished") Else MessageBox.Show("Computation operation failed") End If End Try End Sub
•
•
Join Date: Apr 2008
Posts: 114
Reputation:
Solved Threads: 6
to get the variables display in your meesage try somethig like:
to check and see if the text box is empty:
ill look at the other bits if i have time
VB.NET Syntax (Toggle Plain Text)
MsgBox("The Sum of Array Numbers is " & Sum & " and the Average is " & Average)
to check and see if the text box is empty:
VB.NET Syntax (Toggle Plain Text)
if txtNumber.Text = string.empty then ''put action here if it is empty Else ''put action here if contains text End If
ill look at the other bits if i have time
Last edited by ninjaimp; Nov 21st, 2008 at 12:41 pm.
•
•
Join Date: Mar 2008
Posts: 365
Reputation:
Solved Threads: 0
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.
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.
VB Syntax (Toggle Plain Text)
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click Dim MyArray As Integer() MyArray = New Integer(200) {} For I = 0 To MyArray.GetUpperBound(0) MyArray(I) = I * 2 Next Dim Sum As Integer Dim Average As Double For I = 0 To MyArray.GetUpperBound(0) Sum = Sum + I Next Average = Sum / MyArray.GetUpperBound(0) MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average) Dim bolFinished As Boolean txtNumber.Text = "" bolFinished = False Try Dim Num As Integer = Convert.ToInt32(txtNumber.Text) Sum = Sum + Num txtNumber.Text = Sum.ToString() bolFinished = True Catch formatExceptionParameter As FormatException If txtNumber.Text = String.Empty Then MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _ MessageBoxButtons.OK, MessageBoxIcon.Error) Else MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average) End If Catch OtherEx As Exception If txtNumber.Text = String.Empty Then MessageBox.Show(OtherEx.ToString, "Unknown Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) Else MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average) End If End Try End Sub
•
•
Join Date: Mar 2008
Posts: 365
Reputation:
Solved Threads: 0
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) 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:
VB Syntax (Toggle Plain Text)
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click Dim bolFinished As Boolean Try Dim Number As Integer = Convert.ToInt32(txtNumber.Text) Dim MyArray As Integer() Dim Sum As Integer Dim Average As Double MyArray = New Integer(200) {} For I = 0 To MyArray.GetUpperBound(0) MyArray(I) = I * 2 Next For I = 0 To MyArray.GetUpperBound(0) Sum = Sum + MyArray(I) Next Average = Sum / MyArray.GetUpperBound(0) MessageBox.Show("The Sum of Array Numbers is " & Sum & " and the Average is " & Average) bolFinished = True Catch formatExceptionParameter As FormatException MessageBox.Show("You must enter a number less than 200", "Invalid Number Format", _ MessageBoxButtons.OK, MessageBoxIcon.Error) Catch OtherEx As Exception MessageBox.Show("There was a problem...Please email customer service", "Unknown Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) If txtNumber.Text = String.Empty Then MessageBox.Show("You must enter a numberl ess than 200") End If End Try End Sub
![]() |
Similar Threads
- Problems with ubuntu (Window and Desktop Managers)
- some simple problems... (C++)
- Simple sql questions (broken commands and retrieving columns) (Database Design)
- remote pc problems (Networking Hardware Configuration)
- Very simple I'm sure! (Windows NT / 2000 / XP)
- windows problems... (Windows NT / 2000 / XP)
Other Threads in the VB.NET Forum
- Previous Thread: How to create file in VB.net (VS 2005)
- Next Thread: UI probs
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google hardcopy html images input insert intel internet mobile monitor ms net networking objects open output panel passingparameters pdf picturebox picturebox1 port position printing problem project save searchbox searchvb.net select serial settings shutdown soap sqlserver survey tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet view visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year





