Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro.

Similar presentations


Presentation on theme: "1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro."— Presentation transcript:

1 1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro

2 2 The Language Custom Classes

3 HCI430 – J.Toro3 Custom classes VB.NET is Object-Oriented So far, you have handled pre-defined classes (Form, Button, Integer, String, etc…) -but- You can also create your own classes that can ease the coding and fit the needs of your prototype

4 HCI430 – J.Toro4 Custom classes How do you know when you need a custom class?  You need to do some design decisions on what kind of classes you will need.  There is no golden rule in this, many different classes can be created and used, it all depends how you want to architect your code.

5 HCI430 – J.Toro5 Custom classes When you are writing the code inside a form, you are actually writing the code for the Form’s class…

6 HCI430 – J.Toro6 Your form Your form is defined as a class

7 HCI430 – J.Toro7 Custom classes Creating a custom class  Custom classes are created in separate files  Same as different forms are in separate files  To add a custom class file 1. File -> Add New Item… 2. Select Class, give a name to it 3. Done.

8 HCI430 – J.Toro8 1

9 9 2 1 Select Class 2 Name the Class

10 HCI430 – J.Toro10 3 The class file appears in your Solution Explorer window This code is automatically generated. Here is where you write the code to define the properties and methods of your class.

11 HCI430 – J.Toro11 Custom classes Defining properties for the class  One way: Declare global variables as Public. Public Class Member Public p_id As String Public p_lname As String Public p_fname As String Public p_address As String Public p_city As String Public p_state As String Public p_zip As String End Class Properties

12 HCI430 – J.Toro12 Member class

13 HCI430 – J.Toro13 Custom classes Using your custom class  You create instances (objects) of the class Use the New keyword, the same way you use it to create forms.

14 HCI430 – J.Toro14 Form1 class You now can declare Member objects

15 HCI430 – J.Toro15 Custom classes Everything declared with either Dim or Private will not be accessible from outside the class.

16 HCI430 – J.Toro16 p_ssn is not declared Public. It will be accessible only inside this class. Member Class

17 HCI430 – J.Toro17 p_ssn is not accessible outside the class, it was not declared Public. x is an instance of Member class Form1 Class

18 HCI430 – J.Toro18 Custom classes Defining methods  All the subs and Functions declared Public are considered methods and are accessible outside the class.

19 HCI430 – J.Toro19 ResetNames is a Sub declared Public. It will be accessible outside. Member Class

20 HCI430 – J.Toro20 ResetNames is accessible. Form1 Class

21 HCI430 – J.Toro21 Custom classes Sometimes, you want your object to start with some preset values in some of its properties.  Constructor Used to provide values to the properties when an instance is created You can have different constructors for different situations A constructor is always declared as Public and it is always named New

22 HCI430 – J.Toro22 Constructor1 (default) Constructor2 (custom)

23 HCI430 – J.Toro23 constructor1 is used here constructor2 is used here

24 24 The Language Modules

25 HCI430 – J.Toro25 Modules Modules are files where you can write code that does not belong to any particular form.  Global functions  Global Subs  Global variables Global variables declared in a Module are global to all the project.

26 HCI430 – J.Toro26

27 HCI430 – J.Toro27 1 Select Module 2 Name the Module

28 HCI430 – J.Toro28 The module file appears in your Solution Explorer window This code is automatically generated. Here is where you write the code.

29 HCI430 – J.Toro29 Modules Sub Main  You can set the Startup Object of your project to a special sub named Main  You create the Sub Main inside a Module file.

30 HCI430 – J.Toro30 mainForm is a global variable mainForm is created mainForm is shown

31 HCI430 – J.Toro31 Modules In the previous example, if you set your startup object of your project to be the Sub Main, you have to create the instance of Form1 and show it. This is useful when you have a prototype with many form files.

32 32 The Language Class Libraries

33 HCI430 – J.Toro33 Class libraries A separate project for creating classes for use in other applications This is what you will get from me  A project with some classes inside

34 HCI430 – J.Toro34 Class libraries Using the library in your prototype  (1/2) Add the library into your prototype’s project

35 HCI430 – J.Toro35

36 HCI430 – J.Toro36 Select the project name

37 HCI430 – J.Toro37 The project appears into the Solution explorer

38 HCI430 – J.Toro38 Class libraries Using the library in your prototype  (2/2) Reference the class library in your project so you can start using the classes Why do you have to do this?  Because the classes I wrote are inside a separate project, they are not part of yours.

39 HCI430 – J.Toro39 1 Select your project 2 Select “Add Reference”

40 HCI430 – J.Toro40 1 Click over the Projects tab 2 Select the Utils Project 3 Click Select

41 HCI430 – J.Toro41 The library will appear here Click Ok

42 HCI430 – J.Toro42 The Utils library will appear listed under the References folder in your project

43 HCI430 – J.Toro43 Questions?


Download ppt "1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro."

Similar presentations


Ads by Google