Syntax Error 'Sub ...'

Newbie, working my way through ‘Introduction…’ tutorial. I’m getting a syntax error for a method (of ‘Course’) named ‘EnrollStudent’, taking 1 param ‘s’, with the code:
Me.EnrolledStudents.Append(s)

…where the Course property ‘EnrolledStudents()’ is data type ‘Student’. The error is:

Syntax Error
Sub EnrollStudent(s)

‘Newbie’ means I’m only dimly aware of what a subclass is, let alone what’s wrong with this one. I think the message is merely telling me the syntax is incorrect, but not why or what it should be.

The exercise is on page 204, where we are being introduced to classes and properties.

Whenever you declare a variable you must also specify the type with the As keyword:

Sub EnrollStudent(s As Student) Me.EnrolledStudents.Append(s) End Sub

Missing s datatype? Like: Sub EnrollStudent(s As String)

Thank you for the quick and agreeing replies. When I use Andrew’s code, I now get:

Syntax Error
End Sub

Something else doesn’t quite make sense. In the tutorial, he is just starting to get into OOP, and has not yet mentioned anything about subclasses. The other methods he’s had us build don’t use ‘Sub’.

The instructions for adding this method are:

  1. Add a method to your Course class called “EnrollStudent”.

  2. Add this code to EnrollStudent:

Me.EnrolledStudents.Append(S)

This method takes one parameter: S As Student. This method’s job is adding the
provided student to the EnrolledStudents array.

[quote=37006:@John Weinshel]Syntax Error
End Sub[/quote]

My fault, I think. The Sub EnrollStudent(s As Student) and End Sub lines should not be copied directly into the code editor. Rather, when you see code formatted like I did above you will need to break it into its parts in the IDE:
.

“Sub” is short for “Subroutine” and is not related to subclassing. In Xojo, methods come in two varieties: Function and Sub. The only difference (aside from the name) is that a Function returns a value but a Subroutine does not:

Sub SayHello(UserName As String) MsgBox("Hello, " + UserName + "!") End Sub

Function Add(Number1 As Integer, Number2 As Integer) As Integer Dim result As Integer = Number1 + Number2 Return result ' return a value End Function

Refer to page 111 of Book 1: Fundamentals for more on Xojo methods, return types, etc.

Not your fault at all: it just took you a couple of rounds to realize how newbie I am. I am a Filemaker beta tester, and the kind and gentle responses on this list are making me feel I should do a better job of answering beginner questions on Filemaker lists.

Adding ‘As Student’ to the method param solved the immediate problem, but, more importantly, your explanation explained why. I am indeed consulting Fundamentals before I post here, but a central problem of being a beginner is you don’t yet know what you don’t know, so it’s tough to know what to look for in the manuals.

Two more questions: how do I add a graphic to these posts, and how do I flag this thread ‘Solved’? If I click on the ‘Image’ icon here, it inserts an HTML link as, I presume, a placeholder. Does that mean I replace the placeholder text with the real file path, and the image will upload?

Thank you again.

Everyone was a newbie once :slight_smile:

Replace the example URL with the actual URL:

[img]http://example.com/image.jpg[/img]

The forum does not (yet) allow for uploads. If you have an image you want to share you’ll need to use a third-party hosting site (or have your own website.) For the screenshot in my previous post, I used Imgur, which is free and doesn’t require signing up.

Mouse over the message you want to flag, and a grey checkmark will appear in the top right corner of the message.

I had the exact same question. In my view, the manual is not at all clear on this point, suggesting that the sub and end sub statements should be included in the main body of the code.