take a initial number of textbox1.text

fifiddu70

Well-Known Member
Licensed User
Longtime User
I need to make a calculation of a textbox, the textbox contains the following parameters:
B4X:
TextBox1.Text = "5 burger € 4.50"
I need to take the initial value of 5 textbox that represents the amount of hamburger to perform a multiplication.
The initial value of the textbox can change from 1 to 100 and contains only numbers, how do I take these initial numbers.
 

mc73

Well-Known Member
Licensed User
Longtime User
I think you are not in the correct path. Instead of constructing a textbox and then trying to get values from it, it would be more simple and efficient, to simply store the values in an array, or list, while user inputs data.
Example: I press 5, you store this. I choose 'burger' you store its id. Value is 4.50, you store this. You don't go in a textbox and grab the contents.
If somehow you insist following this path, you should use formulae as the ones kindly provided by Klaus to another similar post you did earlier.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
SInce there is always a space after the number, you can do somthing like this:
B4X:
Dim MyValue As Float
TextBox1.Text = "5 burger $4.50"
MyValue=TextBox1.Text.SubString2(0,TextBox1.Text.IndexOf(" "))
Msgbox(MyValue,"")  'returns 5
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I fully agree with mc73 !
Where does your data come from ?
How do you fill the EditText and (or) the ListView.
You already asked how to extract the value from an EditText here and you got an answer.
Then you aked a similar question here, the principle to extract is exactly the same.
Now you ask once again a similar question here, the principle is always the same !

I think you should expose the whole project on what you want to do and then we could give you concrete advices on how doing it.

Best regards.
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
sorry if they are insistent, unfortunately some things I can not understand them and try to study to improve my knowledge of basic4android, now thanks to your help I was able to almost finish my project is to extrapolate from the textbox the cost in euro and return it to another textbox, but I can not do the other way around, I now extract only the text without the cost in euro, whereas the text can vary in length, with the method index the individual value € but how do I put all the text before the value €?
I hope to have your help and understanding for my little knowledge of basic4android
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Once again, please explain the whole problem, what data where does it come from and what do you want to do with it.

I asked you two questions you didn't answer.
Where does your data come from ?
How do you fill the EditText and (or) the ListView.


Depending on how your data is organized the advice will be different.
For example you have the text: 5 burger € 4.50
- where does it come from ? Is it a full string or is it composed of different data ?
- what is 5 and where does it come from ?
- where does burger come from ?
- where does 4.50 come from ?
All thes data should be in array variables.
Knowing the index of the dataset you know every single value.

Now for you specific question:
B4X:
Dim i As Int
i = textboxdescription.Text.IndexOf("€")
If i >= 0 Then
    ' extracts the cost
  textboxeuro.Text = textboxdescription.Text.SubString2(i + 2, textboxdescription.Text.Length)
    ' extracts the text befor €
    textboxtext.Text = textboxdescription.Text.SubString2(0, i)
End If
Best regards.
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
I solved the problem, I was able to work efficiently throughout the project, now I'm finishing a few tweaks to the code and then finally going to launch an update on google play,
thanks friends.
 
Upvote 0
Top