Getting value from other other application in runtime

Rioven

Active Member
Licensed User
Longtime User
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.

B4X:
Sub Button1_click

Shell("section.exe")

            FileOpen (c1,AppPath&"\SectionSelected.text",cRead)
           lbsection.Text= FileRead (c1)
   FileClose(c1)
                  
End Sub


What is the right way?... or effective solutions?:sign0085:


Thanks,
Rioven
 

Cableguy

Expert
Licensed User
Longtime User
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...

B4X:
Sub Button1_click

Shell("section.exe")
[COLOR="Red"]Do While FileExist ("myFile.txt") =  False
DoEvents
Loop[/COLOR]
[COLOR="Green"]'This waits for the file to be present before trying to open it[/COLOR]

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)...
 
Last edited:

Rioven

Active Member
Licensed User
Longtime User
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!
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Rioven,

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
 

Rioven

Active Member
Licensed User
Longtime User
Hi Randomcoder,

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 :sign0163:

while waiting... I'll also think of other workaround or strategies on my codes.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
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 :sign0163:

Regards,
RandomCoder
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Erel has in many ways reiterated my previous statement...
I'm not for delays myself, but sometimes its the simplest solution.

We should not overlook the simple way of doing things, instead of striving to over complicate the problem.

Regards,
RandomCoder
 

Rioven

Active Member
Licensed User
Longtime User
Thanks guys for your input.

I've tried the following code,
I created a dummy control 'tb001' to trigger the file reading...

Now it works...No overlaps or error on file reading. Is this code OK??

B4X:
Sub Section_click
Shell("sectionProperty1.exe")
tb001.Focus
End Sub

Sub tb001_GotFocus
           FileOpen (c1,AppPath&"\"&"SectionFileSelected.txt",cRead)
           lbsection.Text= FileRead (c1)
     FileClose(c1)
End Sub
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Looks good to me, nice work around ;)

Regards,
RandomCoder
 

Rioven

Active Member
Licensed User
Longtime User
My main program form waits for the shelled application form to close before enabled the focus. It is ok on desktop, I'll try on my device.

I've posted a sample code, but actually...

I have a main application that launches and process data from several other applications... only if user need it.These separate programs have similar basic structure in keeping, editing files with their individual functions.

If I combine them together in one application, it will be to long, so many repetitions and variables, and will be confusing to me. That is why I applied these kind of structure...

I need advice from you guys on my application structure's effeciency on device. Appreciate any suggestions.:sign0163:

Also, I've searched forum but got fragmented results..still can't figure out how to install several applications in one installation process...:sign0085:


Many thanks.
 

Cableguy

Expert
Licensed User
Longtime User
The best way to achieve a simple multi installation file is to create an exe file to "batch" all other installations,but be carefull with timming..
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Also, I've searched forum but got fragmented results..still can't figure out how to install several applications in one installation process...:sign0085:

This sounds like the perfect topic for the next tutorial. I'd certainly be interested in learning how to do this, so far I haven't compiled any of my programs - I'm just content being able to create them run them through B4PPC.

Regards,
RandomCoder
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'd be happy having a tutorial that demonstrated how to compile just one program with a couple of dll's and a single icon.
This might not be what Rioven had in mind but its a good starting point - just because I'm a B4PPC Veteran it doesn't mean that I can't still be a bit of a noobie at times :D

Regards,
RandomCoder
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can't merge the dll files into the compiled file, but using the SetupBuilder you can create a single setup file which will install your application on the device (from the desktop), create a shortcut icon on the Program section and add your programs to the Remove Programs list.
See this thread: http://www.b4x.com/forum/showthread.php?t=37
 

Rioven

Active Member
Licensed User
Longtime User
Do you need to create a shortcut icon for each program?
Hi Erel,
Just the main program to have a shortcut icon, other executable files are to be kept at the same folder only and maybe no installations setup required.

When I used the setupbuilder, all exe-files was installed.
What should be the solution?
 

Rioven

Active Member
Licensed User
Longtime User
Is that it?
that's simple...:sign0060:

Thank you!
 

Rioven

Active Member
Licensed User
Longtime User
My application was installed to my device and working well with other exe files.:D

Thanks,

P.S.
I don't know why my EULA.txt and Readme.txt in the same directory with my compiled application cannot find by SetupBuilder? But if I put these 2 text files to other folder then it works.:confused:
 
Top