Android Question Calculation

G-ShadoW

Active Member
Licensed User
Longtime User
Hello,

I have 2 EditText's and one button

EditText1 is for input x
EditText2 is 00001

If I enter in EditText1 number 5

after pressing button I need that EditText1 to look like ( 00002, 00003, 00004, 00005, 00006 ) and edittext2 will be 00006
 

udg

Expert
Licensed User
Longtime User
Hi,
use NumberFormat like in:
B4X:
Log(NumberFormat(1, 5 ,0)) '"00001"
In your button1_clik just use a for loop to generate as many items as the new value inserted in EditText1 indicates, place those items in a string that will be your final EditText1 and use last one of them to populate EditText2.

udg
 
Last edited:
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
B4X:
EditText1.Text=NumberFormat2((EditText1.Text + EditText2.text), 5, 0, 0, False)

calculation for only 1 number, but I dont know how to add 5 calculation's in loop
 
Upvote 0

udg

Expert
Licensed User
Longtime User
If I understand it correctly, you would need something like
B4X:
dim start as int = EditText2.text
dim count as int as EditText1.text
dim s as string = ""
for i = 1 to count
  s=s&NUmberFormat(start+i,5,0)&" "
next
EditText1.text = s  '00002 0003....
EditText2.Text=NumberFormat(start+count,5,0)
Code not tested and useful just to show what I understood out of post#1
ps: there are better ways to do it!
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
B4X:
Sub Button1_Click

  EditText3.Text=""
   
   Dim i As Int
   i=EditText1.text
   For i = NumberFormat2((EditText2.Text + 1),5,0,0,False) To EditText2.Text+i
   
     Log("Log : " & NumberFormat2((i), 5, 0, 0, False))
     EditText3.Text=EditText3.Text & NumberFormat2((i), 5, 0, 0, False) & ","
   
     Next
     
       
   If EditText3.Text.Length > 0 Then
     EditText3.Text = EditText3.Text.Substring2(0, EditText3.Text.Length - 1)
   End If
   
   EditText1.Text=(EditText1.Text + EditText2.text)
   
End Sub

I have done it this way, maybe there is a better and easier code, but this works exactly like I need.
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
If I understand it correctly, you would need something like
B4X:
dim start as int = EditText2.text
dim count as int as EditText1.text
dim s as string = ""
for i = 1 to count
  s=s&NUmberFormat(start+i,5,0)&" "
next
EditText1.text = s  '00002 0003....
EditText2.Text=NumberFormat(start+count,5,0)
Code not tested and useful just to show what I understood out of post#1
ps: there are better ways to do it!

there is syntax error in your code

B4X:
Dim count As Int As EditText1.text
 
Upvote 0

udg

Expert
Licensed User
Longtime User
You're right. It was intended just to show my understanding of your initial request. Read it as being more of a scheme than actual code.
 
Upvote 0
Top