<< Chapter < Page
  Ti dsp/bios lab   Page 1 / 1
Chapter >> Page >
The module is a lab assignment to help you better understand the very basics of Microsoft Visual Basic delegates.

Introduction

This lab module will help you become familiar with the basics of delegates in Microsoft Visual Basic(V). The exercises are written assuming you are using Visual Basic 2005 and the .NET Framework version 2.0 (or later). Some older versions will work the same, but you may need to figure out some differences. It should work with newer version also.

Module prerequisites

You should complete the Visual Basic Threads and Semaphores lab before this one.

Labratory

Part 1

  • In this part you will make a project with a thread that will try to change a TextBox text without using a delegate method. When the thread tries to change the TextBox text it won't work because the TextBox control is not handled by the thread.
  • Start up Visual Studio and create a new Visual Basic project.
  • On the GUI, put a new TextBox. By default it should have the name TextBox1 .
  • Create a thread called Task1 and start the thread in the Form1_Load method.
  • In the thread method Task1 , assign a string to the TextBox.
  • Run your program and observe what happens. You should get an error when the thread tries to access the TextBox control. Record what the error says.

Part 2

  • In this part we will make a delegate that will allow the thread to change the text in the TextBox.
  • Either start a new project or modify the one from the previous part. What you should have in your project is:
  1. A TextBox on the GUI with the name TextBox1 .
  2. A thread called Task1 that is started in the Form1_Load method.
  • Add commands to define a delegate type and an instance of a delegate. If you want to use the names shown here you can. These statements should be right under the beginning of the Form1 class (right after " Public Class Form1 ").
Delegate Sub DelegateType(ByVal myStr As String) Dim IDel As New DelegateType(AddressOf DelegateMethod)
  • Make a new DelegateMethod method that takes a string as an input and uses it to change the text of the TextBox.
  • In the Task1 method, use the TextBox1 to invoke the delegate method. Have it write the text "Task Text" to the TextBox.
  • Run your program and observe that the text "Task Text" gets written to the TextBox.

Part 3

  • In this part we will make a simple clock. All we will do is continuously get the current time and write it to the TextBox.
  • In this part we will have everything that is in the previous part so you can start where it left off. Your project should have:
  1. A TextBox on the GUI with the name TextBox1 .
  2. A thread that uses the Task1 method that is started in the Form1_Load method.
  3. Commands to define a delegate and an instance of a delegate.
  4. A delegate method that writes the input string to the TextBox.
  • In the thread, we will have it get the current date/time and the write it to the TextBox.
  • Put the following commands that will define objects to get the current date/time.
Dim count As Integer Dim dispDt As DateTimeDim datePatt As String = "M/d/yyyy hh:mm:ss tt" Dim dtString As String
  • In the thread make a continuous while loop that puts the date into the string dtString and then sends that string to the delegate. To get the date use the command:
dispDt = DateTime.Now ' get the time now dtString = dispDt.ToString(datePatt) ' Convert the date to a string
  • In the while loop make the thread sleep for 100 ms so that it is not doing too much processing. It will get the time/date and write it to the TextBox every 100 ms.
  • Run your program and observe that the text displays the date/time and that the seconds change.

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ti dsp/bios lab. OpenStax CNX. Sep 03, 2013 Download for free at http://cnx.org/content/col11265/1.8
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ti dsp/bios lab' conversation and receive update notifications?

Ask