function vs method in a menu handler

HI All.

I’ve got a question that reading the threads and the documentation, explains the difference well.
Function returns something
Method does not.

However, when I use the following code in a method, it keeps telling me I have to use the value.

If MyDBFile <> Nil Then MyDatabase = New SQLiteDatabase MyDatabase.DatabaseFile = MyDBFile If MyDatabase.CreateDatabaseFile Then If MyDatabase.Connect Then CreateSchema Return True Else Return False End If Else Return False End If End If

In the method, which is public, I set the return type to boolean.

If I take out the boolean, and enter this, it works like a charm.

[code]MyDBFile = SpecialFolder.ApplicationData.Child(“Ch12.sqlite”)
If MyDBFile <> Nil Then
MyDatabase = New SQLiteDatabase
MyDatabase.DatabaseFile = MyDBFile

If MyDatabase.CreateDatabaseFile Then //createdatabasefile will connect if the database already exists per the document library
If MyDatabase.Connect Then
CreateSchema // create the table

Else
  
End If 

Else

End If

End if[/code]

I’m easily confused.

Regards

which line is it complaining about ?
I have a guess but the compiler should be saying so in the errors pane and you can copy & paste that into the forums so we can tell

Slight clarification of terminology: a Method is code that does something and may or may not return a value. For clarity, a Function is what we call a Method that does return a value. Technically, a Sub (Subroutine) is a Method that does not return a value.

When the error message says that you must use the value it means that you are calling a Function (Method that returns a value) but are not using or assigning the returned value. My guess, without seeing exactly where the error is manifesting, is that the Method is returning a value (Boolean you said) but you are not using it where you are calling the method. That’s why when you remove the return value in the Method definition everything works.

almost seems like if removing the boolean return values works then the error is “You can t return a value because this method has no return type defined”

and that is quite different

Hi all.

Norman: the error is

[quote]“You must use the value returned by this Function”
“app.mycreateDatabase”[/quote]

Even when I had the return type as Boolean and in the code I tell it when to finish doing the if / then / else loop to return a true or false.

Dale. That is what I understood as well, which is why I added the return TRUE or FALSE. But it still stuck out its tongue at me.

Remove the return type as boolean, and it runs fine!

if your first post is the method “MyCreateDatabase” and it returns a boolean (like the following)

Function MyCreateDatabase() as boolean

If MyDBFile <> Nil Then
MyDatabase = New SQLiteDatabase 
MyDatabase.DatabaseFile = MyDBFile
If MyDatabase.CreateDatabaseFile Then
If MyDatabase.Connect Then CreateSchema
Return True
    Else
      Return False
End If Else
    Return False
  End If
End If
end function

then code like

app.mycreateDatabase

will call that method but does nothing with the returned boolean value
You have 3 choices

  1. ignore the returned value by rewriting that as
call app.mycreateDatabase // this will ignore the returned value
  1. “use” the returned value by rewriting that as
dim b as boolean =  app.mycreateDatabase 
  1. as you discovered - remove the RETURNs from the method and dont say whether things worked or not (probably NOT the best option but it is one option)