<< 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 biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
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