Pause app to replace data entry

jschuchert

Active Member
Licensed User
Longtime User
My application sometimes requires users to replace an entry while the app is running. I have the following code to try to accomplish that but the code still continues after the message box is closed, thus preventing a new entry in an edittext box. Maybe someone can tell me how to work around this. Neither 'exit' nor 'return' does the job. It would be ideal if the issue could be handled immediately after making the original entry in the edittext box and prior to tapping OK. Thanks very much.

B4X:
Sub btnOK_click
main.strpointno = txtTo.Text 
generalsubs.pointprotect 
.
.
.
.
end sub

B4X:
Sub pointprotect
Dim reader As TextReader 
reader.Initialize (File.openinput(File.DirInternal, main.strfilename))
Dim lineoftext As String
Dim cline()
lineoftext = reader.ReadLine ' get the first line
Do While lineoftext<> Null 
cline = Regex.Split(",", lineoftext)
If cline(0) = main.strpointno Then
Msgbox("Point " & main.strpointno & " has been used. Please select another","msg")
'Return
Exit
End If
lineoftext=reader.ReadLine
Loop
End Sub

Jim Schuchert
 

kickaha

Well-Known Member
Licensed User
Longtime User
Are you trying to exit the btnOK_click sub if the point has been used?

If so you need to return a value from your pointprotect sub to indicate if the point has been used or not:
B4X:
Sub btnOK_click
main.strpointno = txtTo.Text 
if generalsubs.pointprotect Then Return ' if we get True back we know the point has been used.
.
.
.
.
end sub

B4X:
Sub pointprotect
Dim reader As TextReader 
reader.Initialize (File.openinput(File.DirInternal, main.strfilename))
Dim lineoftext As String
Dim cline()
lineoftext = reader.ReadLine ' get the first line
Do While lineoftext<> Null 
cline = Regex.Split(",", lineoftext)
If cline(0) = main.strpointno Then
Msgbox("Point " & main.strpointno & " has been used. Please select another","msg")
Return True ' A match was found so return true
End If
lineoftext=reader.ReadLine
Loop
Return False ' No match, return false
End Sub
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Andy,

I guess I spoke too soon. It did work a couple of times using the emulator. Now I am on a device and get a message about "cannot parse: as boolean" It is a java.lang.runtime exception. It happened the first time when I was going to put a number in that was new. Then even though a number exists, as soon as I click the ok button on the msgbox, the same thing happens. Can this be prevented? Since I don't have access to an emulator currently, I can't check that aspect.

Jim
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
It works on all devices I have tried, what version of android is the device ?

Edit to add:

I wonder if it is that I did not declare the return type?

Try
B4X:
Sub pointprotect As Boolean
.
.
.
End Sub
 
Last edited:
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
That didn't work, either. If fact, it now simply adds the same number again to the database. Without the 'boolean' addition, the program halts on the line where it says "if pointprotect, then return'. As mentioned before, it seemed to work with the emulator. Maybe I'll get that back when I hear from Erel again. Right now I can only compile to my tablet from the xp computer. It runs Android 2.1. Everything else seems to work ok on the tablet.

Jim
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Try replacing
B4X:
if generalsubs.pointprotect Then Return ' if we get True back we know the point has been used.
with
B4X:
if generalsubs.pointprotect  = True Then Return ' if we get True back we know the point has been used.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
The message box appears but after closing it, the code continues without a chance to replace the number. Say I go to point 3 which is already in the file. Message appears. I close the box. Code continues. Although point 3 has a different coordinate than before, it is not written to the file with that new coordinate. Earlier it would show both 3's with different coordinates but now still only shows the original 3. I really appreciate your time but don't spend any more time on this. I will try to figure out a work-around even if I have to cancel the point protection.

Jim
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Copied this from the other thread to keep it all together.

Jim,
You are never a pain!

Lets sum up the code and what should happen:

1) You click on the OK button

2) The Sub btnOK_click is called

3)within Sub btnOK_click you call generalsubs.pointprotect, and if this returns a True value we know we have a duplicate

4a) If we have a True value, we exit (Return) from the Sub btnOK_click to allow the user to enter a different number.

4b) If we have a False value we process the data

Now as I understand it when Sub pointprotect is called with a duplicate value, it is displaying the messagebox (so should be returning a True value), but the rest of btnOK_click is being run (so the true value is not triggering a return from btnOK_click.

Is that an accurate summary?

Now, post up the code that doesn't throw up the error and we can put some checks into it to see where it is falling over.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Andy,

I believe the problem may be solved. I noticed that I had not used "true" or "false" after the word 'Return' in the pointprotect sub. You had it in yours but somehow I must have removed it. I wondered why it had worked before. Now I know. I have left the declaration as boolean in and also the "= true" in the btnOK sub. I am very sorry to have wasted your time. If it is any different on the tablet, I will let you know. Thanks again for putting up with me. Believe it or not I have completed the code for 30 routines and now in the testing phase. I'm sure there is a lot of tweaking to do but hopefully the major part is behind me.

Jim
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
We have all made errors like that, just glad you have spotted it. Good to hear it is going so well, hope it survives the testing and tweaking (or should that be that YOU survive.....)

Time is never wasted when helping others, especially applies to friends.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…