Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

關於VB6的數字菱形

如果輸入4

就會顯示

    0

   010

  01210

 0123210

012343210

 0123210

  01210

   010

    0

題目就這樣

沒有其他的

2 Answers

Rating
  • 1 decade ago
    Favorite Answer

    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
Still have questions? Get your answers by asking now.