Android Question stringutils, need left$

Mike Olmsted

Member
Licensed User
Longtime User
I have a lookup table like so...
B4X:
Sub SpinnerFill
Spinner1.Clear   
Spinner1.Add("Select account type")   
    Spinner1.Add("1, Cash")
    Spinner1.Add("2, Assets-Current ")
    Spinner1.Add("3, Assets-Other")
    Spinner1.Add("4, Liability-Current")
    Spinner1.Add("5, Liability-Other")
    Spinner1.Add("6, Capital")
    Spinner1.Add("7, Income")
    Spinner1.Add("8, Cost_of_Sales")
    Spinner1.Add("9, Expense")
End Sub
Then when I post it I only need the left digit example 1 or 2 or 3. I remember a left$ function in VB>

Thanks in advance, Mike
 

NJDude

Expert
Licensed User
Longtime User
This code will extract the number (assuming you always use commas as a delimiter)
B4X:
Sub Spin_ItemClick(Position As Int, Value As Object)
 
    Dim Digits As String
 
    Digits = Value 
    Digits = Digits.SubString2(0, Digits.IndexOf(","))
 
    Msgbox(Digits, "")
 
End Sub
 
Last edited:
Upvote 0

Mike Olmsted

Member
Licensed User
Longtime User
A combination of both replies worked,,,Thanks
B4X:
Sub SpnAccount_ItemClick(Position As Int, Value As Object)
    Dim Digits As String 
    Digits = Value 
    Digits = Digits.SubString2(0, 1) 
    EditText2.text = Digits
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Just in case you wish to avoid the indexing in front of the spinner's items, you can populate a list with these numbers, then get them by using the position value of the itemClick Event.
B4X:
sub globals
dim ls as list
...............

populate sub

ls.initialize
ls.add("1")
ls.add("2")
.............

sub ...ItemClick(...)
edittext2.text=ls.get(position)
..............
This can become a solution, in cases where the ids are 'ugly' numbers.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…