Download presentation
Presentation is loading. Please wait.
1
CSI 101 – Elements of Computing Spring 2009 Lecture #15 – Using Classes in Visual Basic 2008 Wednesday, April 22 nd
2
Example Our client has an online music sharing service. They need a means to track their members, their music library, and the favorites of their members.
3
Okay, let’s work on this What do we need to do: What do we need to do: Determine objects Determine objects Determine properties Determine properties Code methods Code methods
4
Objects Member Member Personal data Personal data Contains list of music preferences Contains list of music preferences Music Library Music Library Series of music Series of music Let’s chart the member data… Let’s chart the member data…
5
Classes Class Music Artist as String Title As String Genre as String Hits as Long
6
Classes, cont Class Member Name as String Account As Integer Userid as String Password as String Email as String Catalog(5000) As Music
7
Determine Properties Class Music Class Music All Member data would be desired All Member data would be desired Class Member Class Member Name, Account, and Email Name, Account, and Email Userid and password should remain hidden Userid and password should remain hidden Will have methods to verify or change password Will have methods to verify or change password Catalog can’t have a Property Catalog can’t have a Property Arrays don’t work Arrays don’t work
8
Adding Properties Our classes are getting big Our classes are getting big We’ll work in Wordpad We’ll work in Wordpad
9
Next, on to Methods How will we use these classes? How will we use these classes? Music Music “Hit” – another member downloads song “Hit” – another member downloads song Adding a new song is simply creating a new instance Adding a new song is simply creating a new instance Constructor handles that Constructor handles that Member Member Signing in (verify userid and password) Signing in (verify userid and password) Add song to catalog Add song to catalog
10
Adding Methods We’ll add methods, and then write a couple of event procedures to use the classes We’ll add methods, and then write a couple of event procedures to use the classes We’ll work in Wordpad We’ll work in Wordpad
11
Using the classes in a Form Okay, let’s see how to use the Member class Okay, let’s see how to use the Member class Button on Form to Join: Button on Form to Join: Sub Join_Click( ) DoCmd.OpenForm(“User information”) ‘Opens form to get name, userid, and password – assume stored as data newid = NextID() ‘system function for unique id uid = getPath() ‘system function to get email addr Dim user As New Member(newid, name, userid, pwd, uid) End Sub
12
Using classes on a Form, cont Logging in: Logging in: Sub Login_Click( ) DoCmd.OpenForm(“Get Login”) Dim user As Member user = Find(getPath()) ‘finds user with email addr Dim check As Boolean check = user.Validate(userid, pwd) ‘check against userid and pwd provided on login form If check = False then MsgBox (“Invalid login”) TerminateConnection() TerminateConnection() End If End Sub
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.