Contents       Next page

Visual Basic 6 

Drag-n-Drop Tutorial

  Contents

3.0   Example2 for Drag & Drop Type Question – Difficulty level: Moderate 

3.1 Explains how example2 is Different from Example1
3.2 Database Design
3.3 Downloadable Zip File

  3.0 Example2 for Drag & Drop Match the following type of questions

                3.1 Explains how example2 is different from Example1

This example explains how Drag & Drop type operation is performed for a different question type.

Dragging operation i.e. dragging the control from source to destination is same as what is  explained in Example1 that means same event procedures are used to perform Drag & Drop operation.

In Example1 simple images are simple images are dragged from one place to another

i.e. dragged from source & dropped on to appropriate places(target).

 

But in this example a database is used to store question and answer options.

In the front end of the application control for question, control with blank space and also control for answer option is, all created at runtime.

  Design view of the form looks as below.                                                                            

Fig6 Design view of the screen for Drag & Drop Match cases

Fig8. shows after the controls dragged and dropped on to the destination

    In the below Fig7 each control for Question, Fill in blanks, Answeroption

    Is created at runtime based on the data in the database.

    Initially in the design view all these controls visible property set to false

    Also set the index property to zero (0)

    Load method is used to load the control

    For example, to load the control for question based on the data in the database following 

    code is written

   First create the connection object

    Dim con as Adodb.connection

    Dim rs as Adodb.recordset

    Dim I as integer

    Set con = New ADODB.Connection

    con.Provider=”Microsoft.Jet.OLEDB.4.0”

    con.Open  App.path & “\” &  “DragDropDemo.mdb”

   ‘Create the recordset object

    Set rs = New ADODB.Recordset

    rs.Open "select * from dragdropmatch", con, adOpenStatic, adLockOptimistic, adCmdText

    While rs.EOF = False

                'Depending on the no. of records in database question control is created dynamically

                    Load lblmatqus(i)  

                    lblmatqus(i).Caption = IIf(IsNull(rs!Question), "", rs!Question)

                    intrand = rsmatch1!AnsRnd

                    lblmatqus(i).Top = lblmatqus(i - 1).Top + lblmatqus(i - 1).Height + 100

                    lblmatqus(i).Left = lblmatqus(i - 1).Left

                    If lblmatqus(i).Caption = "" Then

                        lblmatqus(i).Visible = False

                    Else

                        lblmatqus(i).Visible = True

                    End If

    I=I+1

    Rs.movenext

    Wend

    In the above example the statement IIf(IsNull(rs!Question), "", rs!Question) checks for null value in the question field ,if so question control with blank space is displayed or else value of the question field from the table is displayed

To avoid the blank question control displayed, it’s made invisible if question field contains the null value and made visible if it contains some text.

Below code explains how it works

If lblmatqus (i). Caption = "" Then

                        lblmatqus(i).Visible = False

                    Else

                        lblmatqus(i).Visible = True

                    End If

Similar technique is used to create other two controls (control for blanks and control for answer options)

 

Fig7 Output Screen for Drag & Drop match cases control before being dragged

 

 

 

       

    Fig8 Output Screen for Drag & Drop match cases control after being dragged    

 

3.2 Database design

                      Table Name: DragDropMatch

   Field Name

 Data Type

    AnsSrNo    Number
   Question    Memo
   Answer    Memo
   AnsRnd     Number
    Qid     Number

In the above-mentioned table Question and also Answer for the question is stored serially.AnsRnd field used to display the answer option randomly.

Before displaying the answer option for candidate it’s randomized and displayed

You can use any randomize technique to randomize the answer or in AnsRnd field

of the table DragDropMatch you can just enter the AnsSrNo field randomly in

AnsRnd field

 

  3.3 Downloadable zip file

              

              

Top

Previous

Contents

Next


 HOME   UP   

Web design by AnandSoft