|
-
May 14th, 2008, 03:23 PM
#1
Thread Starter
New Member
[2005] Do "x" only at first runtime
Hello,
I'm making a program and I want to x code to be executed only at the first runtime. How could i make this? I have no idea what code it could be, but you could se how I mean with this code:
HTML Code:
Private Sub TestIfFirstRun
If App.FirstRun Then ' App.x is from vb6 but its just an example
MsgBox("First Run")
Else
GoTo start
End If
start:
MsgBox("Start")
End Sub
If anybody knows if it's any API or function for this please reply!
-
May 14th, 2008, 03:27 PM
#2
Re: [2005] Do "x" only at first runtime
Go into your project properties (Project menu, the option at the very bottom), then click the Settings tab.
Here you can create settings for your application. Create a setting of type boolean, set its value to True, and give it a good name...say "FirstExecution".
Here's the code you'll need now:
VB.NET Code:
If My.Settings.FirstExecution Then
'Do whatever you want.
My.Settings.FirstExecution = False
End If
This can be done in many ways, so this is just one of many.
-
May 14th, 2008, 03:30 PM
#3
Re: [2005] Do "x" only at first runtime
Go into the Settings tab of the MyProject page and add a variable there with a scope of User. Call it "FirstRun" or something and make it a Boolean.
Then in your code:
Code:
Private Sub TestIfFirstRun
If My.Settings.FirstRun = False Then
MsgBox("First Run")
My.Settings.FirstRun = True
My.Settings.Save
Else
GoTo start
End If
start:
MsgBox("Start")
End Sub
Oi! Atheist beat me to posting a solution again.
(VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.
-
May 14th, 2008, 03:32 PM
#4
Re: [2005] Do "x" only at first runtime
i don't recall, but if my.settings is saved automagically, then you need to set it to true. of course the boolean could just be dim'ed
Dim OneTime as Boolean = True
If OneTime then
onetime = false
'one time code here
end if
-
May 14th, 2008, 03:40 PM
#5
Thread Starter
New Member
Re: [2005] Do "x" only at first runtime
Thank you, it worked!
OT: When I copy VB code from the VB code box you put, I get all the numbers of the lines like
1.
2.
3.
4.
5.
Can i do anything about this, because if I copy like 70 lines it's very annoying!
-
May 14th, 2008, 03:51 PM
#6
Re: [2005] Do "x" only at first runtime
You could use our code as a suggestion of what to do and then write it yourself. That would solve the problem.
(VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.
-
May 14th, 2008, 04:35 PM
#7
Re: [2005] Do "x" only at first runtime
i totally misunderstood. i thought it was code to run once each time the app was run, not just run one time.
i gotta ask, what are you trying to do just once? i ask because maybe my.settings isn't right, but without knowing the WHAT it is hard to know.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|