Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Getting value from other other application in runtime

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-16-2007, 03:35 PM
Senior Member
 
Join Date: May 2007
Posts: 174
Awards Showcase
Beta Tester 
Total Awards: 1
Default 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.

Code:

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?


Thanks,
Rioven
__________________
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
Reply With Quote
  #2 (permalink)  
Old 09-16-2007, 09:49 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

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">Do While 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!

Last edited by Cableguy : 09-16-2007 at 09:52 PM.
Reply With Quote
  #3 (permalink)  
Old 09-17-2007, 02:38 AM
Senior Member
 
Join Date: May 2007
Posts: 174
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
Reply With Quote
  #4 (permalink)  
Old 09-17-2007, 11:25 AM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #5 (permalink)  
Old 09-17-2007, 02:16 PM
Senior Member
 
Join Date: May 2007
Posts: 174
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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

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
Reply With Quote
  #6 (permalink)  
Old 09-17-2007, 04:24 PM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
Reply With Quote
  #7 (permalink)  
Old 09-17-2007, 05:31 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

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.
Reply With Quote
  #8 (permalink)  
Old 09-17-2007, 05:58 PM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Erel has in many ways reiterated my previous statement...
Quote:
Originally Posted by RandomCoder View Post
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
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #9 (permalink)  
Old 09-18-2007, 02:53 AM
Senior Member
 
Join Date: May 2007
Posts: 174
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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??

Code:
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
__________________
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
Reply With Quote
  #10 (permalink)  
Old 09-18-2007, 11:16 AM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Looks good to me, nice work around

Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Click and drag during runtime J12345T Questions (Windows Mobile) 1 06-24-2008 09:37 AM
add menu item at runtime? bob Questions (Windows Mobile) 1 11-20-2007 11:05 AM
Runtime controls manipulation Erel Tutorials 0 09-26-2007 01:18 PM
addlabel in runtime tvrman Questions (Windows Mobile) 2 09-04-2007 02:58 PM
Tab Simulation @ Runtime anansath Questions (Windows Mobile) 1 05-19-2007 02:55 PM


All times are GMT. The time now is 11:12 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0