# Passing return values back from a method

**URL:** <https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954>\
**Category:** Getting Started\
**Created:** [February 6, 2017, 9:36pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954 "2017-02-06T21:36:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Delbert\_Thompson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@Delbert\_Thompson](https://forum.xojo.com/u/Delbert_Thompson)\
**Post date:** [February 6, 2017, 9:36pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/1 "2017-02-06T21:36:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [February 6, 2017, 9:40pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/2 "2017-02-06T21:40:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wayne\_Golding](https://forum.xojo.com/user_avatar/forum.xojo.com/wayne_golding/32/165_2.png) [@Wayne\_Golding](https://forum.xojo.com/u/Wayne_Golding)\
**Post date:** [February 6, 2017, 10:32pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/3 "2017-02-06T22:32:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Delbert\_Thompson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@Delbert\_Thompson](https://forum.xojo.com/u/Delbert_Thompson)\
**Post date:** [February 7, 2017, 2:22am UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/4 "2017-02-07T02:22:34Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![Delbert\_Thompson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@Delbert\_Thompson](https://forum.xojo.com/u/Delbert_Thompson)\
**Post date:** [February 7, 2017, 2:32am UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/5 "2017-02-07T02:32:59Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [February 7, 2017, 2:44am UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/6 "2017-02-07T02:44:21Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [February 7, 2017, 2:46am UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/7 "2017-02-07T02:46:30Z")

</div>

[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

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

---

<div class="post-metadata">

**Author:** ![Delbert\_Thompson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@Delbert\_Thompson](https://forum.xojo.com/u/Delbert_Thompson)\
**Post date:** [February 7, 2017, 9:09pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/8 "2017-02-07T21:09:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [February 7, 2017, 9:23pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/9 "2017-02-07T21:23:04Z")

</div>

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](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/](http://xdevlibrary.com/)

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [February 7, 2017, 9:25pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/10 "2017-02-07T21:25:45Z")

</div>

The best resource I can recommend is Bob Keeney’s training videos at [http://xojo.bkeeney.com/XojoTraining/](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.

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [February 7, 2017, 9:51pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/11 "2017-02-07T21:51:45Z")

</div>

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

- [Database Overview](http://developer.xojo.com/userguide/database-overview)
- [Database Operations](http://developer.xojo.com/userguide/database-operations)
- [How do I use databases?](http://developer.xojo.com/kb/databases)
- [Webinar: Connecting to Databases](http://developer.xojo.com/webinar-connecting-to-db)
- [Webinar: Designing Delightful Databases](http://developer.xojo.com/webinar-designing-delightful-databases)

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

---

<div class="post-metadata">

**Author:** ![Delbert\_Thompson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@Delbert\_Thompson](https://forum.xojo.com/u/Delbert_Thompson)\
**Post date:** [February 8, 2017, 2:50am UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/12 "2017-02-08T02:50:29Z")

</div>

Thank you for all the great reference material suggestions!

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:38pm UTC](https://forum.xojo.com/t/passing-return-values-back-from-a-method/35954/13 "2020-10-29T18:38:46Z")

</div>


