Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing Data in VB..... 1

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
0
0
GB
This is pretty simple toa nswer I'm sure but...

Is it possible to store the data typed into a text box in the exe so that every time it is started you can view the data? I didn't want to use databases etc.... just store a few lines of text which will be password protected on the front end...

any ideas?

Thanks...
 
If I read your question correctly, you just want to store a little data in the application EXE....

You can do that but modifying the data at a later date is a little tricky under Windows. I started doing this when I required an app that needed unquestionable security for its configuration settings (I didn't want the user to locate and delete or modify a separate data file).

Basically, this requires two copies of the EXE to be present on the system. Prior to packaging your app you must create a small utility to save the initial data to the EXE. This might consist of a few lines of code similar to:[tt]

MyText$ = "Placeholder for my data."
TxtLength& = Len(MyText$)
ff = FreeFile
Open "MyApp.exe" For Binary as #ff
FileLength& = Lof(ff)
Put #ff, FileLength& + 1, MyText$
Put #ff, FileLength& + 1 + TxtLength&, TxtLength&
Close #ff
[/tt]

This just appends MyText$ here to the end of the EXE and then appends a long variable noting the length of MyText$. (You would probably use a user defined Type scructure instead of a string. I just show a string for the sake of simplicity.)

When "MyApp.exe" is executed it checks for the existence of its clone. If, for instance, "MyApp2.exe" does not exist, it performs a [tt]FileCopy "MyApp.exe" "MyApp2.exe"[/tt] (you would probably use [tt]App.Path & "\" & App.ExeName[/tt] to simplify matters).

The next step would be to retrieve the data from "MyApp2.exe":[tt]

ff = FreeFile
Open "MyApp2.exe" For Binary as #ff[/tt]

Get #ff, Lof(ff)-3, TxtLength&
MyText$ = String$(TxtLength&, 0)
Get #ff, Lof(ff) - TxtLength& -1, MyText$
Close #ff[/tt][/b]
'Show the text in the Text box[tt]
Text1.Text = MyText$
[/tt]

If you are only interested in storing fixed data in the executable, there is no need to use a clone of the EXE. Windows doesn't object to reading from the EXE of a running application. It objects strongly when one trys to modify an EXE while it is running. Hence, the clone.

This is where the scheme gets a bit complex. Whenever the data is changed (written to the clone) the main app must shell to the clone, unload and terminate. The clone must wait for the main app to terminate (or force a termination with SendMessage) and then overwrite it with the updated EXE.

All of the above fall under the heading of "Extreme Measures" and don't apply to most situations. The simple way to do this is to write the data to the registry or save it in an INI or data file. I only posted this solution to show a way to save data when normal methods are inadequate. And, although somewaht complex, it actually works. I have a VB app that stores three separate applications appended to the VB EXE (two DOS based EXE's and a COM executable). The VB app extracts and runs them, as needed, and then removes them from the system to maintain security.


VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
Hi,
I have an application running smooth on COM+. There is a Client layer, business layer and data layer. This application is running on Oracle database. There are certain stored procedures which are executed from the application that take around 1-2 hours. So, when this process is running the client application is blocked and there is nothing else the user can do with the application but wait for the process to complete. Currently, we are calling the stored procedure from the data layer. To solve this, we thought of doing the following.
* Create an ActiveX Exe.
* Call the Active Exe from the data layer.
* Call the stored procedure in the ActiveX Exe.
By doing this we thought that the data layer would free up and the control returns back to the application. But rightnow, it is not happening this way. The system still is blocked. Is there anyway that we can solve this using ActiveX exe.
Please help...
Thanks,
Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top