I am a long time VBA programmer and used to doing things a certain way. I don't mind change but I want to do it right.
I am using the SMB lib to copy files to a Window network (wonderful - works like a charm) my problem is I can't for the life of me see how to write clean, readable code with it. I feel like I must be missing something obvious. SMB runs in the background and fires an event when it is done. I am used to something like this (Pseudocode):
If anything fails it jumps to the error routine and the rest of the code does not run.
With SMB if I do this:
It will run all of the code, delete my local files without waiting to see if they copied successfully.
I tried putting a DO Doevents WHILE loop (with a timeout of course) after the upload to wait for Upload Completed but UploadCompleted Does not fire as long as the doevents Loop is running.
I could of course do a variable flag and test it in UploadCompleted to see where I am at and act accordingly but this becomes ugly, unreadable code and what happens when you call another Upload from inside the return event for the previous upload?
I feel like I must be missing something obvious here.
I love B4A and I am awed by this developer community! Every one here is amazing. Thank you all and thanks in advance for any help.
Kim
I am using the SMB lib to copy files to a Window network (wonderful - works like a charm) my problem is I can't for the life of me see how to write clean, readable code with it. I feel like I must be missing something obvious. SMB runs in the background and fires an event when it is done. I am used to something like this (Pseudocode):
B4X:
Sub MySubCopyFile
On Error Go To MyErr
CopyFile LocalBlah, Blah
CopyFile LocalBlah2, Blah2
CopyFile LocaBlah3, Blah3
DeleteFile LocaBlah
DeleteFile LocaBlah2
DeleteFile LocaBlah3
Exit Sub
MyErr:
Do Something About The Error
End Sub
If anything fails it jumps to the error routine and the rest of the code does not run.
With SMB if I do this:
B4X:
Sub MySub
UploadFile LocalBlah Blah
UploadFile LocalBlah2 Blah
UploadFile LocalBlah3 Blah
DeleteFile LocalLocaBlah
DeleteFile LocalLocaBlah2
DeleteFile LocalLocaBlah3
End Sub
Sub UploadCompleted Blah
If Failure
Do Something
Else
Do Something Else
End If
End Sub
It will run all of the code, delete my local files without waiting to see if they copied successfully.
I tried putting a DO Doevents WHILE loop (with a timeout of course) after the upload to wait for Upload Completed but UploadCompleted Does not fire as long as the doevents Loop is running.
I could of course do a variable flag and test it in UploadCompleted to see where I am at and act accordingly but this becomes ugly, unreadable code and what happens when you call another Upload from inside the return event for the previous upload?
I feel like I must be missing something obvious here.
I love B4A and I am awed by this developer community! Every one here is amazing. Thank you all and thanks in advance for any help.
Kim
Last edited: