1 / 12

CSI 101 – Elements of Computing

This example demonstrates using classes in Visual Basic 2008 to track members, their music preferences, and manage a music library for an online music sharing service.

smoot
Download Presentation

CSI 101 – Elements of Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSI 101 – Elements of Computing Spring 2009 Lecture #15 – Using Classes in Visual Basic 2008 Wednesday, April 22nd

  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: • Determine objects • Determine properties • Code methods

  4. Objects • Member • Personal data • Contains list of music preferences • Music Library • Series of music • 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 • All Member data would be desired • Class Member • Name, Account, and Email • Userid and password should remain hidden • Will have methods to verify or change password • Catalog can’t have a Property • Arrays don’t work

  8. Adding Properties • Our classes are getting big • We’ll work in Wordpad

  9. Next, on to Methods • How will we use these classes? • Music • “Hit” – another member downloads song • Adding a new song is simply creating a new instance • Constructor handles that • Member • Signing in (verify userid and password) • 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 work in Wordpad

  11. Using the classes in a Form • Okay, let’s see how to use the Member class • 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: 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() End If End Sub

More Related