I am busy with a program that randomly selects data from a databse and then populates controls with the random data. the user must then select an option that must be stored for printing at the end of the program.
Below I have pasted my code. I am using VB6 and MSAccess Database.
Thanking You in Advance.
Julian
ps. I am a beginner
Expand|Select|Wrap|Line Numbers
- Option Explicit
- Dim CN As ADODB.Connection
- Public RS As ADODB.Recordset
- Dim i As Long
- Dim strArray(5) As Long
- Dim x As Long
- Dim z As Long
- Dim WordCounter As Long
- Dim CurrentWord As Long
- Dim SQL As String
- Private Sub OpenConnection()
- Set CN = New ADODB.Connection
- CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\cas.mdb"
- CN.Open
- End Sub
- Private Sub ReturnRecords()
- Set RS = New ADODB.Recordset
- OpenConnection
- With RS
- .ActiveConnection = CN
- .Source = "SELECT * FROM [caslit]"
- .CursorType = adOpenStatic
- .LockType = adLockOptimistic
- .Open
- End With
- End Sub
- Private Sub cmdNext_Click()
- Test 'jumps to sub. to generate the next question
- lblStatus.Caption = RS.AbsolutePosition & " of " & RS.RecordCount
- End Sub
- Private Sub Form_Load()
- ReturnRecords
- lblDate.Caption = Date
- lblTime.Caption = Time
- 'Test
- Finder
- lblStatus.Caption = RS.AbsolutePosition & " of " & RS.RecordCount
- End Sub
- Private Sub Form_Paint()
- Dim wid As Single
- Dim hgt As Single
- Dim x As Single
- Dim y As Single
- wid = Picture1.ScaleWidth
- hgt = Picture1.ScaleHeight
- y = 0
- Do While y < ScaleHeight
- x = 0
- Do While x < ScaleWidth
- PaintPicture Picture1.Picture, _
- x, y, wid, hgt
- x = x + wid
- Loop
- y = y + hgt
- Loop
- End Sub
- Private Sub mnuExit_Click()
- Set CN = Nothing
- Set RS = Nothing
- Load frmIndex
- frmIndex.Show
- Unload Me
- End Sub
- Private Sub Test()
- Dim RndNum As Long
- Dim strCount As Long
- For i = 0 To 5
- If strCount = 1 Then
- i = i - 1
- strCount = 0
- End If
- strCount = 0
- Randomize
- RndNum = Int((5 * Rnd) + 1)
- x = 0
- For x = 0 To i
- If strArray(x) = RndNum Then
- strCount = 1
- End If
- Next x
- If strCount < 1 Then
- strArray(i) = RndNum
- strCount = 0
- End If
- Next i
- 'Call Finder
- End Sub
- Private Sub Finder()
- Call Test
- WordCounter = 5
- 'create
- SQL = "SELECT * FROM caslit WHERE indexid="
- CurrentWord = 0
- For z = 0 To WordCounter - 1
- If z <> WordCounter - 1 Then
- SQL = SQL & "'" & strArray(z) & "' OR indexid="
- CurrentWord = CurrentWord + 1
- ElseIf z = WordCounter - 1 Then
- SQL = SQL & "'" & strArray(z) & "'"
- End If
- Next z
- lblQuestion.Caption = RS!question
- OptA1.Caption = RS!c1
- OptA2.Caption = RS!c2
- OptA3.Caption = RS!c3
- OptA4.Caption = RS!c4
- End Sub