Android Question Type with select case

Discussion in 'Android Questions' started by Enthousiastic, Jul 19, 2015.

Similar threads

B4A Tutorial StateListDrawable example
B4A Code Snippet Switch Colors
B4A Library CustomListView - A flexible list based on ScrollView
B4A Tutorial Nine patch images tutorial
B4A Code Snippet ColorStateList
B4A Library RippleDrawable
  1. Enthousiastic

    Enthousiastic Active Member Licensed User

    Hello , in Sub Process_Globals i wrote :

    Type ColCondition ( ConBlue As String , ConBrown As String , _
    ConGreen As String , ConRed As String , ConYellow As String , GonGrey As String )

    In a sub i wrote :

    Sub DBButtonFirstR(Condition As ColCondition ) As StateListDrawable

    Dim BtnOn , BtnOff As String
    Dim bdwOn,bdwoff As BitmapDrawable
    Dim sldmotor As StateListDrawable

    Condition.Initialize ' <==== is wrong ?

    Select Condition

    Case Condition.ConBlue

    BtnOff= btnFirstR_Blue(0)

    End Select

    bdwOn.Initialize(LoadBitmap(File.DirAssets, BtnOn))
    bdwoff.Initialize(LoadBitmap(File.DirAssets, BtnOff))

    Dim states(2) As Int
    states(0) = sldmotor.state_enabled
    states(1) = -sldmotor.state_pressed
    sldmotor.addState2(states, bdwoff)

    Dim states(1) As Int
    states(0) = sldmotor.state_enabled
    sldmotor.addState2(states, bdwOn)

    Return sldmotor

    End Sub

    but i i have error in select condition statement
    What shall i write ?

    Many thanks enthousiastic
  2. sorex

    sorex Expert Licensed User

    what is condition supposed to be? it's nowhere defined in the source.
  3. sorex

    sorex Expert Licensed User

    oh there it is... it's a sub parameter.

    what's the code before calling the sub?

    you should init it there and pass a value to it before calling the parameterized sub
  4. Roycefer

    Roycefer Well-Known Member Licensed User

    In addition to what sorex said (don't re-initialize Condition in the sub, it will have been initialized outside of the sub), there are other problems. ColCondition is a Type (which is to say, it's basically a class with no member functions and all public data members), not an Enum (as of yet, B4X doesn't support Enums). It is essentially 6 Strings bundled together. When you call
    Select Condition
    Case Condition.ConBlue
    you're asking if Condition is equal to Condition.ConBlue, which is meaningless. How can an object containing 6 Strings be equal to one of the Strings in that object?

    I'm guessing at what you're trying to accomplish but I don't think you need a Type called ColCondition, you just need a String variable called ColCon and you can do this:
    Select ColCon
    Case "blue"
              BtnOff= btnFirstR_Blue(
    End Select
    Also, I assume there are more Cases in that Select statement because if "blue" is the only one, you're better off with an If-Then.
    Last edited: Jul 19, 2015
    ArminKH likes this.
  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