Join 132,494 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,056 people online right now. Registration is fast and FREE... Join Now!
design.doc ( 103k )
Number of downloads: 8 I am so lost in this class, just back from Iraq and time to learn another new language. The assignment is: Write an application that displays a table of numbers from 1 to an upper limit, along with each numbers squared value (for example, the number n to the power 3, or n ^ 3). The user specifies the upper limit, and the results are displayed in a listbox. I have attached a screen shot of the program in Design View also. Example: display intCounter, intCounter^2, and intCounter^3 inCounter += 1 Loop
It is too be done with a Do Untill... Loop. We are to declare a int counter to declare how many times to complete the loop. My code is below, We dont have to use inCounter, but if we did I dont understand it, Id rather learn without it for less confusion. My ate up code: _________________________________________________
vb
Public Class TableOfPowersForm
Private Sub inputTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inputTextBox.TextChanged
End Sub
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
Dim input As Integer 'Declare Variable Dim results As Integer 'Declare results
input = Val(inputTextBox.Text) 'Retreive Number from TextBox results = Val(resultsListBox.Text) 'Results
You have done a great job explaining the assignment and posting your code.
Now, can you describe where specifically you are having the problem?
Are you just having trouble outputting the resulting data?
I am a little confused by your use of Console.WriteLine, this will only output to the console window, but it appears that you have a Windows Forms project.
Did you mean to output all the results to the ListBox?
You have done a great job explaining the assignment and posting your code.
Now, can you describe where specifically you are having the problem?
Are you just having trouble outputting the resulting data?
I am a little confused by your use of Console.WriteLine, this will only output to the console window, but it appears that you have a Windows Forms project.
Did you mean to output all the results to the ListBox?
Hello, good point that console.writeline is wrong, I copied from my textbook, Im confused how to start the Do Untill loop and how to write the math equation, I need to show X, X^2, X3, and the user specifies a number, lets say 5 so the program gives square roots of 1 to 5. Just been puzzled, Im in Military and its just a hard time to learn a new language, 3rd week of school and first time running into problems.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim input As Integer = TextBox1.Text 'user entered variable Dim myVariable As Integer = 1 ' used as a base number for the power function
Dim count As Integer = 1 ' needed to control loop 1 Dim count2 As Integer = 1 'needed to control loop 2
'loop 1 Do Until count > input ListBox1.Items.Add(Math.Pow(count, myVariable)) count += 1 Loop
'loop 2 'i used a second loop just for ease of reading. you can if you want merge the two and only run one loop Do Until count2 > input ListBox2.Items.Add(Math.Sqrt(count2)) count2 += 1 Loop
End Sub
sorry if i'm off track but it's really not my morning. one or two hints either way. For math functions use the math class Type Math. and then have a look at the options available to you, they're fairly self explainatory. And also when stuck on code structures, right click and go to code snippets. Theres a whole bunch that you can have a look at
I'm a bit confused on your use of the two loops but the main difference between the do loop until and do until loop is that the first one(do loop until) is always executed at least once whereas that is not neccessarily(spelling?) true for a do until loop.
This post has been edited by Damage: 5 Sep, 2008 - 06:26 PM
Good information. The listbox once the user inputs the upper limit is to display this, I have already added the header to my code shown: Example is if user inputs 5
N N^2 N^3 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125
QUOTE(foobleys @ 5 Sep, 2008 - 06:20 PM)
QUOTE(jayman9 @ 5 Sep, 2008 - 05:57 PM)
You have done a great job explaining the assignment and posting your code.
Now, can you describe where specifically you are having the problem?
Are you just having trouble outputting the resulting data?
I am a little confused by your use of Console.WriteLine, this will only output to the console window, but it appears that you have a Windows Forms project.
Did you mean to output all the results to the ListBox?
Hello, good point that console.writeline is wrong, I copied from my textbook, Im confused how to start the Do Untill loop and how to write the math equation, I need to show X, X^2, X3, and the user specifies a number, lets say 5 so the program gives square roots of 1 to 5. Just been puzzled, Im in Military and its just a hard time to learn a new language, 3rd week of school and first time running into problems.
Good information. The listbox once the user inputs the upper limit is to display this, I have already added the header to my code shown: Example is if user inputs 5
N N^2 N^3 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125
QUOTE(foobleys @ 5 Sep, 2008 - 06:20 PM)
QUOTE(jayman9 @ 5 Sep, 2008 - 05:57 PM)
You have done a great job explaining the assignment and posting your code.
Now, can you describe where specifically you are having the problem?
Are you just having trouble outputting the resulting data?
I am a little confused by your use of Console.WriteLine, this will only output to the console window, but it appears that you have a Windows Forms project.
Did you mean to output all the results to the ListBox?
Hello, good point that console.writeline is wrong, I copied from my textbook, Im confused how to start the Do Untill loop and how to write the math equation, I need to show X, X^2, X3, and the user specifies a number, lets say 5 so the program gives square roots of 1 to 5. Just been puzzled, Im in Military and its just a hard time to learn a new language, 3rd week of school and first time running into problems.
I recently finished with VB 2005 so I can understand the frustration.
The Do Until loop iterates until its test expression is true. The Do Until loop may be written in pretest or posttest form. Here is the general format of the Do Until loop.
Here is the pretest form:
Do Until expression statement (more statements may follow) Loop
Here is the posttest form:
Do statement (more statements may follow) Loop Until expression.
This should cause it to loop and and display what your program requires (was coded to do) until the input from the user becomes true. I believe the post test would be used to display up to and include the user input whereas the pretest would not.
I hope I understood the problem correctly and this helps solve the problem.