Post: Visual Basic Quick Question
03-28-2015, 08:30 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); I am having a problem getting my "*" to increase as the lines increase. What would you recommend to do this? I'm new to VB and this is a HW question. Thanks for any advice!

use the value in TB1 as the size. Clear the ListBox. Draw a triangle of *’s in the ListBox with 1 * on the first line and each successive line having 1 more * than the line before up to a line with size number of *. Then it should go down until there is 1 *. There should be 2*size -1 number of lines and size number of * on the middle line. For example, a size 4 triangle would result in :
03-28-2015, 09:06 PM #2
jagex
Gym leader
Your question and wording is very hard to understand :s
03-28-2015, 09:10 PM #3
Originally posted by jagex View Post
Your question and wording is very hard to understand :s


Sorry, ill try to re-explain it.
So if i put 4 into Textbox 1 and hit the button "Triangle" then my listbox will have
*
**
***
****
***
**
*

I am unsure of how to make my *'s increase and decrease accordingly.
03-28-2015, 10:09 PM #4
jagex
Gym leader
    
private void Add_Stars(int amtStars)
{
string[] stars = new string[amtStars];
char astrik = '*';
int count = 1;

for (int i = 0; i < stars.Length; i++)
{
stars[i] = new string(astrik, count);
count++;
listBox1.Items.Add(stars[i]);
}


I have to go to a wedding, just need code the "decreasing" part.

edit: quickly added a decreasing method but it doesn't add the last star has to do with != 0 i think lol :p

    
for (int i = 0; i <= stars.Length; i++)
{
if(i == stars.Length)
{
for(int j = i - 2; j != 0; j--)
{
listBox1.Items.Add(stars[j]);
}
break;
}
stars[i] = new string(astrik, count);
count++;
listBox1.Items.Add(stars[i]);
}


Need to add a check to make sure the text enter is a number but you can do that as well.
    
private void button1_Click(object sender, EventArgs e)
{
Add_Stars(Convert.ToInt16(textBox1.Text));
}
Last edited by jagex ; 03-28-2015 at 10:34 PM.

The following user thanked jagex for this useful post:

Pichu
03-29-2015, 12:03 AM #5
TehMerkMods
I’m too L33T
Originally posted by Conveyy View Post
Sorry, ill try to re-explain it.
So if i put 4 into Textbox 1 and hit the button "Triangle" then my listbox will have
*
**
***
****
***
**
*

I am unsure of how to make my *'s increase and decrease accordingly.


why not just use the pre-mad text box function? If you go to your text box properties and you can add something to do with passwords :P Just set it to true then it turns into *'s or in my case circles with a flat theme
03-29-2015, 12:08 AM #6
jagex
Gym leader
I dont thats what his assignment requires though

If I understood correct it needs to add * based on the number inputted but one on each line incrementing each time and once it reaches the number, go backwards.

The following user thanked jagex for this useful post:

Conveyy

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo