How can I show these numbers exactly the same on the form?
(By clicking on a command button and printing them on the form)
Thanks in advance everyone :) (btw, I'm a beginner so please use the easiest way) ;)
( The "*" character means space. I actually need SPACE instead of *
But here I couldn't show it using space so I put * instead.)
1234567
*12345*
**123**
***1***

Dani AI

Generated

Use a control that actually preserves leading/trailing spaces and a monospaced font. Labels often drop leading spaces, so the simplest, most reliable choice is a multiline TextBox (set MultiLine = True and Locked = True to make it read-only) and set its Font.Name to "Courier New". That guarantees each character — including spaces — occupies the same width so the columns line up.

Concept: start with the full string "1234567", then reduce the number of visible digits by two each row while padding the left and right with the same number of spaces so the total width stays 7. pointed out using a loop and padding; showed the manual Print approach. A short loop produces the same output cleanly and will adapt if you change the base string.

Example (VB6):

Private Sub Command1_Click()
    Dim base As String
    base = "1234567"
    Dim i As Integer
    Dim out As String
    out = ""
    For i = 0 To 3
        out = out & String$(i, " ") & Left$(base, Len(base) - 2 * i) & String$(i, " ")
        If i < 3 Then out = out & vbCrLf
    Next i
    Text1.Font.Name = "Courier New"
    Text1.MultiLine = True
    Text1.Locked = True
    Text1.Text = out
End Sub

Troubleshooting: if alignment looks wrong, verify the TextBox is using a monospaced font and that you are inserting real space characters (HTML forum posts collapse spaces, but VB sees them). If you must use a Label and need visible leading spaces, fill them with Chr$(160) (non-breaking space) — but the multiline TextBox or Form.Print with a monospaced font is simpler.

Recommended Answers

All 2 Replies

One way would be to use a for loop from 7 to 1 step -2 and inside of that loop you would need to use the Space Function, to set the number of spaces you will need to pad to the left, and the Left Function to grab x number of characters from a string that you initialize before you go into the loop.

Good Luck

did you try this:

Private Sub Command1_Click()
Print "1234567"
Print " 12345 "
Print "  123  "
Print "    1  "
End Sub

I don't understand what u need to do. vb5prgrmr said nice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.