Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed 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: 126
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

O2 Atom life 624MHz, 1GB Internal ROM, WM6(upgraded)
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: 1,092
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")
Do While FileExist ("myFile.txt") =  False
DoEvents
Loop
'This waits for the file to be present before trying to open it

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

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

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

O2 Atom life 624MHz, 1GB Internal ROM, WM6(upgraded)
Reply With Quote
  #4 (permalink)  
Old 09-17-2007, 11:25 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 448
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"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: 126
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

O2 Atom life 624MHz, 1GB Internal ROM, WM6(upgraded)
Reply With Quote
  #6 (permalink)  
Old 09-17-2007, 04:24 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 448
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"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: 2,780
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 Veteran
 
Join Date: May 2007
Location: UK
Posts: 448
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"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: 126
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

O2 Atom life 624MHz, 1GB Internal ROM, WM6(upgraded)
Reply With Quote
  #10 (permalink)  
Old 09-18-2007, 11:16 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 448
Default

Looks good to me, nice work around

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing controls in runtime Stanl3yCZ Questions & Help Needed 1 02-18-2008 02:51 PM
add menu item at runtime? bob Questions & Help Needed 1 11-20-2007 11:05 AM
Runtime controls manipulation Erel Tutorials 0 09-26-2007 01:18 PM
addlabel in runtime tvrman Questions & Help Needed 2 09-04-2007 02:58 PM
Tab Simulation @ Runtime anansath Questions & Help Needed 1 05-19-2007 02:55 PM


All times are GMT. The time now is 09:03 PM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0