Android Question How to set List condition ?

Theera

Well-Known Member
Licensed User
Longtime User
I'm sorry my English.
If I have many button in the panel,and I set Tag property is price|RoomNo.
I have the problem as line is >> if mimelist=RentedRoom Then
How do I do?

I have used : if mimelist.get(1)=RentedRoom Then >> Error

B4X:
For i = 0 To Starter.RentedRooms.Size - 1
        Dim RentedRoom As String
        RentedRoom = Starter.RentedRooms.Get(i)
        Log(RentedRoom)
        For Each v As View In Panel1.GetAllViewsRecursive
        
            If   v Is Button Then
                Dim mimeList As List = Regex.Split("\|",v.Tag)
                
                If mimeList=RentedRoom Then
                    v.Enabled=False
                End If
            End If
        Next
    Next
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
B4X:
     If mimeList=RentedRoom ...

This line is definitely a problem (but maybe not the only one). You are testing if a List object (actually an integer pointer value) matches a string value (a word or phrase) - this will never succeed.

Can you give an example of what you expect RentedRoom to contain? Will it be, for instance "35.00/253" (ie room 253 costs 35.00 per night)? Are you trying to find the button that contains that as a Tag value?
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I'm sorry my English.
If I have many button in the panel,and I set Tag property is price|RoomNo.
I have the problem as line is >> if mimelist=RentedRoom Then
How do I do?

I have used : if mimelist.get(1)=RentedRoom Then >> Error

B4X:
For i = 0 To Starter.RentedRooms.Size - 1
        Dim RentedRoom As String
        RentedRoom = Starter.RentedRooms.Get(i)
        Log(RentedRoom)
        For Each v As View In Panel1.GetAllViewsRecursive
       
            If   v Is Button Then
                Dim mimeList As List = Regex.Split("\|",v.Tag)
               
                If mimeList=RentedRoom Then
                    v.Enabled=False
                End If
            End If
        Next
    Next

>> Dim mimeList As List = Regex.Split("\|",v.Tag)

>> If mimeList=RentedRoom Then

This can't work.
RegEx.Split produces a string array. Assigning it to a list (mimeList) might be OK, but I would avoid this.
mimeList = RentedRoom can never work as you comparing a string to a list.

What are the texts in Starter.RentedRooms?
I take it that that is a list.

RBS
 
Upvote 0

emexes

Expert
Licensed User
Can you give an example of what you expect RentedRoom to contain? Will it be, for instance "35.00/253" (ie room 253 costs 35.00 per night)? Are you trying to find the button that contains that as a Tag value?

Subject to confirmation by @Theera , I am guessing that:

- RentedRoom is a list of room numbers (eg "253b") that are already rented out
- The price-room separator is a vertical bar "|" not a forward slash "/"
- He has multiple buttons representing rooms (perhaps on a map) and he wishes to disable the rooms (buttons) that are already rented out eg in RentedRoom list
 
Upvote 0

emexes

Expert
Licensed User
If I have many button in the panel,and I set Tag property is price|RoomNo.
I have the problem as line is >> if mimelist=RentedRoom Then
How do I do?
Subject to confirmation by @Theera , I am guessing that:

In the absence of further clarifying information, perhaps try something like:

B4X:
For i = 0 To Starter.RentedRooms.Size - 1
    Dim RentedRoomNumber As String = Starter.RentedRooms.Get(i)
    RentedRoomNumber = RentedRoomNumber.Trim.ToLowerCase    'make consistent for comparison

    Log(RentedRoomNumber)

    For Each v As View In Panel1.GetAllViewsRecursive
         If v Is Button Then
            Dim TagFields() As String = Regex.Split("\|", v.Tag)
            if TagFields.Length >= 2 then    'ensure RoomNumber field present
                Dim ThisRoomNumber As String = TagFields(1)    'RoomNumber is second field
                ThisRoomNumber = ThisRoomNumber.Trim.ToLowerCase    'make consistent for comparison
                If ThisRoomNumber.CompareTo(RentedRoomNumber) = 0 Then    '0 = strings are same
                    v.Enabled = False    'room not available - already rented
                End If
            End If
        End If
    Next
Next
 
Last edited:
Upvote 1

Theera

Well-Known Member
Licensed User
Longtime User
Thank you ,all of you. @emexes ,your code is perfect.
 
Upvote 0
Top