Me again. Still struggling with the introduction to programming
P71
Did this:
Add a new method called GetSelectedFont to Window1.
Added to method:
Dim currentFont As String
If FontListBox.ListIndex <> - 1 Then
currentFont = FontListBox.List(FontListBox.ListIndex)
Else
currentFont = “”
End If
Return currentFont
Made a PushButton FontButton and added this code to Action event
Dim fontName As String
fontName = GetSelectedFont
MsgBox "You have selected " + fontName
Run gives errors:
This method doesn’t return a value
fontName = GetSelectedFont
Type mismatch error. Expected String, but got Int32
fontName - GetSelectedFont
You cannot return a value because this method has not defined a return type
Return currentFont
You need to define the return type in the properties window for the method not within the method It is the Return Type field in the properties window for the method.
That solved it, but I never would have guessed that these few words: “but its Return Type should be String”’ should have led me to the properties inspector where it would be necessary to set a return type. It strikes me as odd this would not be done with code.