Visual Basic 6 - Example Three For Drag
& Drop Operation
4. Example3 for Drag & Drop
Type Question
4.1 Brief Description of Example3
Example 3 is slightly different from Example2.
This example (project) contains Drag & Drop for fill
in the blanks type questions.
Also it explains how to display the blank spaces in middle
of the question
Here control for answer option is created in the design
view as control array (i.e. minimum no. of option given
are 12)
These options are dragged and dropped on the required
places
Fig9 Design view of the form for Drag & Drop fills
in the blanks type questions
In the question two or more blank spaces may contain the
same answer.Same answer is stored in the database for this
Observe the below table structure, here AnsSrNo 1 & 2
has the same answer
While giving Answer option to candidate only one option is
given
That means duplicate Answer column is omitted.
For this small function is written which checks for duplicate
answer colums
Private Function checkforcaption(strcaption As String) As Boolean
Dim i As Integer
checkforcaption = False
For i = 0 To lblansopt.Count - 1
If lblansopt(i).Visible = True And Trim(lblansopt(i).Caption) = strcaption Then
checkforcaption = True
Exit For
End If
Next
End Function
For more details of coding you can download below zip file
(dragdropdemo2.zip) Which gives you the clear idea of the entire
project
AnsSrNo
Answer
AnsRnd
AnsSel
Qid
1
Pattern
10
0
1
2
Pattern
12
0
1
3
Compile
1
0
1
4
[a][x]+
8
0
1
5
Matcher
4
0
1
6
p
6
0
1
7
axxaxaxxax
3
0
1
8
m
2
0
1
9
group()
5
0
1
10
start
11
0
1
11
pattern
7
0
1
12
matcher
9
0
1
For example the question stored in the database may be looks
as shown below
Import java.io. *;
Class Test
{
public ** void (** )
{
Int [] y= {10,20,30,40};
process(y);
}
Public static void process (int ** **)
{
System.out.println (**);
}
}
Note: *(star) in the question is for fill in blanks where
candidate can drop the correct answer.
To retrieve the question field from table, a query is executed
For this first create a connection object and open the connection
using 'Open' method
Next create recordset object where you can pass SQL statement
to get the required records from particular table.
For Example to retrieve the Question field from table following
query is written
Select Question from table name;
The above query displays all the records of the Question
field from specified table.
After retrieving the question field we can bind the value
of this field to required control or any variable.
In this project a procedure named displaythequestion is written.
In this procedure value of the Question field is assigned to
a String variable.
Procedure is written such a way that fist it extracts question,
stored in the string variable. And based on the no. of question,
control for question is created and question string is displayed
in it.
Next it extracts the special character (**) from the question,
stored in the string variable and depending on the no. of special
character, control for the same is created.
Another procedure 'displaythestring' called inside the 'displaythequestion'
procedure
Which combines the question with blanks and displays the
whole question.
The method or technique used for dragging the control from
source to destination is same as Example1. i.e. event procedure
used to drag & drop control from source to destination is
same.
Extra feature added in this example is Drag Over event of
target object
This event is explained below
Private Sub lblsetcorans_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)
If State = 0 Then
lblsetcorans(Index).BackColor = Source.BackColor
ElseIf State = 1 Then
lblsetcorans(Index).BackColor = &HFFC0C0
End If
End Sub
When we drag a source to a target when the mouse pointer
is over the taget its backcolor is set to source backcolor with
state=0 and when source is dropped to target its color is set
back to the original color with state=1
Fig 10 Screen shot for Drag & Drop question Control before
dragging to the target
Fig11 Screen shot for Drag & Drop type question control
after being dragged to the target
Fig10 shows how control for question, fill in blanks and
answer option is displayed
Fig11 is the Screen after the control is dragged and dropped
in fill in blanks (i.e. in place of Placeholder)
4.2 Database Design
Fieldname
Data Type
Qid
Number
Qname
Memo
AnsSrNo
Number
Answer
Memo
AnsRnd
Number
AnsRnd Number used to display the answer option randomly
to candidateQid Number
4.3 downloadable Zip file
5. References
5.1 Msdn Library Visual Studio6.0 5.2 Visual Basic 6 Programming
Black Book Steven Holzner