borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB Home | News Home | Forum Home | Downloads | Register | Search | PM | Profile

Previous Topic (MsgHook.dll download?)Next Topic (Passing Value to Crystal Report 8.5) New Topic Post Reply
AndreaVB OnLine : VB General : adapting code for form 2.0
Poster Resource
ram_son
Level: Graduate

Registered: 01-05-2005
Posts: 11
icon adapting code for form 2.0

Somebody on this forum helped me with this code a while back and it worked fine on a regular form in vb6 but when I tried to use it on a Forms 2.0 it generated a

runtime error 13
type mismatch

and points to the Checklabel Lbl corresponding to the label clicked. Any help on this will be appreciated.

-----------------------------

Private Sub lbl1_Click()
    CheckLabel Lbl1
End Sub

Private Sub lbl2_Click()
    CheckLabel Lbl2
End Sub

Private Sub lbl3_Click()
    CheckLabel Lbl3
End Sub

Private Sub lbl4_Click()
    CheckLabel Lbl4
End Sub

' checks if the clicked label caption has the same value
' of the correct answer variable. If so, loads another question
' otherwise it says "Try again"

Private Sub CheckLabel(lbl As Label)
    If lbl = ca Then
        LoadQuestion
    Else
        MsgBox "Try again"
    End If
End Sub

05-05-2006 at 03:25 AM
View Profile Send Email to User Show All Posts | Add Comment
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: adapting code for form 2.0

Hi

quote:
If lbl = ca Then



Where's the declaration of ca, and which property of the label are you trying to use, for example the caption?


Steve  

[Edited by steve_w on 05-05-2006 at 09:31 AM GMT]
05-05-2006 at 09:31 AM
View Profile Send Email to User Show All Posts | Add Comment
ram_son
Level: Graduate

Registered: 01-05-2005
Posts: 11
icon Re: adapting code for form 2.0

Thanks...That didn't work.
However I was told to change the CheckLabel to CheckAnswer and that seems to have solved the problem.

Maybe you can help me with anoyher issue if you don't mind... It's about choosing the questions randomly.It seems like the choice of question is not really that random as it always starts with the same choice and seems to folow a predictable pattern. Below is the code that I think is responsible for the choices ... the way somebody helped me to
create.

Let me know how I can improve that..


--------------------

Private Sub LoadQuestion()

Set DB = OpenDatabase("D:\....file.mdb")
Set RS = DB.OpenRecordset("select * from qRandomAnswers")

Dim op(1 To 3) As String ' , op2 As String, op3 As String
Dim randomArr(0 To 3) As String
Dim I As Integer, rc As Long
' clear all the labels
lbltext.Caption = ""
Lbl1.Caption = ""
Lbl2.Caption = ""
Lbl3.Caption = ""
Lbl4.Caption = ""
' initialize the system randomizer, in order to randomly
' execute the query
Randomize
' load the recordset from the query
' fills the variables
qt = RS.Fields("QuestionText").Value
ca = RS.Fields("CorrectAnswer").Value

' load the temporary variables with the optional wrong values
RS.MoveFirst
Do While Not RS.EOF
I = I + 1
op(I) = RS.Fields("Correct").Value
RS.MoveNext
Loop
rc = I + 1 ' simulates a records counter, as this recordset
' doesn't expose a RecordCount property to read
' fill the text label
lbltext.Caption = qt
' randomize the four answers from the query into an array

I = Int((rc - 1 + 1) * Rnd + 1) - 1 ' generates a random number 0-3
randomArr(I) = ca
randomArr((I + 1) Mod rc) = op(1)
randomArr((I + 2) Mod rc) = op(2)
randomArr((I + 3) Mod rc) = op(3)

' fills the array values into the labels

Lbl1.Caption = randomArr(0)
Lbl2.Caption = randomArr(1)
Lbl3.Caption = randomArr(2)
Lbl4.Caption = randomArr(3)

' I'm forced to use four separate labels, as MSAccess doesn't support
' arrays of controls. In VB I'd create an array of four labels
End Sub

05-05-2006 at 11:43 AM
View Profile Send Email to User Show All Posts | Add Comment
AndreaVB OnLine : VB General : adapting code for form 2.0
Previous Topic (MsgHook.dll download?)Next Topic (Passing Value to Crystal Report 8.5)New Topic Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder