Problem return structure from Sub

webber

Member
Licensed User
Longtime User
Hello Everybody,
I'm trying to make working this code:

B4X:
Sub Globals
    Public Type(Codice,Nome,Targa) Veicoli
End Sub

Sub App_Start
    Ricerca.Form2.Show   
End Sub
Public Sub Veicolo(Codice)
Veicoli.Codice=Codice
Veicoli.Nome="Franco"
Veicoli.Targa="ES265CK"
Return Veicoli()
End Sub

It works fine when running on Desktop, but when I try to compile it return this error:

Compiler Error Message: CS0029: Cannot implicitly convert type string[] to string
Line Return Veicoli()

Any hint?
Thanks
Francesco
 

Cableguy

Expert
Licensed User
Longtime User
If its declared in globals, you shouldn't need to use a return
 

webber

Member
Licensed User
Longtime User
I'ts right, but Type can't be declared elsewhere.

My need is to call the sub Veicolo(Codice) from other modules just like this:

B4X:
Sub Globals
    Public Type(Codice,Nome,Targa) Macchina As String
End Sub
Sub Form2_show
    macchina()=main.Veicolo("1234")
    Msgbox (macchina.Codice & Chr(13) & macchina.Nome & Chr(13) & macchina.Targa)
End Sub
 

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do ?
This is wrong:
Public Type(Codice,Nome,Targa) Veicoli
It should be:
Public Veicoli Type(Codice As ???, Nome As ???, Targa As ???)
In the Type declaration you must set the variable type !
Then you need to dim a variable of this type.
You might have a look at chapter 10.3.4 Type variables in the Beginner's Guide.
 

webber

Member
Licensed User
Longtime User
I found a solution:
-Remove argument from 'Return'
-modify code calling sub like this:
B4X:
Sub Globals
    Public Type(Codice,Nome,Targa) Macchina As String
End Sub
Sub Form2_show
    main.Veicolo("1234")
    macchina()=main.Veicoli()
    Msgbox (macchina.Codice & Chr(13) & macchina.Nome & Chr(13) & macchina.Targa)
End Sub
 

webber

Member
Licensed User
Longtime User

Sorry Klaus, but on basic4ppc help I found this example about Type Syntax:
B4X:
Example:
Sub Globals
            Dim Type(Name, ID, Age) person
End Sub

I looked for the B4ppc guide but the link on an Erel's post is broken.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…