|
-
Dec 13th, 2010, 05:34 PM
#1
Thread Starter
Junior Member
Extremely Easy Program That I Am Making Hard
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!
Last edited by Adampff; Dec 13th, 2010 at 05:50 PM.
-
Dec 13th, 2010, 05:41 PM
#2
Re: Extremely Easy Program That I Am Making Hard
The first two loops are pretty good, except that both should go to N where N is the number of lines you want (you use 5, but I see no part of your example that has only 5 lines). The loops would look like:
Code:
For x = 1 to N
For Y = 1 to N
If Y>X Then
'Add the space
Else
'Add the character
End If
Next
Next
My usual boring signature: Nothing
 
-
Dec 13th, 2010, 05:49 PM
#3
Re: Extremely Easy Program That I Am Making Hard
If you're looking to do a literal translation of that flowchart into Visual Basic, then you've made a mistake. The flowchart shows a loop from 1 to number (looping the rows). Inside that loop are two loops, one to make the "first char"s and one to make the "second char"s. It is these two loops that you've made a mistake in translating.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|