Visual Basics

Toitjie

Expert Member
Joined
Apr 6, 2008
Messages
1,786
Reaction score
64
Location
PTA/JHB
Any1 here know anything bout VB


Im struggling on something small...and went through many bo0ks

i wane create a pyramid in vb
eg

*
**
***
****
*****

i know its a nested for loop but i still cant get it right
plz help:confused::confused:
 
Any1 here know anything bout VB


Im struggling on something small...and went through many bo0ks

i wane create a pyramid in vb
eg

*
**
***
****
*****

i know its a nested for loop but i still cant get it right
plz help:confused::confused:

Hmmm I know very little about programming let alone vb, but what you'd want to do is create a string variable and add a * to it with every iteration of the for loop.

Don't the language but in pseudo code:

for i = 1 to 10 (or whatever)
string = + "*"
print string

Or Im dumber than I think and you should ignore this.
 
i got that but i cant the print statement just doesnt seem to print it, so this is what i got...take a look


Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
For K = 1 To 8 Step 1
For J = 7 To K Step -1
ListBox1.Items.Add("*")​
Next

Next
End Sub
 
i got that but i cant the print statement just doesnt seem to print it, so this is what i got...take a look


Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
For K = 1 To 8 Step 1
For J = 7 To K Step -1
ListBox1.Items.Add("*")​
Next

Next
End Sub

Why are you using two loops and what does it do when you run it? Any errors?
 
as far as i know there must be 2 loops.... to get the pyramid effect... no errors and i just displays
this
*
*
*
*
*
*

but 20 of them underneath each other...how do i get it to print it next to each other
 
as far as i know there must be 2 loops.... to get the pyramid effect... no errors and i just displays
this
*
*
*
*
*
*

but 20 of them underneath each other...how do i get it to print it next to each other

Well its not adding to the string every time. Create a string variable. For each iteration add a * within the first loop Something like:

stringVariable += "*"

then print using the nested loop:

ListBox1.Items.Add(stringVariable)

Edit: of course I mean declare and not create.
 
Last edited:
Actually I think Im just as confused as you now. :D
 
Now that I think about it that would make a wierd kind of stepped pyramid.
I still think you only need one loop.
 
dude w0w i got it to work

heres code

Dim ast As String
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
For K = 1 To 3 Step 1
For J = 4 To K Step -1
ast += "*"
ListBox1.Items.Add(ast)
Next
Next
End Sub
 
dude w0w i got it to work

heres code

Dim ast As String
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
For K = 1 To 3 Step 1
For J = 4 To K Step -1
ast += "*"
ListBox1.Items.Add(ast)
Next
Next
End Sub

Cool. :)
 
VB :sick:

Thats a common question in any language book, normally found as an excercise question.
 
lol now the tricky part....
how do i get this now

********
*******
******
*****
****
***
**
*
 
VB :sick:

Thats a common question in any language book, normally found as an excercise question.
i did this in turbo pascal...many many mo0ns ago... but 4got how...must b that blue screen that made me 4get

BTW
i like ur SQL quote
 
Last edited:
lol now the tricky part....
how do i get this now

********
*******
******
*****
****
***
**
*

Initialise the string as "*******",
then:

string -="*" ????

Not sure though.

Google is your friend.
 
i tried go0gle the just tell me how to create this with a while

*******
*******
*******
*******
 
Reverse the problem. Start with an initial high value and have your counter count down rather than up.

i did this in turbo pascal...many many mo0ns ago... but 4got how...must b that blue screen that made me 4get

BTW
i like ur SQL quote

Sadly 'tis true.
 
or

stars = "*****"
for k = 1 to 5 do
tempstring = left( stars, len( stars )-1)
print tempstring
stars = tempstring
loop
 
Top
Sign up to the MyBroadband newsletter
X