Write a VB program in which function accepts the integer value from the user and displays the diamond shape according to the user input.
(A)Program Design :
(B) Property(Controls Used) :
- A Label with Caption "Enter Number"
- A Text Box to enter number
- A command Button with Caption "Display"
- A List Box to display Shape
Private Sub Command1_Click() Dim i Dim j Dim NumLines, str NumLines = CInt(Text1) List1.Clear For i = 0 To NumLines / 2 For j = i To NumLines / 2 + 1 str = str & "" Next For j = 0 To i Step 1 str = str & "**" Next List1.AddItem (str) str = "" Next For i = 1 To NumLines / 2 For j = 0 To i + 1 str = str & " " Next For j = i To NumLines / 2 str = str & "**" Next List1.AddItem (str) str = "" Next End Sub |
(D) Output :
(E) Errors :
If found any errors while running your VB program, please click this link Possible Errors while running VB Programs to get a solution.
===============================================
===============================================