VB6如何使用MSFlexGrid表格產生亂數

2010-01-19 7:29 pm
原本小弟是使用多個textbox1產生亂數,因為有大筆資料所以改用MSFlexGrid,這樣不知道可不可行.如果可以那程式碼如何修改..請專家指點說明!

以下程式碼是用多個textbox1+button1的程式碼
Private Sub Command1_Click()
For i = 0 To 5
Text1(i).Text = Round(Rnd, 2)
Next
End Sub

執行結果排列方式如下
試題 V1 V2 V3 V4 V5
001: 0.13 0.33 0.45 0.98 0.45
002: 0.42 0.65 0.86 0.54 0.76
003: 0.99 0.01 0.21 0.44 0.67
更新1:

to:david 差別只是填入的目的地不同吧?這段是什麼意思@@'我有試過把程式碼載入到MSFlexGrid,但是那部份個人還不熟,所以不知道程式該如何改寫...

回答 (2)

2010-01-19 10:49 pm
✔ 最佳答案
拉一個Command1和MSFlexGrid1貼上以下程式碼並執行即可


Private Sub Command1_Click() ' 取亂數
Dim i As Integer, j As Integer
Randomize
For j = 1 To 3
For i = 1 To 5
MSFlexGrid1.Col = i
MSFlexGrid1.Row = j
MSFlexGrid1.Text = Round(Rnd, 2)
Next i
Next j

End Sub

Private Sub Form_Load() ' 初始表格大小,以您上述的執行結果為例
Dim c As Integer
Dim r As Integer
Command1.Caption = "取亂數"
MSFlexGrid1.Cols = 6
MSFlexGrid1.Rows = 4

MSFlexGrid1.Col = 0
MSFlexGrid1.Row = 0
MSFlexGrid1.ColAlignment(0) = 3
MSFlexGrid1.Text = "試題"
For c = 1 To 5
MSFlexGrid1.Col = c
MSFlexGrid1.Row = 0
MSFlexGrid1.Text = "V" & c
Next c

For r = 1 To 3
MSFlexGrid1.Col = 0
MSFlexGrid1.Row = r
MSFlexGrid1.Text = "00" & r & ":"
Next r
End Sub
2010-01-19 9:34 pm
產生亂數填入 textbox



產生亂數填入 msflexgrid

差別只是填入的目的地不同吧


收錄日期: 2021-05-03 13:16:27
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100119000015KK02359

檢視 Wayback Machine 備份