- 帖子
- 406
- 主題
- 8
- 精華
- 0
- 積分
- 453
- 點名
- 0
- 作業系統
- WINDOWS 7
- 軟體版本
- 2007
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 台灣
- 註冊時間
- 2015-2-7
- 最後登錄
- 2021-7-31
|
本帖最後由 n7822123 於 2020-6-17 02:06 編輯
回復 1# 軒云熊
需求:
請問前輩們 以下這段該如何改寫 才能夠改成動態的規律 如何可以縮減程式碼
If TextBox2.Value = 1 Then A = Array(3, 5, 7, 15, 17, 19)
If TextBox2.Value = 2 Then A = Array(5, 7, 9, 17, 19, 21)
If TextBox2.Value = 3 Then A = Array(7, 9, 11, 19, 21, 23)
If TextBox2.Value = 4 Then A = Array(9, 11, 13, 21, 23, 25)
If TextBox2.Value = 5 Then A = Array(11, 13, 15, 23, 25)
If TextBox2.Value = 6 Then A = Array(13, 15, 17, 25)
If TextBox2.Value = 7 Then A = Array(15, 17, 19)
If TextBox2.Value = 8 Then A = Array(17, 19, 21)
If TextBox2.Value = 9 Then A = Array(19, 21, 23)
If TextBox2.Value = 10 Then A = Array(21, 23, 25)
If TextBox2.Value = 11 Then A = Array(23, 25)
If TextBox2.Value = 12 Then A = Array(25)
If TextBox2.Value = "" Then A = Array(3, 5, 7, 15, 17, 19)
同意準大說的,自己寫的程式自己能看懂,才是最好的!
別人寫的很短很厲害,你如果看不懂,之後要改程式也無從下手,會更痛苦
依你的需求,程式改成如下,但執行速度不會比較快~
k = TextBox2.Value: If k = "" Then k = 1
For i = k To 12: Idx = Idx + 1
If Idx < 4 Or Idx > 6 Then
itm = itm + 1: If itm = 7 Then Exit For
s = s & "," & i * 2 + 1
End If
Next i
A = Split(Mid(s, 2), ",") |
|