


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A set of lecture notes from a course on Scripting Languages at Cornell University. The notes cover topics such as classes and properties, visual programming and callbacks, and dialog design in VBA. The document also includes examples of subtyping and event handlers in VBA. The notes touch on missing object-oriented features in VBA and how they have changed in VB.NET. useful for students studying programming languages, object-oriented programming, and VBA specifically.
Typology: Lecture notes
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















CS 5142 Cornell University 1
CS 5142 Cornell University 2
CS 5142 Cornell University 4
CS 5142 Cornell University 5
CS 5142 Cornell University 7
Dim someFruit As Fruit If … Then Set someFruit = New Apple Else Set someFruit = New Banana End If ' compiler knows that the method exists, ' even if it doesn’t know which version ' will get called someFruit.prepare("slice")
CS 5142 Cornell University 8
Public weight As Double Public Function pluck() As String 'empty routine End Function Public Sub prepare(how As String) 'empty routine End Sub Implements Fruit Public color As String Private wght As Double Private Property Let Fruit_weight(ByVal RHS As Double) wght = RHS End Property Private Property Get Fruit_weight() As Double Fruit_weight = wght End Property Private Function Fruit_pluck() As String Fruit_pluck = color & " apple" End Function Private Sub Fruit_prepare(how As String) Debug.Print how & "d " & Fruit_pluck() End Sub Class module “Fruit” (Interface) Class module “Apple” (subclass) Would be abstract in other languages “ Implements ” in subclass identifies superclass Override private with mangled name
CS 5142 Cornell University 10
Soap-box
CS 5142 Cornell University 11
CS 5142 Cornell University 13
Concepts chk Check box cmd Command button frm User form fra Frame lst List box cmb Combo box mnu Menu opt Option button lbl Label txt Text box
CS 5142 Cornell University 14
CS 5142 Cornell University 16
Sub paintLemonStar(nLines As Integer) Dim n As Integer, i As Integer n = nLines - 1 For i = 0 To n Dim l As Shape Set l = ActiveWindow.Selection.SlideRange.Shapes.AddLine( _ BeginX:=300, BeginY:=200 + i * 100 / n, _ EndX :=400, EndY :=300 - i * 100 / n) l.Line.ForeColor.RGB = RGB(i * 255 / n, i * 255 / n, 0) Next i End Sub Private Sub cmdPaint_Click() paintLemonStar CInt(txtNumberOfLines.Text) Hide End Sub Private Sub cmdCancel_Click() End End Sub
Retrieve user input Callbacks with mangled names Auxiliary subroutine
CS 5142 Cornell University 17
CS 5142 Cornell University 19
CS 5142 Cornell University 20
VBA form Subroutine in form with mangled name VBA class WithEvent / RaiseEvent statements Java Pass object on which to call method Perl, Python, JavaScript Pass anonymous function (lambda) C, C++ Pass function pointer C++ Pass object on which to call “()” operator SmallTalk Pass code block PHP Pass name of function as string Concepts