rossc
asked on
One instance
Is there a way to ensure that only one instance of my VB6 application is running on a computer at one time? Or, is there a way to lock a database so that only one application can read or write to it at one time?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
..and that is what is in my code mark2150
You do it in a function call and a dozen lines of code. I do it in one line.
Which is clearer in intent?
Which is less compiled bytes?
Which is faster to execute?
Which has fewer lines to debug?
Which took less time (read cost) to code?
Professional coding is price driven. I'm not going to pay one of my team to write like that when the one line version is simpler and clearer.
Had a guy write something like this:
TempTxt = Textbox.Text
If Len(Trim(TempTxt)) = 0 Then
Str1 = Str1 & " This is a prompt: " & Trim(TempText) & VbCrLf
Else
Str1 = Str1 & " This is a prompt: " & VbCrLf
End If
Now if you look at that you'll find it'll simplify to:
Str1 = Str1 & " This is a prompt: " & Trim(TextBox.Text) & VbCrLf
Five fewer lines, one less working variable faster execution, much clearer intent. Need I say that this person is no longer working for us...
M
Which is clearer in intent?
Which is less compiled bytes?
Which is faster to execute?
Which has fewer lines to debug?
Which took less time (read cost) to code?
Professional coding is price driven. I'm not going to pay one of my team to write like that when the one line version is simpler and clearer.
Had a guy write something like this:
TempTxt = Textbox.Text
If Len(Trim(TempTxt)) = 0 Then
Str1 = Str1 & " This is a prompt: " & Trim(TempText) & VbCrLf
Else
Str1 = Str1 & " This is a prompt: " & VbCrLf
End If
Now if you look at that you'll find it'll simplify to:
Str1 = Str1 & " This is a prompt: " & Trim(TextBox.Text) & VbCrLf
Five fewer lines, one less working variable faster execution, much clearer intent. Need I say that this person is no longer working for us...
M
so mark2150, no validation, no activeating pervious instance, yeah, that is good.
Depends on if you want that or no. Certainly there are times that is good and wanted, but Q wasn't how to bring up alternate, but how to prevent any additional copies from running.
Your change to titlebar will be followed almost instantly by END so user will *NEVER SEE IT*. Ergo: What is point?
Activating alternate may or may not work as you pointed out yourself!
Finally, what is point of coding function call that is only going to be used *once*? Good programming practice says that "single call" functions or subs should be *inlined* for speed and clarity.
M
Your change to titlebar will be followed almost instantly by END so user will *NEVER SEE IT*. Ergo: What is point?
Activating alternate may or may not work as you pointed out yourself!
Finally, what is point of coding function call that is only going to be used *once*? Good programming practice says that "single call" functions or subs should be *inlined* for speed and clarity.
M
ASKER
Thanks for the help.
If App.PrevInstance then END
M