Computer Science Canada Each row will contain the row number |
Author: | peterggmss [ Thu Oct 26, 2006 12:44 pm ] | ||||
Post subject: | Each row will contain the row number | ||||
Hi, sorry to join the site and the first thing I post is a request for help ![]() I need to make a simple program in VB where the user can enter a number of rows, click cmdCalculate and the output will be printed on the form. The output is to be the number of rows which the user wants to see printed on the screen and each row number will contain it's row number. It should be in a pyramid shape. Hard to explain. Example:
I hope that explained it. This is what I have so far:
I hope you can help me, I read the textbook and tried everything for 2 days now |
Author: | raptors892004 [ Thu Oct 26, 2006 2:33 pm ] |
Post subject: | |
Sorry that I cannot help with any code (my VB is getting rusty - I may attempt to code this - shouldn't be too long).. Basically what you can do is get the Integer value of the rows the user input (e.g.: 5) and run two loops. One loop goes from 1 to row numbers they input. The inner for loop goes from 1 to current row which is an integer in the set of 1 to number of rows they input. Each time you go into the inner loop, you add current row number to the total number. Example: They want 3 rows: Loop 1 goes from 1 to 3 (3 times): Inner loop goes from 1 to currentRow When outer loop is 1, Inner loop goes one time (1 to 1) 1 (current row) is added to total number which is to be printed onto the form when the outside loop (1 to max row numbers is complete) Goes on to row 2: Inner loop goes two times (1 to 2) 2 is added to total 2 is added to total Same for row 3 except it adds 3 times the number 3 now.. At the end (outside of the big loop) you print the result onto the form. Hope this helps ![]() |
Author: | raptors892004 [ Thu Oct 26, 2006 2:49 pm ] | ||
Post subject: | |||
I hope this is self explanatory. It uses the method described in the post above.[/code] |
Author: | Silent Avenger [ Thu Oct 26, 2006 3:26 pm ] |
Post subject: | |
Umm raptors I think you need to put the Form1.print (total) in the loop you are running so that it will display the way peterggmss wanted. |
Author: | raptors892004 [ Thu Oct 26, 2006 5:55 pm ] | ||
Post subject: | |||
This basically gets the input from the text field and using iteration prints the triangle. I would've made it print "tab" characters but I don't remember the code that did that. Basically how this works is: If inputRows=3 P.S.: Step -1 indicates that when program comes back to the beginning of the loop, it will decrease the variable used for the condition (e.g.: y) by 1. The most outer loop (x) runs 3 times (from 1 to 3) 1st run of big loop y loop runs 3 times (going from 3 to 1) and adds the spaces 3 times z loop runs 1 time (1 to 1) and prints the 1 one time Pyramid line is printed onto the form 2nd run of big loop y loop runs 2 times (going from 3 to 2) and adds the spaces 2 times to the reset (empty now) outputString variable z loop runs twice and adds the number 2 and a space and the number 2 and a space again to the current pyramid line Pyramid line is printed onto the form 3rd run of big loop y loop runs once (3 to 3) therefore 1 space is printed z loop runs 3 times therefore 3 integers and their spaces are printed Pyramid line is printed onto the form Now the program is done. Hope this is what the question was. |
Author: | raptors892004 [ Thu Oct 26, 2006 6:01 pm ] | ||
Post subject: | |||
An additional problem is the spacing. The fixed code is here. What is different is that when printing the integers, if the integer is less than 10, 3 spaces are printed with it. If it is over 10, only 1 space is printed with it.
|
Author: | Silent Avenger [ Thu Oct 26, 2006 6:12 pm ] |
Post subject: | |
Now I'm just wondering, did you want the numbers to appear on the form in the pyramid shape that you put up above peterggmss? |
Author: | peterggmss [ Fri Oct 27, 2006 12:40 pm ] |
Post subject: | |
Silent Avenger wrote: Now I'm just wondering, did you want the numbers to appear on the form in the pyramid shape that you put up above peterggmss? yes.
Thank you. |