English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

誰能告訴我這圖形迴圈怎麼寫? For..next
1
12
123
1234
12345
1234
123
12
1

2006-02-06 14:53:48 · 7 個解答 · 發問者 Anonymous in 電腦與網際網路 程式設計

那如果數子由大到小怎麼改??
例:
5
54
543
5432
54321
5432
543
54
5 那還有別種寫法嗎?

2006-02-06 15:21:11 · update #1

請問愁痕飄絮:
那可以在請問一下嗎?如果我在Command裡面打數子可是那數字是未知數(意思是隨便打一個數字)呢?
那要更換哪裡程式碼?
(妳可以用你第三個寫法寫出來嗎?)還是有別寫法呢?

2006-02-06 17:06:19 · update #2

我的意思是如果你在command裡在數字例如打:20 。
然後就從1排到20
1
12
123
........以此類推到20
不知道我說的你懂不懂??

2006-02-06 18:07:00 · update #3

7 個解答

Private Sub Command1_Click()
Dim tmp As String, i As Integer
tmp = "12345"
For i = 1 To 5
Print Left(tmp, i)
Next
For i = 4 To 1 Step -1
Print Left(tmp, i)
Next i
End Sub

2006-02-06 21:06:54 補充:
數字由大到小:Private Sub Command1_Click()Dim tmp As String, i As Integertmp = "54321"For i = 1 To 5Print Left(tmp, i)NextFor i = 4 To 1 Step -1Print Left(tmp, i)Next iEnd Sub

2006-02-06 21:08:25 補充:
別種寫法:Private Sub Command1_Click() For i = 1 To 5 For j = 1 To i Print j; Next j Print Next i For i = 4 To 1 Step -1 For j = 1 To i Print j; Next j Print Next iEnd Sub

2006-02-06 23:01:26 補充:
看你的描述,可以直接套用我最原先回答給你的寫法只要更改 tmp這個變數裡面的內容就好。例如把 tmp那行 改成 tmp = "56789"那麼輸出的結果就會是5565675678567895678567565不知這樣的解釋你能理解並變通嗎?

2006-02-06 15:04:02 · answer #1 · answered by ? 6 · 0 0

同意+3
(繼續潛水....)

2006-02-08 09:49:35 · answer #2 · answered by ? 5 · 0 0

同意 +2 & 樓上的兩位也都是VB高手

2006-02-08 04:11:39 · answer #3 · answered by ALEXLEE 5 · 0 0

同意 +1

2006-02-07 04:05:14 · answer #4 · answered by Brian 5 · 0 0

最佳解答會很難選喔^^,愁痕飄絮、Liu-Liu及W.J.S.都是VB高手...

2006-02-06 17:22:06 · answer #5 · answered by 網頁設計被無名淹沒了. 7 · 0 0

'由小到大
Private Sub Command1_Click()
Dim S As String, I As Integer
For I = 1 To 5
  S = S & I: Print S
Next
For I = 4 To 1 Step -1
  Print Left(S, I)
Next
End Sub

'由大到小
Private Sub Command2_Click()
Dim S As String, I As Integer
For I = 5 To 1 Step -1
  S = S & I: Print S
Next
For I = 4 To 1 Step -1
  Print Left(S, I)
Next
End Sub

2006-02-06 16:17:51 · answer #6 · answered by W.J.S. 7 · 0 0

Private Sub Command1_Click() '小到大
 For i = -4 To 4
  For j = 1 To 5 - Abs(i)
   Print j;
  Next
  Print
 Next
End Sub

Private Sub Command2_Click() '大到小
 For i = -4 To 4
  For j = 1 To 5 - Abs(i)
   Print 6 - j;
  Next
  Print
 Next
End Sub

2006-02-07 08:25:49 補充:
以下可利用 n 值來改變其範圍:由小到大: n = 5 For i = -n + 1 To n - 1  For j = 1 To n - Abs(i)   Print j;  Next  Print Next由大到小: 將  Print j; 改成  Print n - j + 1; 即可。

2006-02-06 16:12:06 · answer #7 · answered by 世賢 7 · 0 0

fedest.com, questions and answers