Error 17 from Return in subs or functions

New to FreeBASIC? Post your questions here.
Post Reply
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Error 17 from Return in subs or functions

Post by newbieforever »

Code: Select all

Declare Sub RemNul(sss As String)
Sub RemNul(sss As String)
  Dim As String aux = ""
  For in As Integer = 1 to len(sss)
    Dim As String fd = mid(sss, in, 1)
    If fd <> chr(0) Then aux = aux & fd
  Next
  Return aux
End Sub
What am I doing wrong?
Return aux: >>> error 17: Syntax error, found 'aux' ???


Two further newbie questions:
- Must Declare be used in such cases?
- I don't see a difference between Function and Sub in usage and syntax...
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: Error 17 from Return in subs or functions

Post by nimdays »

You need a function

Code: Select all

Declare function RemNul(sss As String) as string
function RemNul(sss As String) as string
  Dim As String aux = ""
  For in As Integer = 1 to len(sss)
    Dim As String fd = mid(sss, in, 1)
    If fd <> chr(0) Then aux = aux & fd
  Next
  Return aux
End function
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: Error 17 from Return in subs or functions

Post by newbieforever »

OK, thank you, nimdays!

I was confused because I saw everywhere that Return can be used in Subs too. But i see now:
"Sub is the same as Function, except it does not allow a value to be returned."
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: Error 17 from Return in subs or functions

Post by newbieforever »

May I append another question:

viewtopic.php?f=2&t=26848
Post Reply