FTP: How Can I Make the Msgbox Display the Message

Mahares

Expert
Licensed User
Longtime User
How can I make the below code stop at the msgbox and display when it succeeds and when it fails. It does not stop even with the msgbox in the code.
B4X:
'DOWNLOAD COMPLETED
   Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
       Log(ServerPath & ", Success=" & Success)
       If Success = False Then          
           Msgbox(LastException.Message & ". No Files were downloaded to device.".ToUpperCase,"")
            'Log(LastException.Message)
            Return
      Else
           Msgbox("Files downloaded successfully to device.","")
      End If
   End Sub
 

mc73

Well-Known Member
Licensed User
Longtime User
Mahares, what if you try using msgbox2? still the same?

Erel, yesterday another friend reported the very same msgbox behavior though with another process, that I don't remember right now? Perhaps something changed either with new version of b4a or some ROMs? I don't know...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I'm unable to reproduce it.
@Erel: When I intentionally disconnetc the internet or intentionally store a wrong password to test it, the msgbox does not stop when Success=False.
On the other hand, now it displays when it downloads successfully, but since I am downloading 6 files in succession, the message box stops after every file download. I would like it to only display when it completes all 6 files download.

what if you try using msgbox2? still the same?
@mc73: How would I use the msgbox2 when all I want is a message display, not a prompt to answer a question? You got me on this one.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I think you can use msgbox2 by simply inserting just the positive response, and placing "" for the other two. Then in checking the response you can guide your code proceeding with your next routine based on the result of the ftp process.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Erel and mc73: I tried to use the msgbox2 in the below code as mc73 suggested, but unfortunately the message does not show or stop to display when it fails, in other words when I intentionally disconnect the internet. The same behavior happens using the code in my first post of this thread. If you still need the full code, I can isolate it and post it.

B4X:
'DOWNLOAD COMPLETED
   Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
       Log(ServerPath & ", Success=" & Success)
         If Msgbox2("No connection","no internet",False,"","",Null)= DialogResponse.POSITIVE Then
               Msgbox(LastException.Message & ". No Files were downloaded to device.".ToUpperCase,"")
         End If
   End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I don't quite understand your code. Please try the following:
B4X:
'DOWNLOAD COMPLETED
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)

    Log(ServerPath & ", Success=" & Success)
    select Success
        
        case false
            dim rt as int
            rt=Msgbox2(LastException.Message & ". No Files were downloaded to device.","nointernet","OK","","",Null)            
            If rt= DialogResponse.POSITIVE Then
                                return
                     End If

        case true
            dim rt as int
            rt=Msgbox2("successful download,"allOK","OK","","",Null)            
            If rt= DialogResponse.POSITIVE Then
                                return
                     End If
    end select

End Sub

Please note that the changes I made haven't been tested, since I am writing from a PC without b4a installation.
A second note. I don't quite remember the procedure, but reading Erel's comment earlier, I think that a way to prevent the msgbox from closing, is to initiate your next download from inside the FTP_downloadCompleted Sub (or elsewhere) AFTER the previous download ended. Just a thought.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@mc73 and Erel: Thank you for your code. Unfortunately, it behaved exactly the same way as my first post code. What I am seeking the answer to is this:
When I intentionally disconnet the internet or intentionally store a wrong password to test it, I would like the msgbox to stop when Success=False. To my chagrin, it does not stop to say that it failed as I wanted it to display in the first post.
It does not stop at this below line:
B4X:
Msgbox(LastException.Message & ". No Files were downloaded to device.".ToUpperCase,"")
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
@mc73 and Erel: Thank you for your code. Unfortunately, it behaved exactly the same way as my first post code. What I am seeking the answer to is this:
When I intentionally disconnet the internet or intentionally store a wrong password to test it, I would like the msgbox to stop when Success=False. To my chagrin, it does not stop to say that it failed as I wanted it to display in the first post.
It does not stop at this below line:
B4X:
Msgbox(LastException.Message & ". No Files were downloaded to device.".ToUpperCase,"")

Question: Do you log the success flag and if so, you surely get a false? I mean, does the msgBox shows up, in the first place?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@mc73, a true friend: When I log a SUCCESS=True, the message box stops after each file download (in my code and yours) which is supposed to do that according to Erel's post, although I would like it to stop only after all files were downloaded. The problem is with the SUCCESS=FALSE. This is where I would like it to stop, but it does not stop at all.
Thank you for your willingness to always help.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
OK Margret thank you. I had an uneasy feeling that was it, but was never sure. Then, what kind of SUCCESS=FALSE situations will make the msgbox appear, in other words does it happen only when the download start and for some reason it aborts or what.
By the way, I have been monitoring the arrival of you new FTP class that you mentioned a few weeks ago, but have not seen it. If you need some guinea-pigs to test it, there are many of us.
Thank you
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Erel: Thank you so much for addressing this issue
1. SUCCESS=False: How good is log() to a user using the release version when he/she cannot see a msgbox to explain the problem. I am not as much concerned about the debug mode.
2. SUCCESS=True. How can you have only ONE msgbox when download success=true only after all 6 files have been successfully downloaded.
These are only the 2 issues I have not been able to accomplish.
Thanks
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
@Erel: Thank you so much for addressing this issue
1. SUCCESS=False: How good is log() to a user using the release version when he/she cannot see a msgbox to explain the problem. I am not as much concerned about the debug mode.
2. SUCCESS=True. How can you have only ONE msgbox when download success=true only after all 6 files have been successfully downloaded.
These are only the 2 issues I have not been able to accomplish.
Thanks

Dim a global array, an upload-counter and a totalUploads variable
B4X:
dim processFinishedFlag()as boolean, uploadCounter as int,totalUploads as int
uploadCounter=0
Inside the FTP sub, write
B4X:
processFinishedFlag(uploadCounter)=success:uploadCounter=uploadCounter+1
 if uploadCounter=totalUploads then
dim s as string:s="":for k=0 to totalUploads-1
s=s & "upload #" & (k+1) & " "
if processFinishedFlag(k)=false then s=s & "failed, " else s=s & "succeeded, "
next
msgbox(s,"something like this")
end if
You can even store the error messages in an array and display them in the same way.
Keep in mind, that due to the different size of the files, the sequence may vary, ie, you may see fie #3 positioned as #2 and so on. You can handle this, though, I just didn't get into checking more the ftp util.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
OK mc73. I will try that and report back. I am actually concerned about the DOWNLOAD part. I only upload 1 file, but download 6 files to the device. I hope I can still apply your code to the download.
Inside the FTP sub
I assume you are referring to the
B4X:
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
Thank you again for persevering.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
OK mc73. I will try that and report back. I am actually concerned about the DOWNLOAD part. I only upload 1 file, but download 6 files to the device. I hope I can still apply your code to the download.

I assume you are referring to the
B4X:
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
Thank you again for persevering.

Yes, that's the sub. Sure, you can apply this either to the upload or download, the logic is the same.
 
Upvote 0
Top