Hello all!
I am working on a program which should be easy, but I am making it harder than it should be on myself.
I need to make a program that if I press the button below each ListBox that it displays the corresponding output.
How my teacher would like us to do this is to actually make each one a rectangle and half of the characters be spaces and the other half be A, B, C or D. Does that make sense?
So for the first output is should be like this...
lets say space = #
A#########
AA########
AAA#######
AAAA######
AAAAA#####
AAAAAA####
AAAAAAA###
AAAAAAAA##
AAAAAAAAA#
AAAAAAAAAA
Here is a flowchart we made in class in Visual Logic, I am not sure if any of who have heard of this, but either way here is the flowchart.
Here is the corresponding code implemented into Visual Basic.
vb.net Code:
Dim number As Integer Dim FirstCharacter As String Dim SecondCharacter As String Dim row As String number = 5 FirstCharacter = "A" SecondCharacter = "*" row = "" For count = 1 To number For firstCount = 1 To count row = row & FirstCharacter For secondCount = 1 To ((number - firstCount) + 1) row = row & SecondCharacter Next Next lstOutputA.Items.Add(row) row = "" Nextt
Now I am not sure what I did wrong, but this code doesn't work in Visual Basic. I The output is...
A*****
A*****A****
A*****A****A***
A*****A****A***A**
A*****A****A***A**A*
NOTE: I am using the "*" to represent spaces so I can see where they are.
I am pretty sure it is because these...
vb.net Code:
For firstCount = 1 To count row = row & FirstCharacter For secondCount = 1 To ((number - firstCount) + 1) row = row & SecondCharacter Next Next
Need to be separated loops instead of nested loops. So they should be like this...
vb.net Code:
For firstCount = 1 To count row = row & FirstCharacter Next For secondCount = 1 To ((number - firstCount) + 1) row = row & SecondCharacter Next lstOuput.Items.Add(row) row = ""
The only problem is firstCount in the secondCount loop becomes invalid because it is not yet declared.
So how would I get around that?
Any help would be greatly appreciated!
Thanks!








Reply With Quote