Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

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!




Help in VB2005 Class Loop Until Exponent Program

 
Reply to this topicStart new topic

Help in VB2005 Class Loop Until Exponent Program, Trouble with an assignment.

foobleys
post 5 Sep, 2008 - 01:19 PM
Post #1


New D.I.C Head

*
Joined: 5 Sep, 2008
Posts: 3


My Contributions


Attached File  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

resultsListBox.Items.Add("N" & ControlChars.Tab & "N^2" & ControlChars.Tab _
& "N^3") 'Header

Do


Loop Until

Do Until

Loop

End Sub
End Class ' TableOfPowersForm


This post has been edited by foobleys: 5 Sep, 2008 - 05:56 PM
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 5 Sep, 2008 - 03:00 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,927



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Moved to VB.NET smile.gif
User is online!Profile CardPM

Go to the top of the page

Jayman
post 5 Sep, 2008 - 04:57 PM
Post #3


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

foobleys
post 5 Sep, 2008 - 05:20 PM
Post #4


New D.I.C Head

*
Joined: 5 Sep, 2008
Posts: 3


My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

Damage
post 5 Sep, 2008 - 06:20 PM
Post #5


D.I.C Addict

Group Icon
Joined: 5 Jun, 2008
Posts: 733



Thanked 7 times

Dream Kudos: 75
My Contributions


do you mean something like this?
CODE

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 tongue.gif 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
User is offlineProfile CardPM

Go to the top of the page

foobleys
post 6 Sep, 2008 - 05:58 AM
Post #6


New D.I.C Head

*
Joined: 5 Sep, 2008
Posts: 3


My Contributions


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.

User is offlineProfile CardPM

Go to the top of the page

ccrasherdeb
post 6 Sep, 2008 - 02:33 PM
Post #7


D.I.C Head

**
Joined: 3 Mar, 2008
Posts: 79



Thanked 1 times
My Contributions


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.

User is offlineProfile CardPM

Go to the top of the page

Damage
post 6 Sep, 2008 - 03:25 PM
Post #8


D.I.C Addict

Group Icon
Joined: 5 Jun, 2008
Posts: 733



Thanked 7 times

Dream Kudos: 75
My Contributions


this is a real hack job but it's something like the way you want it to look, you can place with the spacing and stuff.

CODE

ListBox1.Items.Add("N" + " " + "N^2" + " " + "N^3")
        Do Until count > input
            Dim item1 As Integer = Math.Pow(count, 1)
            Dim item2 As Integer = Math.Pow(count, 2)
            Dim item3 As Integer = Math.Pow(count, 3)
            Dim displayString As String = (item1 & " " & item2 & "    " & item3)
            ListBox1.Items.Add(displayString)

            count += 1
        Loop


your other alternative is to have a look at using a listview which is more suited to columns
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 05:00PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month