I'm new using Visual Basic, so I need help.

For example:

If I input "14" into the textbox, i want to have a list that will say:

1
2
3
4
5
.
.
.
14

I have a counter in my program, but I have no clue how to use it correctly. Please give me the code to bump up the count to display the list above.

Secondly, I want to create "Do-While Loop" that will give me the cubes of the numbers.

1       1
2       8
3       27
4       64
5       125
.
.
.
14     2744

I'm currently stuck, and I am not familiar with the code VB.

This is what I have so far:

Dim Product1 As Integer  ' Is the list for the numbers: 1 2 3 4 5 6 7 8 etc
        Dim Product3 As Integer  '  is the list for the cubes of the numbers
        Dim Max As Integer
        Dim Counter As Integer

        lstProduct3.Items.Clear()
        Max = txtnumber.Text


        Product1 = txtnumber.Text
        Do While Product1 < 15
            Product3 = Product1 * 3
            lstProduct3.Items.Add(Product3)
            If Product1 > 15 Then
                Exit Do
            End If



        Loop

        Exit Sub

    End Sub

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hi,

you can change your code

Max = txtnumber.Text
        Product1 = txtnumber.Text
        Do While Product1 < 15
            Product3 = Product1 * 3
            lstProduct3.Items.Add(Product3)
            If Product1 > 15 Then
                Exit Do
            End If
        Loop

as

Max = Val(txtnumber.Text)
        Product1 = 1  ' Start with the First Value

        'Iterate 1 2 3 -- Upto Max
        Do While Product1 < Max
            ' Find the Cube Of the Number 
            Product3 = Product1 * Product1 * Product1
            ' For the Number 1 2 3 4 .. Upto Max
            lstProduct1.Items.Add(Product1)
            ' For the Cube of 1 2 3 4 ...
            lstProduct3.Items.Add(Product3)
            ' Update Product1 Value to Next
            Product1 = Product1 + 1
        Loop

do you want to put the data in the listbox? or you want to have a list of textbox according to the number you have entered?

hi !!!!!!!!
i m completly new to visual basic 6 n i want tomaster this language .how should i start working on it.can anyone suggest me some books ..........

do you want to put the data in the listbox? or you want to have a list of textbox according to the number you have entered?

Yes, I need to do it in a list box.


I have to get the cubes by doing the "Do-While", "For..Next", and "Do Until" loops.

For example:

The user enters a numbers....Lets say 14

After I click any of the buttons named "Do While", "For..Next", or "Do Until", it will give me a list of numbers from 1-14 and for each button i press, it will cube me the cubes for those numbers 1-14.

Alright, I have everything done except the "Do-Until" loop...The same rules apply. I'm trying to get the counter to read the input of the numbers.

For example, if I put in 14 for input...

The list will print

1
2
3
4
5
6
7
.
.
.
14

The Product4 in my code is to get the cubes of all numbers in the list.

1 1
2 8
3 27
4 64
5 125
etc.

This is what I have so far...

    Dim Product4 As Integer ' To add up the cubes
    Dim Values1 As Integer ' to get the list of numbers
    Dim Max As Integer
    Dim Counter As Integer

    lstProduct4.Items.Clear()
    lstValues.Items.Clear()
    Max = txtnumber.Text

    Values1 = 0
    Do Until Values1 > 15
        Counter = Counter + 1
        Values1 = Values1 + 1
        Product4 = Values1 * Values1 * Values1
        lstProduct4.Items.Add(Product4)
        lstValues.Items.Add(Values1)
        Exit Do

    Loop

    Exit Sub
End Sub

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I'll just give you the Do While...

Suppose you have a textbox that will accept the numbers to be cubed.

Dim i As Integer

i =1
list1.Clear
Do While i <= Val(Text1.Text)
      list1.Add  i  &  vbTab &  "3"  & vbTab  &  i * 3
      i = i + 1
Loop

It's still the same honey...

Dim i As Integer

i =0
list1.Clear
Do 
      i = i + 1
      list1.Add  i  &  vbTab &  "3"  & vbTab  &  i * 3
Loop Until i <= Val(Text1.Text)

Ooops! sorry for the cubes...

for the Do While

Dim i As Integer

i =1
list1.Clear
Do While i <= Val(Text1.Text)
      list1.Add  i  &  vbTab &   i ^ 3
      i = i + 1
Loop

and as for the Do Until...

Dim i As Integer

i =0
list1.Clear
Do 
      i = i + 1
      list1.Add  i  &  vbTab &  i ^ 3
Loop Until i <= Val(Text1.Text)

Correction in Do Until...

Dim i As Integer

i =1
list1.Clear
Do Until i = Val(Text1.Text)
      list1.Add  i  &  vbTab &  i ^ 3
      i = i + 1
Loop
This article has been dead for over six months. Start a new discussion instead.