Problem return structure from Sub

Discussion in 'Questions (Windows Mobile)' started by webber, Mar 27, 2015.

  1. webber

    webber Member Licensed User

    Hello Everybody,
    I'm trying to make working this code:

    Code:
    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
     
  2. Cableguy

    Cableguy Expert Licensed User

    If its declared in globals, you shouldn't need to use a return
     
  3. webber

    webber Member Licensed 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:

    Code:
    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
     
  4. klaus

    klaus Expert Licensed 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.
     
  5. webber

    webber Member Licensed User

    I found a solution:
    -Remove argument from 'Return'
    -modify code calling sub like this:
    Code:
    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
     
  6. webber

    webber Member Licensed User

    Sorry Klaus, but on basic4ppc help I found this example about Type Syntax:
    Code:
    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.
     
  7. klaus

    klaus Expert Licensed User

    Are you speaking about Basic4PPC or Basic4Android?
    Where did you find DimType(Name, ID, Age) person ?
    If you enter Type in the Search Box you'll get the answer on top.
     
  8. webber

    webber Member Licensed User

  9. klaus

    klaus Expert Licensed User

    Sorry, I didn't notice that it was the B4PPC forum.
     
  10. webber

    webber Member Licensed User

    Don't worry Klaus, thank you for Your prompt replies
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice