Android Question call a sub with the values of a variable

Discussion in 'Android Questions' started by parijs, Feb 10, 2015.

  1. parijs

    parijs Active Member Licensed User

    Is it possible to call a sub with the values of a variable
     
  2. klaus

    klaus Expert Licensed User

    What exactly do you want to do ?
     
  3. DonManfred

    DonManfred Expert Licensed User

    Code:
    dim mystring as String = "Hallo world"
    MySub(mystring)
    '
    '
    Sub MySub(myvalue as String)
      
    ' here you get he given value in myvalue
      log(myvalue)
    end sub
     
  4. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Not sure how you mean?

    Code:
    Sub example(val1 As Int, val2 As Int) ' declare any type of variable you need

    Log("Value 1=" & val1 & " Value 2=" & val2)

    End Sub

    ' call using...
    example(variable1, variable2)
    Or of course you could use a global variable inside your sub?
    Or do you mean...

    Code:
    Select var
        
    Case "example"
            example(variable1, variable2) 
    'sub call to example
        Case "example2"
            example2(str1, str2) 
    'sub call to example2
       Case Else
            anothersubname 
    'sub call to anothersubname
    End Select
    This is not quite dynamically calling of a Sub but I don't know of another way.
     
  5. parijs

    parijs Active Member Licensed User

    Something like this Claus

    Dim Variable As String
    Variable = "Try"

    Variable 'gall the sub

    Sub Try
    ....
    End Sub
     
  6. DonManfred

    DonManfred Expert Licensed User

    No you can not do this

    Maybe you can use a callsub or callsubdelayed

    this works (but remember Try is a registered keyword. You can not use it as subname)

    Code:
    Dim Variable As String
        Variable = 
    "TryThis"
        CallSubDelayed(Me,Variable) 
    'call the sub


    Sub TryThis
    Log("Trythis")
    End Sub
     
    Last edited: Feb 10, 2015
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I could be wrong but I think you will need to use the Select Case statement or similar to program each call.
     
  8. warwound

    warwound Expert Licensed User

  9. DonManfred

    DonManfred Expert Licensed User

    this will work too when not executed in activity_create
    Code:
    Sub Activity_Resume
        
    Dim Variable As String
        Variable = 
    "TryThis"
        
    CallSub(Me,Variable) 'call the sub
    End Sub
     
    lemonisdead and RandomCoder like this.
  10. parijs

    parijs Active Member Licensed User

    Hi Don

    It was only an example
    Your code works thank you :)
     
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