30.01.2015 Views

the integration of visual basic programming language into physics ...

the integration of visual basic programming language into physics ...

the integration of visual basic programming language into physics ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Insert one label for <strong>the</strong> refractive index “n= “. To edit <strong>the</strong> text inside <strong>the</strong> label go to properties<br />

and look for “Text” and type in <strong>the</strong> desired name.<br />

Add seven Text Boxes for each value (it‟s where <strong>the</strong> user types in <strong>the</strong> experimental values and<br />

where <strong>the</strong> final values will be displayed).<br />

Add four labels to display <strong>the</strong> measurement units.<br />

Add four buttons placed like in Figure 4. They will be used to calculate <strong>the</strong> data (Calculate<br />

button), save <strong>the</strong> data (Save button), reset <strong>the</strong> fields (Reset button) or to return to <strong>the</strong> main page (Main<br />

page button).To edit <strong>the</strong> names <strong>of</strong> <strong>the</strong> buttons we use <strong>the</strong> same technique previously used on <strong>the</strong><br />

window title, which is by editing its properties.<br />

Figure 4. The buttons <strong>of</strong> <strong>the</strong> GUI<br />

2.2 Writing <strong>the</strong> s<strong>of</strong>tware code<br />

Writing <strong>the</strong> code is, sometimes, <strong>the</strong> tricky part. We have to write code lines for <strong>the</strong> buttons and<br />

<strong>the</strong> errors that will be displayed if <strong>the</strong> user commits a mistake [11, 13].<br />

We start by declaring some variables at <strong>the</strong> beginning <strong>of</strong> <strong>the</strong> page. First double click on <strong>the</strong><br />

first button to get to <strong>the</strong> coding page.<br />

Above “Public Class minimum_dev” write:<br />

Option Explicit On<br />

Option Strict Off<br />

Below it write:<br />

Inherits System.Windows.Forms.Form<br />

We‟ll need <strong>the</strong>se lines mainly for exporting <strong>the</strong> data <strong>into</strong> <strong>the</strong> excel table [11, 13].<br />

Below “Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As<br />

System.EventArgs) Handles Button1.Click” we write <strong>the</strong> code that‟ll calculate <strong>the</strong> values.<br />

Because our value is an angle and it‟s limited between 30 and 50 degrees, we have to add a<br />

condition that‟ll check if <strong>the</strong> value typed in by <strong>the</strong> user corresponds to <strong>the</strong> experimental data.<br />

How will <strong>the</strong> program check for errors<br />

First it checks <strong>the</strong> field not to be empty. If it is empty, <strong>the</strong>n an error will be displayed. If it‟s<br />

not empty it moves on to <strong>the</strong> next condition which is <strong>the</strong> angle‟s value. If it‟s not in <strong>the</strong> interval<br />

ano<strong>the</strong>r error message will be displayed (Figure 5). If everything is ok it will move on and calculate<br />

<strong>the</strong> values.<br />

Next, after checking for any possible errors we move on to <strong>the</strong> codes that calculate and display<br />

<strong>the</strong> values. We write <strong>the</strong>m below <strong>the</strong> error lines [12].

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!