Solved

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

Posted on 2006-07-17
4
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 15 hours left to enroll

617 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