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.

THE INTEGRATION OF VISUAL BASIC PROGRAMMING LANGUAGE INTO<br />

PHYSICS DISCIPLINE<br />

Catalin CHITU<br />

University <strong>of</strong> Bucharest, Faculty <strong>of</strong> Physics, Atomistilor Street, Bucharest-Magurele, Romania<br />

catalinchitu@yahoo.com<br />

Razvan Constantin INPUSCATU, Alexandra VINTILA<br />

Energetic High School, No. 1, Grivitei Street, Campina, Romania<br />

razvan92ctin@yahoo.com, alexandra92fish@yahoo.com<br />

Abstract: This article discusses <strong>the</strong> use <strong>of</strong> Visual Basic <strong>programming</strong> <strong>language</strong> in <strong>the</strong> experimental<br />

laboratory lessons. Thus, alternative experimental methods used to determine certain physical<br />

parameters can be found in an integrated manner, in a single application <strong>of</strong> educational s<strong>of</strong>tware.<br />

Basically, through a single graphical interface, users can select <strong>the</strong> desired experiment and its<br />

corresponding computer will provide values for physical parameters searched.<br />

We believe that <strong>integration</strong> <strong>of</strong> s<strong>of</strong>tware calculating application in <strong>the</strong> experimental laboratory teaching<br />

is a useful element to enhance <strong>the</strong> quality <strong>of</strong> Physics discipline.<br />

Keywords: Visual Basic s<strong>of</strong>tware, Graphic User Interface, Integration treatment, The calculators.<br />

I. INTRODUCTION<br />

This article presents <strong>the</strong> manner <strong>of</strong> realization <strong>of</strong> an educational s<strong>of</strong>t using Visual Basic<br />

<strong>language</strong> [8]. This s<strong>of</strong>tware, toge<strong>the</strong>r with o<strong>the</strong>r s<strong>of</strong>tware realized in <strong>the</strong> same <strong>language</strong>, forms a unity<br />

which is <strong>the</strong> base for a graphic user interface (GUI). This GUI represents <strong>the</strong> main part which is used<br />

in <strong>the</strong> laboratory <strong>physics</strong> lessons.<br />

Visual Basic is a <strong>programming</strong> <strong>language</strong> produced by Micros<strong>of</strong>t, derived from <strong>the</strong> Basic<br />

<strong>language</strong>. Visual Basic is popular due to its graphic interface which is relatively simple compared to<br />

o<strong>the</strong>r similar programs [9, 3].<br />

Visual Basic is a part <strong>of</strong> Micros<strong>of</strong>t‟s Visual Studio pack and , like any o<strong>the</strong>r „<strong>visual</strong>‟ <strong>language</strong><br />

from Micros<strong>of</strong>t (excepting C++), it is based on <strong>the</strong> program‟s graphic interface, <strong>the</strong> programmer being<br />

able to easily design standard Windows interfaces (windows, buttons, lists and so on) without having<br />

to write a code for it. Visual Basic contains a library <strong>of</strong> <strong>visual</strong> components (lists, schedules, menus and<br />

so on) whose components (graphical and functional) are already implemented within <strong>the</strong> program,<br />

giving <strong>the</strong> user <strong>the</strong> opportunity to introduce and use his own components or components made by o<strong>the</strong>r<br />

programmers [10].<br />

Visual Basic is a <strong>language</strong> based on objects, already having implemented a list <strong>of</strong> classes with<br />

general use. Until <strong>the</strong> 6th version, Visual Basic was using and developing COM/COM+ and ActiveX<br />

components and classic libraries <strong>of</strong> DLL functions. With <strong>the</strong> advent <strong>of</strong> version 7, with <strong>the</strong> advent <strong>of</strong><br />

.NET technology, Visual Basic (now Visual Basic.NET) is able to use and create .NET components<br />

with all <strong>the</strong> advantages <strong>the</strong>y <strong>of</strong>fer. Visual Basic is a high level <strong>language</strong> having implemented multiple<br />

levels <strong>of</strong> abstraction <strong>of</strong> developing an application and also <strong>the</strong> possibility <strong>of</strong> compiling in Windows<br />

EXE or 16 bit or 32 bit DLL formats [10].<br />

Visual Basic is an interpreted <strong>language</strong>, which means every code written in <strong>the</strong> Visual Basic<br />

<strong>language</strong> must be translated <strong>into</strong> a lower level <strong>language</strong> and after that executed (unlike native


<strong>language</strong>s like C++). This thing has advantages (such as running <strong>the</strong> applications without compiling or<br />

<strong>the</strong> portability across platforms) and disadvantages (such as <strong>the</strong> need <strong>of</strong> a virtual machine to interpret<br />

<strong>the</strong> code) [10].<br />

One <strong>of</strong> <strong>the</strong> primary roles <strong>of</strong> <strong>the</strong> Visual Basic <strong>language</strong> is that <strong>the</strong> user can create complex<br />

applications in a short period <strong>of</strong> time and he can use relatively simple dedicated computer systems<br />

(such as data bases – Visual Basic can use any systems <strong>of</strong> data base management known so far,<br />

directly or by using ODBC).<br />

The use <strong>of</strong> <strong>the</strong> Visual Basic <strong>language</strong> is a general one, being used for simple, educational<br />

applications but also for complex ones (such as games). Theoretically anybody (more or less<br />

experienced) can use Visual Basic because it‟s a simple <strong>programming</strong> <strong>language</strong> [10].<br />

The primary role <strong>of</strong> <strong>the</strong> calculators is decreasing <strong>the</strong> working time. By taking out <strong>the</strong> time<br />

spent on doing calculations <strong>of</strong> <strong>the</strong> experimental data, <strong>the</strong> working time is decreased.<br />

The calculators made in Visual Basic are easy to use. The user types in <strong>the</strong> experimental data<br />

and by pressing a button he receives <strong>the</strong> final value instantly [3].<br />

Ano<strong>the</strong>r major role <strong>of</strong> <strong>the</strong>se applications is that <strong>the</strong> user is able to save <strong>the</strong> experimental data<br />

and export it <strong>into</strong> an Excel table. By doing this he can use it later for o<strong>the</strong>r projects.<br />

We think that integrating this s<strong>of</strong>tware in <strong>the</strong> laboratory <strong>physics</strong> lesson increases <strong>the</strong> lesson<br />

quality and develops <strong>the</strong> motivation for <strong>the</strong> experimental methods <strong>of</strong> matter investigation.<br />

II.<br />

BUILDING THE APPLICATIONS<br />

We will use one <strong>of</strong> <strong>the</strong> calculators (<strong>the</strong> “Minimum Deviation Experimental Method”<br />

calculator) in order to show you how it was created. The Graphic User Interface is presented below<br />

(Figure 1).<br />

Figure 1. The GUI for <strong>the</strong> “Minimum Deviation Experimental Method”<br />

2.1 Designing <strong>the</strong> GUI (Graphic User Interface)<br />

We start by setting <strong>the</strong> window size in Visual Basic. Next we can edit <strong>the</strong> title, icon and <strong>the</strong><br />

window properties (Figure 2).


Figure 2. The properties window. The toolbox.<br />

Any changes made in <strong>the</strong> “Properties” window will be written with bold font. The next step is<br />

using <strong>the</strong> Toolbox control (Figure 2).<br />

Insert one Picture Box (where we place a picture <strong>of</strong> <strong>the</strong> main formula – Figure 3) and add a<br />

picture in it: click on <strong>the</strong> picture box, go to properties (<strong>the</strong>y‟re placed on <strong>the</strong> lower right corner <strong>of</strong> <strong>the</strong><br />

screen, <strong>the</strong>y look like <strong>the</strong> window properties where we changed <strong>the</strong> title - Figure 2) and <strong>the</strong>n look for<br />

Background Image and browse <strong>the</strong> picture.<br />

Add six more Picture Boxes (for <strong>the</strong> o<strong>the</strong>r formulas – Figure 3). We use <strong>the</strong>m instead <strong>of</strong><br />

writing <strong>the</strong> formulas directly because <strong>the</strong>y are all fractions. To write such a formula in Visual Basic<br />

means to draw lines. If we do this we end up having our application not working. It will not run on any<br />

o<strong>the</strong>r computer which doesn‟t have Visual Basic installed because Windows lacks some files (DLL<br />

files) needed to read <strong>the</strong> lines we‟ve drawn.<br />

Figure 3. The main formula. The o<strong>the</strong>r formulas.


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].


Figure 5. Displaying error message<br />

If TextBox1.Text = Nothing Then<br />

MsgBox("Please type in a value for δmin!", MsgBoxStyle.Exclamation, "Error")<br />

ElseIf TextBox1.Text < 30 Or TextBox1.Text > 50 Then MsgBox("δmin cannot be above 50<br />

or below 30 degrees!", MsgBoxStyle.Exclamation, "Error")<br />

ElseTextBox2.Text = (TextBox1.Text + 60) / 2<br />

TextBox3.Text = 0.01745 * ((TextBox1.Text + 60) / 2)<br />

TextBox4.Text = Math.Sin(0.01745 * ((TextBox1.Text + 60) / 2))<br />

TextBox5.Text = "0.5235"<br />

TextBox6.Text = "0.5000"<br />

TextBox7.Text = (Math.Sin(0.01745 * ((TextBox1.Text + 60) / 2))) / 0.5<br />

End If<br />

All <strong>the</strong>se lines are for calculating <strong>the</strong> values, for <strong>the</strong> first button. The reset button will have no<br />

errors to check and will be easier to write. All it does is wiping <strong>the</strong> data written in <strong>the</strong> text boxes.<br />

Double click on <strong>the</strong> “Reset” button. It will take you to <strong>the</strong> coding page.<br />

We write <strong>the</strong> reset code between “Private Sub Button2_Click(ByVal sender As System.Object,<br />

ByVal e As System.EventArgs) Handles Button2.Click” and <strong>the</strong> line below it (which is where <strong>the</strong> code<br />

for this button ends) “End Sub”<br />

The code is like this:<br />

TextBox1.Text = Nothing<br />

TextBox2.Text = Nothing<br />

TextBox3.Text = Nothing<br />

TextBox4.Text = Nothing<br />

TextBox5.Text = Nothing<br />

TextBox6.Text = Nothing<br />

TextBox7.Text = Nothing<br />

Like we said all it does is wiping <strong>the</strong> values in <strong>the</strong> Text Boxes. After typing in those lines <strong>the</strong><br />

code for <strong>the</strong> Reset button should be like this [12]:<br />

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />

Handles Button2.Click<br />

TextBox1.Text = Nothing<br />

TextBox2.Text = Nothing


TextBox3.Text = Nothing<br />

TextBox4.Text = Nothing<br />

TextBox5.Text = Nothing<br />

TextBox6.Text = Nothing<br />

TextBox7.Text = Nothing<br />

End Sub<br />

Now we move on to <strong>the</strong> Save button. We‟ve added an error message to be displayed if <strong>the</strong> user<br />

didn‟t calculate <strong>the</strong> values and wants to save <strong>the</strong> results without doing it: it checks if <strong>the</strong> last Text Box<br />

is empty and if it is <strong>the</strong> error message will be displayed when <strong>the</strong> user clicks on Save, if not it will<br />

move on and write all <strong>the</strong> data <strong>into</strong> an excel table.<br />

For <strong>the</strong> last button we only have to write 2 code lines. First double click on <strong>the</strong> Main Page<br />

button. After writing <strong>the</strong> code, it should look like this [11, 13]:<br />

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />

Handles Button4.Click<br />

Form1.Show()<br />

Me.Close()<br />

End Sub<br />

2.3 Saving <strong>the</strong> program<br />

After you‟re done you want to save <strong>the</strong> application. First you have to build it (go to Build ><br />

Build ~application name~). That will check for any errors made by you in <strong>the</strong> code (Figure 6). If it‟s<br />

all fine it will display “Build succeeded” in <strong>the</strong> lower left corner <strong>of</strong> <strong>the</strong> program.<br />

Figure 6. Building <strong>the</strong> application<br />

If <strong>the</strong>re are no code errors you can move on and save <strong>the</strong> project (Figure 7). It will display<br />

“Item(s) saved” in <strong>the</strong> lower left corner <strong>of</strong> <strong>the</strong> program. If <strong>the</strong>re are errors, Visual Basic will tell you<br />

where to look for.<br />

Figure 7. Saving <strong>the</strong> application<br />

2.4 The final application (<strong>the</strong> final GUI)<br />

The final result is binding all <strong>the</strong> calculators in one interface from which <strong>the</strong>y can be accessed.<br />

In <strong>the</strong> first drop down box <strong>the</strong>re will be displayed a list <strong>of</strong> <strong>the</strong> experimental laboratory projects. The<br />

user will be able to choose <strong>the</strong> desired project. Even more, each project contains two alternative<br />

experimental methods. Corresponding to that, <strong>the</strong> application displays <strong>the</strong> two calculators. Therefore,<br />

Figure 8 presents <strong>the</strong> determination <strong>of</strong> <strong>the</strong> refractive index through <strong>the</strong> alternative method, “The<br />

minimum deviation <strong>of</strong> <strong>the</strong> light”.


Figure 8. The final interface <strong>of</strong> <strong>the</strong> calculators<br />

This Graphic User Interface that we made contains <strong>the</strong> following computers for experimental<br />

laboratory work in <strong>physics</strong> classes: “Laser Radiations Wavelength Experimental Methods” with two<br />

alternative experimental methods such as: “Young Device Method” and “Grating Diffraction Method”,<br />

“Refractive Index Experimental Method” with two alternative methods such as: “Minimum Deviation<br />

Experimental Method” and “Limit Angle Experimental Method” and finally, “Strip Elastic Constant<br />

Method” with <strong>the</strong> alternative experimental methods such as: “Static Balance Method” and “Energy<br />

Balance Method” respectively.<br />

By pressing <strong>the</strong> “Run” button <strong>the</strong> chosen calculator will open in a new window. The user will<br />

be able to calculate in a relatively short period <strong>of</strong> time <strong>the</strong> required physical parameters <strong>of</strong> <strong>the</strong> project<br />

[7]. If <strong>the</strong> user wants extra information, by pressing <strong>the</strong> “About” button, <strong>the</strong> team who created <strong>the</strong><br />

application will be displayed.<br />

III.<br />

CONCLUSIONS<br />

The Visual Basic <strong>language</strong> is useful for <strong>the</strong> teaching process in Physics discipline, but also for<br />

an interdisciplinary discussion <strong>of</strong> <strong>the</strong> physical notions and <strong>of</strong> <strong>the</strong> natural phenomena. The graphic<br />

interfaces allow <strong>the</strong> user to be easily integrated in <strong>the</strong> lesson. He benefits <strong>of</strong> an interactive training,<br />

obtaining feedback at certain moments [4].<br />

The displayed messages, by <strong>the</strong> graphic interfaces, represent useful guides for knowledge and<br />

interpretation <strong>of</strong> <strong>the</strong> natural phenomena. The application is all about <strong>the</strong> existent conditions in <strong>the</strong><br />

school labs.<br />

Using <strong>the</strong> GUI develops skills for students on <strong>the</strong> <strong>visual</strong> learning style [1, 6, 2]. Also, <strong>the</strong><br />

students can be involved in activities <strong>of</strong> conception and <strong>integration</strong> <strong>of</strong> <strong>the</strong> s<strong>of</strong>tware for <strong>the</strong><br />

experimental lessons. In this way, students are trained in a differentiated manner [5, 2].<br />

By integrating <strong>the</strong> educational s<strong>of</strong>t during <strong>the</strong> Physics lessons, <strong>the</strong> quality <strong>of</strong> <strong>the</strong> teachinglearning-evaluation<br />

process will be improved.<br />

Acknowledgements:<br />

This work was supported through <strong>the</strong> project launched by <strong>the</strong> Ministry <strong>of</strong> Education, Research,<br />

Youth and Sport and by <strong>the</strong> University <strong>of</strong> Bucharest through <strong>the</strong> POSDRU/6/1.5/S/24 project.


References<br />

[1] Bostrom, R. P., Olfman, L., and Sein, M. K., 1990. The importance <strong>of</strong> learning style in end-user training, MIS<br />

Quarterly, Pages 101-109.<br />

[2] Chiţu, C., Antohe, S., Ilisie, G., 2010. Learning styles assessment role in increasing school performance in Physics<br />

discipline. EDULEARN 2010 CONFERENCE, BARCELONA, Proceedings CD, ISBN: 978-84-613-9386-2.<br />

[3] Chiţu, C., Inpuscatu, R. C., Viziru, M., 2010. Visual Basic Applications to Physics Teaching, Proceedings <strong>of</strong> <strong>the</strong> 5<br />

th INTERNATIONAL CONFERENCE ON VIRTUAL LEARNINGICVL 2010. Bucharest University Publisher.<br />

Bucharest, Pages 403-409.<br />

[4] Cucos, C., 2006. Pedagogy, Polirom Publisher. Iasi, 6 th edition. Pages 288-289.<br />

[5] Florian, G., 2004. Differential treatment <strong>of</strong> students in Physics discipline. Else Publisher. Craiova, Pages 23-37.<br />

[6] Fritzsche, D. J., 1976. On <strong>the</strong> relationships <strong>of</strong> learning style, perceived learning, and performance. Paper presented<br />

at <strong>the</strong> Third International ABSEL Conference, Knoxville, TN.<br />

[7] Malinovschi, V., 2003. Teaching Physics, Didactic and Pedagogic Publishing R. A., Bucharest, Pages 111-113.<br />

[8] Miron, C., 2008. Teaching Physics, Bucharest University Publishing House. Bucharest, 1th edition. Pages 89-90.<br />

[9] http://www.micros<strong>of</strong>t.com/express/Downloads/#2008-Visual-Basic - link to download Visual Basic.<br />

[10] http://ro.wikipedia.org/wiki/Visual_Basic<br />

[11] http://www.vbforums.com/ - forum for support.<br />

[12] http://msdn.micros<strong>of</strong>t.com/en-us/v<strong>basic</strong>/default - Micros<strong>of</strong>t Development Centre.<br />

[13] http://www.dreamincode.net – Webmaster Scripts & Tutorial Directory.

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

Saved successfully!

Ooh no, something went wrong!