Getting value from other other application in runtime
Hi,
I've made the following event that launch 'section.exe' to generate a value, but before I get the value, it process right away the 'fileOpen' after the shell command. With this, I could not get the right value.
From the looks of your code section.exe generates a txt file named "SectionSelected.text", and you are having trouble getting the data because the section.exe is taking more time to create the file...
If so you can use FileExist to check if the txt file already exist...
Code:
Sub Button1_click
Shell("section.exe") <font color="Red">DoWhile FileExist ("myFile.txt") = False DoEvents Loop</font> <font color="Green">'This waits for the file to be present before trying to open it</font> FileOpen (c1,AppPath&"\SectionSelected.text",cRead) lbsection.Text= FileRead (c1) FileClose(c1)
End Sub
I would also suggest you made sure that the file is after deleted so that the next time the sub is runned the file is NOT there, or you will load the wrong file (outdated)...
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)
My Posts helped you? Consider Buying me a Porto Glass!
Hi Cableguy, you got my point , I will try it...and again I've learned new things in a quick way. As a beginner and a limitted time (you can also say lazy ), I'm so greatful that members of this forum are very helpful. Thanks again Cableguy!
__________________
Rioven
DEVICE: Motorola ATRIX (Dual Core) Android 2.2.1
DESKTOP: Intel Pentium Dual-core E5200; Microsoft® Windows® Vista Home (Basic); Hard Disk:320GB; Memory:4096MB
You might also want to try using Sleep(2000), to wait for 2 seconds, instead of the Do While loop or alternatively add a count or timer in the loop so that your program doesn't hang if the file does not get created. You could then display a message to the user letting them know that there was a problem creating the file.
Regard,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Thanks. yes. I thought a small delay is needed on cableguy's solution, because when file is created quickly, the DoEvents fires right away before the 'SectionSelected.text' file closes by section.exe and it causes an error because on the event it tries to open a file which is not yet close.
I'm not really for delays....
You may have other suggestions? or
while waiting... I'll also think of other workaround or strategies on my codes.
__________________
Rioven
DEVICE: Motorola ATRIX (Dual Core) Android 2.2.1
DESKTOP: Intel Pentium Dual-core E5200; Microsoft® Windows® Vista Home (Basic); Hard Disk:320GB; Memory:4096MB
I'm not for delays myself, but sometimes its the simplest solution.
Another option would be to catch the error and use a label to go back to trying to open the file. You could count how many times the program loops round and possibly throw up an error message if after say 6 attempts it still hasn't opened.
There is probably other alternatives too
Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Catching the errors here is not a good solution as there could be many many errors raised in that way.
I think that waiting using a sleep method should do the job. Maybe you should also check the FileSize so you want read an empty or incomplete file.
Two applications could also communicate using the Network library and ip 127.0.0.1 but it will also require a Timer to wait for the data and it is much more complicated.