# 關於VB6的數字菱形

０

０１０

０１２１０

０１２３２１０

０１２３４３２１０

０１２３２１０

０１２１０

０１０

０

Rating

Dim n%, flag%, temp!, num#

Private Sub Form_Activate()

Do

n = Val(InputBox("請輸入大於0且小於10之正整數", N值))

Loop Until n > 0 And n < 10

num = 1: temp = 10

For i = -n To n

flag = Abs(i)

If flag = n Then

Print Tab(flag + 1); "0"

ElseIf flag = n - 1 Then

Print Tab(flag + 1); "010"

Else

If temp = 10 And (n < 9 Or flag <> 0) Then

Print Tab(flag + 1); "0" & Val(String(2 * (n - Abs(i)) - 1,

"1")) + num * 10 & "0"

num = Val(String(2 * (n - Abs(i)) - 1, "1")) + num * 10

ElseIf temp = 10 And n = 9 And flag = 0 Then

Print "0123456789876543210"

num = Val(String(2 * (n - Abs(i)) - 1, "1")) + num * 10

ElseIf temp = 0.1 Then

Print Tab(flag + 1); "0" & (num - Val(String(2 * (n -

Abs(i)) + 1, "1"))) / 10 & "0"

num = (num - Val(String(2 * (n - Abs(i)) + 1, "1"))) / 10

End If

If flag = 0 Then

temp = 0.1

End If

End If

Next i

End Sub

Source(s): me

你先拉一個Button 和 兩個Textbox後...

在Button_chick的條件裡打下下面這些程式碼就好了...

Dim x,i,j As Integer

x = CInt(TextBox1.Text)

TextBox2.Text = Nothing

For i = 0 To x

For j = 1 To x - i

TextBox2.Text &= " "

Next

For j = 0 To i

TextBox2.Text &= CStr(j)

Next

For j = i - 1 To 0 Step -1

TextBox2.Text &= CStr(j)

Next

TextBox2.Text &= vbNewLine

Next

For i = x - 1 To 0 Step -1

For j = 1 To x - i

TextBox2.Text &= " "

Next

For j = 0 To i

TextBox2.Text &= CStr(j)

Next

For j = i - 1 To 0 Step -1

TextBox2.Text &= CStr(j)

Next

TextBox2.Text &= vbNewLine

Next

Source(s): Me