Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

803 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