SlideShare a Scribd company logo
Rapid Application Development 1 (F21RA1)                                                      Rick Dewar



Lab Sheet 1 – a Gentle Introduction to Visual Basic
Introduction

To complete this lab you’ll need to first visit the problem manager in room 1.77 and ensure you can
access the XP network. Next you’ll need to use the machines in G.46/47 or 1.53/54.

Please note that at some points in the lab you will be required to get a lab helper to tick your name
on a list to record that you have achieved what is required of you. These ticks will count towards
your marks for the module and are very important for us to see how you are progressing.

Good luck and enjoy!

Getting Started

Firstly, let’s start up the application called Microsoft Visual Studio .NET, see Figure 1.




Figure 1 - Starting Visual Studio

You should eventually see a development window something like that shown in Figure 2.




Figure 2 – Development Environment Window

As shown in Figure 2,create a new project. You should then see a dialogue box like that in Figure 3.
Give the new project a meaningful name and save it in a sensible place on the H drive. Your H
drive is a network drive that you can access from other machines. You each have private file storage

Created On 15/10/2003                      1                      Last Modified: 07/10/2005
Rapid Application Development 1 (F21RA1)                                                         Rick Dewar


on it that is regularly backed-up. However, Visual Studio sometimes grumbles that it doesn’t trust
projects that are stored on the H drive. This is because the H drive is actually on a machine that
does not run a Microsoft operating system. Fortunately, you can trust the H drive, so please ignore
any warnings of this ilk.

Occasionally, it might be necessary for you to store your projects on the D drive (a writable local
drive) to get some functionality to run. However, beware that the D drive is volatile and public and
is not a viable place you store your files. If you have to put your files on the D drive to get them to
run, make sure you move them back onto your H drive at the end of the session.




Figure 3 - Name and Save a New VB Windows Application

Having done this you are now confronted with a blank VB form within a new project – see Figure
4.

As per Figure 4, add a text box, button and label to the empty form from the toolbox on the left. If
the toolbox is not visible enter the View menu and select Toolbox from the list.

Now go to the properties window of the text box by right clicking on it in the central design
window and selecting properties from the list that appears. These properties should then appear in
the window to the right of the screen. Scroll down this list until you come to the Text attribute.
Delete the word TextBox1 and you’ll see the text box in the form is now empty, once you have hit
enter of have clicked elsewhere. This is called initialising the object since you are setting its initial
value. In this case, you are setting it to nothing, or null as we often call it, since it essentially has no
value.

Next select the command button’s properties and initialise its Text attribute to “Greetings” and set
the Enabled property to False. Finally, initialise the Text property of the label to null. You should
then have something similar to Figure 5.




Created On 15/10/2003                      2                         Last Modified: 07/10/2005
Rapid Application Development 1 (F21RA1)                                                   Rick Dewar




                                                                        Code Tab




Figure 4 - Adding Objects to the Form




Figure 5 - The form after initialisation

Before we continue, let’s do the sensible thing and save our work. At this stage you should Save
All. Later, as you become more confident you can just save the current form you are working on.
This should highlight the fact to you that a VB project is made up of a number of files.

Created On 15/10/2003                      3                   Last Modified: 07/10/2005
Rapid Application Development 1 (F21RA1)                                                      Rick Dewar


Now we can run the VB program that we’ve created by selecting Start from the Debug menu. The
application won’t do anything, but it’s a useful check to show that all is as it should be. Figure 6
shows what you should obtain. You can enter text into the text box and but cannot click the
command button because we’ve disabled it; remember?




Figure 6 - Running the VB application for the First Time

When you’re finished, remember to close the running application or it will interfere with the VB
project and form files you’re editing.

Congratulations! You’ve created and run your first VB application.

T1: Now get a lab helper to tick your name off the list to show you’ve
completed this first task. Remember, these ticks count towards your
overall mark for the module.
Event Driven Behaviour

As we’ve seen, the application doesn’t do much just now, but the form is ready for us to add certain
behaviour.

To begin with let’s discuss a scenario that describes what we want the application to do. First of all,
it would be useful for the command button to become active when someone enters text into the text
box. Next, when someone clicks the command button, we’d like a greeting to be displayed in the
label. This greeting should incorporate the text entered in the text box by the user previously.

