Passing return values back from a method

I’m calling a method that returns a true or false value if there has been a database error see below:

Public Function AddURLRow(URL As String, comment As String) as Boolean
// Add a row to the url table
If Not IsConnected Then
MsgBox(“Create the database and create the table first.”)
Return False
End If
Dim d as new date
Dim row As New DatabaseRecord
// ID will be added automatically
row.Column(“url”) =url
row.Column(“comment”) = comment
row.Column(“datechange”) = str(d)

App.DB.InsertRecord(“urldata”, row)

If App.DB.Error Then
MsgBox( "DB Error: " + App.DB.ErrorMessage)
Return False
End If

//Return True
End Function

here is the calling code:
Dim d as new date
Dim row As New DatabaseRecord
// ID will be added automatically
row.Column(“url”) =url
row.Column(“comment”) = comment
row.Column(“datechange”) = str(d)

	App.DB.InsertRecord("urldata", row)
		If  Not App.DB.Error   then
			MsgBox("Record Added")
			return
	       End if
	I keep getting the error message:URLManager.AddButton Action line 46, you must use the  value returned by the function.  

Can somone please explain to me why I’m getting this message as it seems to me I am using the returned value App.DB.Error.

so which line is line #46 (the line numbers appear at the bottom of the editor window)

Please use code tags around your pasted code to make your posts more readable.

I can’t see any call to AddURLRow in the calling code, so perhaps you’ve pasted the wrong data here?

Also never use str(d) to save date data to a database. Always use d.sqldatetime.

Sorry, Here is the calling code:

[code] Dim url,comment as string
url = urlfield.text
comment = “This is a comment”
AddURLRow(url,comment)

	If  Not App.DB.Error   then
			MsgBox("Record Added")
			return
	End if[/code]

Thanks for the tip on setting the date. Line 46 follows:

[code]AddURLRow(url,comment)/code]

I’m just trying to set a variable to he current date and time and it Is not clear to me how d.sqldatetime works: the following code throws type mismatch errors:

Dim d as new date d =d.SQLdatetime row.Column("datechange") = d.SQLDateTime

One problem with your code is that AddURLRow doesn’t return anything useful. It either returns False, or it returns nothing (which is the default value of False). You have 2 options:
1 - In AddURLRow, return App.DB.Error (or at least return TRUE in your if App.DB.Error Then block). And change your calling code to

if AddURLRow(url,comment) then
     MsgBox("Record Added")
     return
End if

2 - Remove the return value from AddURLRow
3 - Change AddURLRow such that it returns TRUE on success and FALSE on failure. Modify the code in 1), above, appropriately.

I would recommend option 3.

[quote=314229:@Delbert Thompson]I’m just trying to set a variable to he current date and time and it Is not clear to me how d.sqldatetime works: the following code throws type mismatch errors:

Dim d as new date d =d.SQLdatetime row.Column("datechange") = d.SQLDateTime[/quote]
Use

Dim d as new date
row.Column("datechange") = d.SQLDateTime

Thank you for your replies. Your suggestions have everything working now. Would you be able to recommend a good XoJo for dummies books that would take me through building a database application?

Thanks again for your help.

There is no Xojo for Dummies, but you can still find RealBasic For Dummies at Amazon, starting at $1.09 :
https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=realbasic+for+dummies

A good deal of the content is still valid. Of course the pictures of the IDE do not match, but the principles of the language remain.

More contemporary, but in electronic form only, “Database with Xojo”, by Eugene Dakin, at http://xdevlibrary.com/

The best resource I can recommend is Bob Keeney’s training videos at http://xojo.bkeeney.com/XojoTraining/

He has a video series that builds a complete database appication and also provides example projects to work through. Very good stuff.

In addition, here are links to some of our database-related materials:

Lastly, you might also want to refer to the Eddie’s Electronics sample app:
Examples/Sample Applications/EddiesElectronics

Thank you for all the great reference material suggestions!