1.11M Members

Asterisk Pattern Using Looping Statement

 
0
 

I just want to know how Can I display an asterisk pattern like

if the user selects on the combobox.additem = 1 then it will display

*
**
***
**
*

If user selects combobox.additem= 2 then

*
**
***
**
*
**
***
**
*

then so on and so forth until combobox.additem =2

Following were the codes that I have used...

Thank YOu

Dim x As Integer
Dim y As String


Private Sub cmdCreate_Click()
y = "*"
Wave = cboWave.Text

If Wave = "1" Then
x = 5
Do
Print y
x = x - 1
y = y + "*"
Loop Until x = 2

End If
End Sub
 
0
 

Try the following code. I have changed your if then to a select statement. When the "*" gets to 4, it counts back 1 at a time by removing the last "*" -

Option Explicit

Private Sub Command1_Click()

Dim x As Integer, z As Integer
Dim y As String, Wave As String

x = 5
z = 3
y = "*"
Wave = cboWave.Text

Select Case Wave

Case 1
    Do
    Print y
    x = x - 1
    y = y + "*"
    Loop Until x = 2
    
    Do
    Print y
    If y = vbNullString Then
        Exit Sub
            Else
        y = Left$(y, Len(y) - 1)
    End If
    Loop Until x = 0
End Select
End Sub

Just play around if user selects 2, 3, 4 etc from combobox.

 
0
 

thanks for the help

 
0
 

Only a pleasure. If this solved your problem, please mark it as solved, thanks.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article