In order to create such behaviour, we need to enter VB code. We can access the code window by
choosing the appropriate code tab above the central form design window; see annotation in Figure
4. If the code tab is not already visible, double click one of the elements of the form in the design
window, eg the text box, and the window in Figure 7 should now appear. Here you can see a Sub
procedure related to the object TextBox1 and the event that might happened to it, namely that it has


Created On 15/10/2003                      4                      Last Modified: 07/10/2005
Rapid Application Development 1 (F21RA1)                                                      Rick Dewar


experienced a TextChanged event. If you pull down the lists in these combo boxes at the top of
code window, you’ll see the other objects that you could choose from and the other events that can
happen to them, respectively.




Figure 7 - The Code Window for the Form

There is a lot of text, terms and language in this code that will be unfamiliar to you. Please don’t
panic; you will eventually and gradually learn what is important. For the moment we are making
simple changes to small parts of the code.

You now need to enter code (i.e. instructions) in the Sub procedure (TextBox1_TextChanged) to
enable the button in our scenario. The significant line that you need to add is the second line below.
If you type “button1.” (notice the full stop), you’ll see a list of valid properties appears. The full
stop means you are interested in some property or component of the button. Highlight the property
you want (ie enabled) and hit tab. Then enter an equals sign and another list will show valid values
of that property. Clever time-saving, error-avoiding feature isn’t it?
      Private Sub TextBox1_TextChanged(...)...
          Button1.Enabled = True
      End Sub
Notice the indentation of the second line. This makes it easier for us to read and is very important
for you to remember. However, the Visual Studio environment can automatically do this sort of
formatting for you.

So what we’re saying is that when a change happens to TextBox1, we want to set the enabled
attribute of the object Button1 to True. Try and run the application again and see what happens
when you add text to the text box.

Now let’s add the second part of our scenario where we display the greeting in the label. Here we
want to enter:
        Private Sub Button1_Click(...)...
           Label1.Text = "Hi " + TextBox1.Text + ". How are you?"
        End Sub
The plus signs here add strings of text together rather than numbers. Feel free to experiment with
the content and formatting of this text so you can understand how it works.

Having saved your work, when you run the application you should be able to see output like we
have in Figure 8.




Created On 15/10/2003                      5                      Last Modified: 07/10/2005
Rapid Application Development 1 (F21RA1)                                                      Rick Dewar




Figure 8 - Some Simple Behaviour

To enhance our scenario, let’s create a new Sub procedure that will clear the contents of the text
box when the text in the label changes. To do this, select the Label1 object from the combo box at
the top left of the code window and then select the TextChanged method from the right hand combo
box. You will see that an empty Sub procedure has been created. Now add a line to this new
procedure that will clear/nullify the text of the text box. An empty string can be created using two
double quotes.

Furthermore, in the same Sub, add another line of code that will disable the button when the label’s
text changes.

Finally, make sure you save All of the project and then create a standalone executable of the
application by choosing Build Solution from the Build menu. Once you’ve done this, you can
locate the application (file type .exe) in your file system and run it independently of the Visual
Studio environment.

T2: Now get a lab helper to tick your name off the list to show you’ve
completed this series of tasks. Remember, these ticks count towards
your overall mark for the module.
Well done, if you’ve got this far and have had all your work ticked off.

Please note that your next lab will build on the work you have done here so make sure you do not
lose or delete this VB project.




Created On 15/10/2003                      6                      Last Modified: 07/10/2005

More Related Content

What's hot

Creating Windows-based Applications Part-I
Creating Windows-based Applications Part-ICreating Windows-based Applications Part-I
Creating Windows-based Applications Part-I
Umar Farooq
 
Vp lecture1 ararat
Vp lecture1 araratVp lecture1 ararat
Vp lecture1 ararat
Saman M. Almufti
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0sanket1996
 
Visual programming lecture
Visual programming lecture Visual programming lecture
Visual programming lecture
AqsaHayat3
 
