Solved

reading info from an ini file the loops don't run correctly any ideas why

Posted on 2006-07-17
4
209 Views
Last Modified: 2010-04-30
Hi

I am running some code to prevent no more than two instances of my exe file opening at any one time. I have two values in a text file.
If one version is opened I read the values if they are 0 and 0 it loads, changes the values in the text file to 1 and 0.
if a second opens it looks for 1 and 0 and loads, changes the values to 1 and 1
if a third is opened it sees the 1 and 1 and doesn't load.
That's the idea. However I am using the following but it only sees and changes the first sections

Dim inst1 As String
Dim inst2 As String
Dim val1 As String
Dim val2 As String
Dim instance As Integer

'set both instances to 0 at load

buffer = String$(260, Chr$(13))
Call GetPrivateProfileString("instances", "inst1", vbNullString, buffer, Len(buffer), file)
DataString = StripChr(buffer)
inst1 = buffer 'buffer contains the text from the ini file
val1 = inst1
MsgBox val1

buffer = String$(260, Chr$(13))
Call GetPrivateProfileString("instances", "inst2", vbNullString, buffer, Len(buffer), file)
DataString = StripChr(buffer)
inst2 = buffer 'buffer contains the text from the ini file
val2 = inst2
MsgBox val2


'End  'end if two instances are already running

    If val1 = 0 And val2 = 0 Then MsgBox "one version"
     val1 = 1
     val2 = 0
    instance = 1 'assign instance value 1 for this instance of application
    Call WritePrivateProfileString("instances", "inst1", val1, file)
    Call WritePrivateProfileString("instances", "inst2", val2, file)
   
ElseIf val1 = 1 And val2 = 0 Then MsgBox "two versions"

 val1 = 1
 val2 = 1
    instance = 2 'assign instance value 2 for this instance of application
    Call WritePrivateProfileString("instances", "inst1", val1, file)
    Call WritePrivateProfileString("instances", "inst2", val2, file)
   

ElseIf val1 = 1 And val2 = 1 Then End

    End If

even when the values are 1 and 0 (i check using the msg boxes and delete them later) it ignors it , loads the form and doesn't change any text files. I 've changes the configurations and am now getting frustrated.

Any ideas greatly appreciated.
0
Comment
Question by:eneate
  • 2
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17124004
instead of using .ini file, use the mutex concept:
http://www.osix.net/modules/article/?id=6

so in your application, check 2 mutex values, if both are created, don't allow the application to be started,
if only 1 or none are present, create the other one and let the application start.
0
 

Author Comment

by:eneate
ID: 17124142
That looks interested, but in this application I have an exe file that runs ontop of another application almost as an additionAL form. I need to be able to load two copies of the form, but if the user tries to load three, the software just uses end to stops a further load. These commands being in the load function of the form.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17124215
so where is the issue about using mutex instead of ini file?
0
 

Author Comment

by:eneate
ID: 17124384
Thanks for the feedback, I've found a way to get it working with the ini file - always find the answer after posting a question!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question