Solved

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

Posted on 2006-07-17
4
192 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 142

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 142

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now