看板 Visual_Basic 關於我們 聯絡資訊
※ 引述《stormbird (單眼皮)》之銘言: : 我想寫一個在Text.text裡面連續出現數字的一個東西 : 例如:我在Text1.text=48,Text2.text=51 : 而我要在Text3.text依序出現49,50,51 : 如果Text1.text=48,Text2.text=48 : 則Text3.text=48 : 我有先寫出來,但是出現的都不是我想要 : 我這樣寫不知是否正確 : 請各位給我一點指教,指點指點我,謝謝 小弟改一下您的程式 (sorry, 身邊電腦沒裝VB6, 用 .Net 假裝一下) Dim n1 As Integer Dim n2 As Integer 'CInt是轉換為integer的函數, vb6或有不同 n1 = CInt(Text1.Text) n2 = CInt(Text2.Text) '比較兩數大小, 不過預防出現 n1=48, n2=49這種情形 '所以規定 abs(n1-n2) >1 if abs(n1-n2)>1 then If n1 > n2 Then For i = (n1+1) To (n2-1) Step -1 Text3.Text = "" Text3.Text = i Next i ElseIf n1 < n2 Then For i = (n1+1) To (n2-1) Step 1 Text3.Text = "" Text3.Text = i Next i end if '只剩下 abs(n1-n2)<=1 這種情形 (ex : n1=48, n2=49; 或是 n1=n2=48) '如果n1=n2 => 兩數相加除以2 答案不變 '如果n1=48, n2=49 => 看要出現 48.5 這種答案還是出現錯誤 '這邊取 48.5 else Text3.Text = "" Text3.Text = CInt((n1+n2)/2) end if 請參考, 如有錯誤尚請指正 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.174.190.186
SmallBeeWayn:你反而把問題複雜化了 03/24 20:19
sky008888:哈~~樓上寫的比較簡潔, 我是依照原 po 提供的 code 改一 03/24 21:46
sky008888:下而已... 03/24 21:47