| | |
Pyramid Issue
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
Hey I was having a major problem in creating a complex number pyramid. The user inputs a number of rows, but if it exceeds 20 it would go off page, so 1-20. I have a nested For loop (using QBasic) that looks something like this
for x = 1 to rows
for y = 1 to x
(CODE)
next y
(CODE)
next x
IT would be simple ... but the pyramid must look something like this
__________________0
_________________101
________________21012
_______________3210123
That would be for 4 rows, and it continues on in that pattern, with the last number increasing 1 per row....what ive come up with is creating a addition type formula, but i keep gettin the wrong solution and ive changed it about a million different ways so i scratched it all together..... :mad: lol, anyone have an idea on the coding ill need to create the 21012 type pattern in the second For loop....or am i setting it up completly wrong and need a new method of doing this??
for x = 1 to rows
for y = 1 to x
(CODE)
next y
(CODE)
next x
IT would be simple ... but the pyramid must look something like this
__________________0
_________________101
________________21012
_______________3210123
That would be for 4 rows, and it continues on in that pattern, with the last number increasing 1 per row....what ive come up with is creating a addition type formula, but i keep gettin the wrong solution and ive changed it about a million different ways so i scratched it all together..... :mad: lol, anyone have an idea on the coding ill need to create the 21012 type pattern in the second For loop....or am i setting it up completly wrong and need a new method of doing this??
Just a thought:
this should give you
0
01
012
0123
...
and im sure you can go back over the loop and draw the other side
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
CLS row = 0 For y = 0 to 19 ' 20 rows For x = 0 to row print "x" ' i cant remember the code for adjacent text Next print " " 'new line row = row + 1 ' increment row Next
this should give you
0
01
012
0123
...
and im sure you can go back over the loop and draw the other side
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
•
•
Join Date: Dec 2004
Posts: 207
Reputation:
Solved Threads: 7
First of all, you need a nonkerning font....
Second, I would use the concatenating + in an assignment statement to give you what you need, such as:
nu$ = STR$(i)
hol$ = nu$ + lis$ + nu$
lis$ = hol$
This adds the new number to both ends of the string lis$.
Now all you have to do is figure out how to use STRING$ to make a line of dashes, one dash shorter than the previous time.
Second, I would use the concatenating + in an assignment statement to give you what you need, such as:
nu$ = STR$(i)
hol$ = nu$ + lis$ + nu$
lis$ = hol$
This adds the new number to both ends of the string lis$.
Now all you have to do is figure out how to use STRING$ to make a line of dashes, one dash shorter than the previous time.
•
•
Join Date: Sep 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Just a thought:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
CLS row = 0 For y = 0 to 19 ' 20 rows For x = 0 to row print "x" ' i cant remember the code for adjacent text Next print " " 'new line row = row + 1 ' increment row Next
this should give you
0
01
012
0123
...
and im sure you can go back over the loop and draw the other side
To achieve the single line printing, please refer the below code. Hope this helps.....
Dim res As String
res = ""
row = 0
For y = 1 To 6 ' 20 rows
For x = 1 To row
res = res & "x"
Next
Print res
res = ""
row = row + 1 ' increment row
Next
Output will be as follows
x
xx
xxx
xxxx
xxxxx
•
•
Join Date: Sep 2009
Posts: 57
Reputation:
Solved Threads: 8
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim x As Long Dim y As Long Dim S As String For y = 0 To 20 S = "" For x = -y To y S = S & Abs(x) Next Print Space(100 - Len(S)) & S Next
![]() |
Similar Threads
- Windows Explorer Issue: my "Address" bar is gone, how do I get it back? (Windows NT / 2000 / XP)
- Power boot up issue (Motherboards, CPUs and RAM)
- Kernel Version of Mandrake and error message (*nix Software)
- Memory Issue's! Please Help!! (Motherboards, CPUs and RAM)
- Internet Explorer Connection Issue (Web Browsers)
- Netgear router issue...read this if you have one (Networking Hardware Configuration)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB6 age calculator
- Next Thread: Do until loop
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





