VbDotNetExample - Methods

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
Finzd thee wrang lelters ino eacuh wosrd

Revision 15 as of 2007-09-12 11:52:18

location: VbDotNetExample

A sample experiment in VB.net

Download

The example is here attachment:ExperimentTemplate.zip

This is an attention monitoring experiment. It may be used in the scanner, or out of the scanner, with a simple switch of a parameter. It contains a colleciton of modules (starting Exp...) that contain functions that should be generally useful for many experiments.

This program is provided as an illustration only. You should always check your code carefully.

Program components

ExpSettings

General experimental settings. Most useful is probably

Public FullScreen As Boolean == True

By default, the experiment acquires the whole screen, to give accurate timing, and prevent other programs from being displayed. However, this can be irritating when debugging, so set this to False when programming.

ExpDisp

Contains various subroutines to help you use DirectX for display.

Initialize()

Sets up screen, in full screen or windowed mode. Make sure the number of colours (third argument in

             DXDevice.SetDisplayMode(ES.ScreenWidth, ES.ScreenHeight, 32, 0, False)

is set to the same as the colour depth that windows was started in, if you use .FROMARGB anywhere to convert RGB values to colours.

ClearScreen

Clears the screen

DrawFixation

Draws a fixation cross

FlipSurface

To ensure that graphics are displayed tidily, drawing is done on an "off screen surface" and then flipped to the display. This command flips the display. If in fullscreen mode, a DirectX flip command is used, which will be executed by the graphics card, and give high performance. In the testing windowed mode, a copy command is used to emulate the action of the flip.

ExpTimingAndReponses

Various routines for getting accurate timing, synchronising with the scanner (if used), checking button boxes and the keyboard.

Set USESCANNER and USEBUTTONBOX to True to use the software on the scanner or mimic machines.

ExpTrial & AttentionTrial

The ExpTrial class that represents a single trial, storing the parameters of the trial. This class would usually be used as a base for your own class, which more fully implements the particular experiment in question. Here, this is done in AttentionTrial, which inherits ExpTrial, but extends the "Run" method to display an attention monitoring trial.

ExpTrialList & AttentionTrialList

ExpTrialList stores a list of trials, and knows how to randomize it (or individual parameters), run all of the trials, and dump various things to the output file. AttentionTrialList is a specific implementation for this experiment, that also prepares the grating stimuli. Nevertheless, the example code of AttentionTrialList contains several snippets useful for various experiments:

Useful code for loading bitmaps is comprised of code necessary to find the files on disk:

    Function getstimdir()
        Return (Application.StartupPath & "\stim")
    End Function

    Function getfn(ByVal k, ByVal j) As String
        Return (getstimdir() & "\grating_" & k & "_" & j & ".bmp")
    End Function

These two functions specify the path to the various images necessary for the experiment. Using variables (here 'k' and 'j') to define the specific file (e.g. 'grating_1_2.bmp') allows concise description of each image. Additionally, initial loading of all the necessary images before the experiment can aid performance:

    For k As Integer = 0 To 1
        For j As Integer = 0 To numbitmap
            b(k, j) = New Bitmap(getfn(k, j))
        Next
    Next

Here, 'b(k, j)' becomes a stored image that can be recalled in the experimental trial.

frmStart

This is the main form. The code behind the "Start" button actually runs the experiment. This code contains the definitions of the trials:

Dim NUMCONDS = 4
Dim NUMSUBBLOCKS = 12
Dim ATTENDLIST() = {0, 3, 12, 15}

Modify these definitions to describe the design of your experiment. You may choose to represent each condition by a number of definitions (e.g. a trial may be defined by CONGRUENCY, SOA, DELAY and PRIMEPRESENCE).

Then a list of trials is created:

TL = New AttentionTrialList(NUMCONDS * NUMSUBBLOCKS, txtOutputFilename.Text, txtSubjectCode.Text)

Here, you have three arguments separated by commas: (NewNumTrials, NewOutputFilename, NewSubjectCode); dictate the value of the first argument in relation to the definitions described above.

Finally, the list is populated by the different parameters relevant to each experimental trial, again dependent on the definitions above:

For i = 0 To NUMSUBBLOCKS - 1
            For j = 0 To NUMCONDS - 1
                TL.TrialList(ind).AddParameter("Subblock", i)
                TL.TrialList(ind).AddParameter("MonitorDur", ((MAXBLOCKDUR - MINBLOCKDUR) * i / (NUMSUBBLOCKS - 1.0)) + MINBLOCKDUR)
                TL.TrialList(ind).AddParameter("AttendTo", ATTENDLIST(j))
                ind = ind + 1
            Next
        Next

This nested function ensures all trials are created different. Expand/modify this depending on the structuring of your trials.

Then the trials are randomized with either or both of two commands:

        TL.RandomizeTrialOrderSingleParameter("MonitorDur")
        TL.RandomizeTrialOrder(True)

The first one randomizes a single parameter of the given name independently of the others (change as appropriate) and the second randomises the order of all trials either preserving (argument set to 'True') or not ('False') the Subblocks (see above). Lastly, before running the experiment we need to initialise the devices necessary for our experiment, such as our keyboard:

TL.ET.InitKeyboard(ExpStimulusForm)

Finally, we run our experiment

TL.RunAllTrials()

and terminate the display afterwards.

ED.Terminate()

Author & Acknowledgements

Page and example program created by Rhodri Cusack. Thanks to Daniel Mitchell & Alejandro Vicente-Grabovetsky who contributed parts to this code.