Vbasic
VbasicVbasic
Best practices for upgrading vb 6.0 projects to vb.net
Best practices for upgrading vb 6.0 projects to vb.netBest practices for upgrading vb 6.0 projects to vb.net
Best practices for upgrading vb 6.0 projects to vb.net
ajmal_fuuast
 
Creating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorialCreating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorialErwin Frias Martinez
 
Book HH- vb2008me preview
Book   HH- vb2008me previewBook   HH- vb2008me preview
Book HH- vb2008me preview
Satya Harish
 
Visual programming
Visual programmingVisual programming
Visual programming
Dr. C.V. Suresh Babu
 
Visual Basic IDE Introduction
Visual Basic IDE IntroductionVisual Basic IDE Introduction
Visual Basic IDE Introduction
Ahllen Javier
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
Osama Yaseen
 
Visusual basic
Visusual basicVisusual basic
Visusual basic
Mandavi Classes
 
Visual basic
Visual basicVisual basic
Visual basicDharmik
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
michael.labriola
 
Visual basic
Visual basicVisual basic
Visual basic
sanjay joshi
 
Transforming Power Point Show with VBA
Transforming Power Point Show with VBATransforming Power Point Show with VBA
Transforming Power Point Show with VBA
DCPS
 

What's hot (20)

Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 
Creating Windows-based Applications Part-I
Creating Windows-based Applications Part-ICreating Windows-based Applications Part-I
Creating Windows-based Applications Part-I
 
Vp lecture1 ararat
Vp lecture1 araratVp lecture1 ararat
Vp lecture1 ararat
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Visual programming lecture
Visual programming lecture Visual programming lecture
Visual programming lecture
 
Vbasic
VbasicVbasic
Vbasic
 
Best practices for upgrading vb 6.0 projects to vb.net
Best practices for upgrading vb 6.0 projects to vb.netBest practices for upgrading vb 6.0 projects to vb.net
Best practices for upgrading vb 6.0 projects to vb.net
 
Creating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorialCreating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorial
 
Book HH- vb2008me preview
Book   HH- vb2008me previewBook   HH- vb2008me preview
Book HH- vb2008me preview
 
Visual programming
Visual programmingVisual programming
Visual programming
 
Visual Basic IDE Introduction
Visual Basic IDE IntroductionVisual Basic IDE Introduction
Visual Basic IDE Introduction
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
Visusual basic
Visusual basicVisusual basic
Visusual basic
 
Ch01
Ch01Ch01
Ch01
 
Visual basic
Visual basicVisual basic
Visual basic
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Visual basic
Visual basicVisual basic
Visual basic
 
Transforming Power Point Show with VBA
Transforming Power Point Show with VBATransforming Power Point Show with VBA
Transforming Power Point Show with VBA
 
Vb%20 tutorial
Vb%20 tutorialVb%20 tutorial
Vb%20 tutorial
 

Similar to Lab1

Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
Ali Mattash
 
The visual studio start page is shown in the figure below
The visual studio start page is shown in the figure belowThe visual studio start page is shown in the figure below
The visual studio start page is shown in the figure belowTan Ps
 
UNIT I.pptx
UNIT I.pptxUNIT I.pptx
UNIT I.pptx
BhargaviJ8
 
Ch02 bronson
Ch02 bronsonCh02 bronson
Ch02 bronson
Bharathi N Reddy
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorialdhi her
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.ppt
LalRatan
 
VB.NET programming
VB.NET programmingVB.NET programming
VB.NET programmingElrey Belga
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorialjayguyab
 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
EliasPetros
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vbarjg_vijay
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Ujwala Junghare
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
marwaeng
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 
Supplement2d netbeans6
Supplement2d netbeans6Supplement2d netbeans6
Supplement2d netbeans6
olveraadrian82
 
Supplement2d netbeans6
Supplement2d netbeans6Supplement2d netbeans6
Supplement2d netbeans6
adrianyourlust1998
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
bantamlak dejene
 
Visual basics Express Project
Visual basics Express ProjectVisual basics Express Project
Visual basics Express Project
Iftikhar Ahmed
 

Similar to Lab1 (20)

Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
The visual studio start page is shown in the figure below
The visual studio start page is shown in the figure belowThe visual studio start page is shown in the figure below
The visual studio start page is shown in the figure below
 
