# Thread: [RESOLVED] how to split a integer into equal parts into a listbox

1. ## [RESOLVED] how to split a integer into equal parts into a listbox

I'm making an application where the user inputs the number of equal parts they want to break up a number, assume it is 1. The output should be displayed in a listbox and should be numbered.

So for example, lets say the user puts in 2 for the input and we assume the number we are cutting into equal parts is 1, the output would be:
1)0.500
lets say the user inputs 4, the output would be:
1)0.250
2)0.500
3)0.750

and so on depending on the user input.

I understand I need to use a loop but I can't figure out how to get the output into equal pieces. I know I would divide the input by 1, so for instance if i enter in 4, i would do 1/4 which is .250 but how do i split it into equal parts like the example above.

2. ## Re: how to split a integer into equal parts into a listbox

Your description of what you are looking for is somewhat ambiguous. What you are describing as "equal parts" isn't exactly clear, but I think I might get it.

If I entered 10, is what you are looking for:

.100
.200
.300
.400
.500
.600
.700
.800
.900?

If so, then I think all you need is something like this:

Code:
```Dim intNumerator, intDenominator As Integer
intDenominator = CInt(txtUserInput.Text)

For intNumerator = 1 to intDenominator - 1
lstOutput.Items.Add (intNumerator.ToString & ")" & FormatNumber(intNumerator / intDenominator, 3)
Next```
Edit: I'm not at a computer with VB.NET installed, so the above code wasn't tested.

3. ## Re: how to split a integer into equal parts into a listbox

Sorry, its a bit confusing to me too but yes that is what I'm looking for. To split a number up into the number of parts that the user inputs, so just as you did by entering 10 and thus the output was the number ,1 , divided into 10 equal parts. Thanks alot

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured