Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-17
4
Medium Priority
?
226 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 1500 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

715 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