UNIT I.pptx
UNIT I.pptxUNIT I.pptx
UNIT I.pptx
 
Ch02 bronson
Ch02 bronsonCh02 bronson
Ch02 bronson
 
Ps4 lesson 1
Ps4 lesson 1Ps4 lesson 1
Ps4 lesson 1
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.ppt
 
VB.NET programming
VB.NET programmingVB.NET programming
VB.NET programming
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
Gui builder
Gui builderGui builder
Gui builder
 
Vb 6ch123
Vb 6ch123Vb 6ch123
Vb 6ch123
 
Supplement2d netbeans6
Supplement2d netbeans6Supplement2d netbeans6
Supplement2d netbeans6
 
Supplement2d netbeans6
Supplement2d netbeans6Supplement2d netbeans6
Supplement2d netbeans6
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
 
Visual basics Express Project
Visual basics Express ProjectVisual basics Express Project
Visual basics Express Project
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

Lab1

  • 1. Rapid Application Development 1 (F21RA1) Rick Dewar Lab Sheet 1 – a Gentle Introduction to Visual Basic Introduction To complete this lab you’ll need to first visit the problem manager in room 1.77 and ensure you can access the XP network. Next you’ll need to use the machines in G.46/47 or 1.53/54. Please note that at some points in the lab you will be required to get a lab helper to tick your name on a list to record that you have achieved what is required of you. These ticks will count towards your marks for the module and are very important for us to see how you are progressing. Good luck and enjoy! Getting Started Firstly, let’s start up the application called Microsoft Visual Studio .NET, see Figure 1. Figure 1 - Starting Visual Studio You should eventually see a development window something like that shown in Figure 2. Figure 2 – Development Environment Window As shown in Figure 2,create a new project. You should then see a dialogue box like that in Figure 3. Give the new project a meaningful name and save it in a sensible place on the H drive. Your H drive is a network drive that you can access from other machines. You each have private file storage Created On 15/10/2003 1 Last Modified: 07/10/2005
  • 2. Rapid Application Development 1 (F21RA1) Rick Dewar on it that is regularly backed-up. However, Visual Studio sometimes grumbles that it doesn’t trust projects that are stored on the H drive. This is because the H drive is actually on a machine that does not run a Microsoft operating system. Fortunately, you can trust the H drive, so please ignore any warnings of this ilk. Occasionally, it might be necessary for you to store your projects on the D drive (a writable local drive) to get some functionality to run. However, beware that the D drive is volatile and public and is not a viable place you store your files. If you have to put your files on the D drive to get them to run, make sure you move them back onto your H drive at the end of the session. Figure 3 - Name and Save a New VB Windows Application Having done this you are now confronted with a blank VB form within a new project – see Figure 4. As per Figure 4, add a text box, button and label to the empty form from the toolbox on the left. If the toolbox is not visible enter the View menu and select Toolbox from the list. Now go to the properties window of the text box by right clicking on it in the central design window and selecting properties from the list that appears. These properties should then appear in the window to the right of the screen. Scroll down this list until you come to the Text attribute. Delete the word TextBox1 and you’ll see the text box in the form is now empty, once you have hit enter of have clicked elsewhere. This is called initialising the object since you are setting its initial value. In this case, you are setting it to nothing, or null as we often call it, since it essentially has no value. Next select the command button’s properties and initialise its Text attribute to “Greetings” and set the Enabled property to False. Finally, initialise the Text property of the label to null. You should then have something similar to Figure 5. Created On 15/10/2003 2 Last Modified: 07/10/2005
  • 3. Rapid Application Development 1 (F21RA1) Rick Dewar Code Tab Figure 4 - Adding Objects to the Form Figure 5 - The form after initialisation Before we continue, let’s do the sensible thing and save our work. At this stage you should Save All. Later, as you become more confident you can just save the current form you are working on. This should highlight the fact to you that a VB project is made up of a number of files. Created On 15/10/2003 3 Last Modified: 07/10/2005
  • 4. Rapid Application Development 1 (F21RA1) Rick Dewar Now we can run the VB program that we’ve created by selecting Start from the Debug menu. The application won’t do anything, but it’s a useful check to show that all is as it should be. Figure 6 shows what you should obtain. You can enter text into the text box and but cannot click the command button because we’ve disabled it; remember? Figure 6 - Running the VB application for the First Time When you’re finished, remember to close the running application or it will interfere with the VB project and form files you’re editing. Congratulations! You’ve created and run your first VB application. T1: Now get a lab helper to tick your name off the list to show you’ve completed this first task. Remember, these ticks count towards your overall mark for the module. Event Driven Behaviour As we’ve seen, the application doesn’t do much just now, but the form is ready for us to add certain behaviour. To begin with let’s discuss a scenario that describes what we want the application to do. First of all, it would be useful for the command button to become active when someone enters text into the text box. Next, when someone clicks the command button, we’d like a greeting to be displayed in the label. This greeting should incorporate the text entered in the text box by the user previously. In order to create such behaviour, we need to enter VB code. We can access the code window by choosing the appropriate code tab above the central form design window; see annotation in Figure 4. If the code tab is not already visible, double click one of the elements of the form in the design window, eg the text box, and the window in Figure 7 should now appear. Here you can see a Sub procedure related to the object TextBox1 and the event that might happened to it, namely that it has Created On 15/10/2003 4 Last Modified: 07/10/2005
  • 5. Rapid Application Development 1 (F21RA1) Rick Dewar experienced a TextChanged event. If you pull down the lists in these combo boxes at the top of code window, you’ll see the other objects that you could choose from and the other events that can happen to them, respectively. Figure 7 - The Code Window for the Form There is a lot of text, terms and language in this code that will be unfamiliar to you. Please don’t panic; you will eventually and gradually learn what is important. For the moment we are making simple changes to small parts of the code. You now need to enter code (i.e. instructions) in the Sub procedure (TextBox1_TextChanged) to enable the button in our scenario. The significant line that you need to add is the second line below. If you type “button1.” (notice the full stop), you’ll see a list of valid properties appears. The full stop means you are interested in some property or component of the button. Highlight the property you want (ie enabled) and hit tab. Then enter an equals sign and another list will show valid values of that property. Clever time-saving, error-avoiding feature isn’t it? Private Sub TextBox1_TextChanged(...)... Button1.Enabled = True End Sub Notice the indentation of the second line. This makes it easier for us to read and is very important for you to remember. However, the Visual Studio environment can automatically do this sort of formatting for you. So what we’re saying is that when a change happens to TextBox1, we want to set the enabled attribute of the object Button1 to True. Try and run the application again and see what happens when you add text to the text box. Now let’s add the second part of our scenario where we display the greeting in the label. Here we want to enter: Private Sub Button1_Click(...)... Label1.Text = "Hi " + TextBox1.Text + ". How are you?" End Sub The plus signs here add strings of text together rather than numbers. Feel free to experiment with the content and formatting of this text so you can understand how it works. Having saved your work, when you run the application you should be able to see output like we have in Figure 8. Created On 15/10/2003 5 Last Modified: 07/10/2005
  • 6. Rapid Application Development 1 (F21RA1) Rick Dewar Figure 8 - Some Simple Behaviour To enhance our scenario, let’s create a new Sub procedure that will clear the contents of the text box when the text in the label changes. To do this, select the Label1 object from the combo box at the top left of the code window and then select the TextChanged method from the right hand combo box. You will see that an empty Sub procedure has been created. Now add a line to this new procedure that will clear/nullify the text of the text box. An empty string can be created using two double quotes. Furthermore, in the same Sub, add another line of code that will disable the button when the label’s text changes. Finally, make sure you save All of the project and then create a standalone executable of the application by choosing Build Solution from the Build menu. Once you’ve done this, you can locate the application (file type .exe) in your file system and run it independently of the Visual Studio environment. T2: Now get a lab helper to tick your name off the list to show you’ve completed this series of tasks. Remember, these ticks count towards your overall mark for the module. Well done, if you’ve got this far and have had all your work ticked off. Please note that your next lab will build on the work you have done here so make sure you do not lose or delete this VB project. Created On 15/10/2003 6 Last Modified: 07/10/2005