這是我寫的亂數程式,但發生錯誤。可否請指出哪裡有錯,如何修改??Private Sub Command1_Click()
Dim R(1 To 20) As Integer
 Dim i, j As Integer
 Dim temp As Integer
 Dim SQL As String
 Dim str
'宣告一個connection類別的物件變數
Dim con As ADODB.Connection
'宣告一個recordset類別的物件變數
Dim rs As ADODB.Recordset
'隨機產生n個亂數
Randomize
 For i = 1 To 20
  R(i) = Int(Rnd() * 1001) + 1
 Next
'將重複之亂數加1
For i = 2 To 20
  For j = 1 To j - 1
   If R(j) = R(i) Then
    R(j) = R(j) + 1
   End If
  Next
 Next
'利用氣泡排序法依遞增排序
For j = 1 To 19
  For i = 1 To 19
   If R(i) > R(i + 1) Then
    temp = R(i)
    R(i) = R(i + 1)
    R(i + 1) = temp
   End If
  Next
 Next
'顯示隨機抽取題號'
str = "丙檢試題.題號=" & R(1) & "or"
  For i = 1 To 19
   str = str & "丙檢試題.題號=" & R(i) & "or"
  Next i
str = str & "丙檢試題.題號=" & R(20)
 SQL = "SELECT 丙檢試題.題號, 丙檢試題.題目, 丙檢試題.選項一, 丙檢試題.選項二, 丙檢試題.選項三, 丙檢試題.選項四, 丙檢試題.難易度"
 SQL = SQL & " From 丙檢試題 WHERE 丙檢試題.題號= str"
 Adodc1.RecordSource = SQL
 Adodc1.Refresh
'建立物件,並且指定給con物件變數
Set con = New ADODB.Connection
'利用ODBC開啟資料庫
con.Open "886440"
'建立物件,並且指定給rs物件變數
Set rs = New ADODB.Recordset
'設定ADO開啟資料庫的方法
rs.CursorLocation = adUseClient
 rs.Open SQL, con, adOpenKeyset, adLockOptimistic
 rs.Close
 Set rs = Nothing
 con.Close
 Text1.Visible = True
 Text2.Visible = True
 Text3.Visible = True
 Text4.Visible = True
 Text5.Visible = True
 Text6.Visible = True
 Text7.Visible = True
 Text8.Visible = True
End Sub
Private Sub Form_Load()
Dim con As ADODB.Connection
 Dim rs As ADODB.Recordset
 Dim SQL As String
 Set con = New ADODB.Connection
 con.Open "886440"
 SQL = "select * from 成績單"
 Set rs = New ADODB.Recordset
 rs.CursorLocation = adUseServer
 rs.Open SQL, con, adOpenKeyset, adLockReadOnly
 rs.MoveLast
 labno.Caption = rs(0).Value
 Refresh
 rs.Close
 Set rs = Nothing
 con.Close
 Set con = Nothing
  Text1.Visible = False
 Text2.Visible = False
 Text3.Visible = False
 Text4.Visible = False
 Text5.Visible = False
 Text6.Visible = False
 Text7.Visible = False
 Text8.Visible = False
End Sub
創作者介紹
創作者 vbqa 的頭像
vbqa

小吳 VBQA 程式設計討論

vbqa 發表在 痞客邦 留言(0) 人氣()