|
-
Nov 17th, 2011, 07:15 PM
#1
Thread Starter
New Member
[RESOLVED] Problem with MsgBoxStyle.YesNo
Hello all,
I've problem with this code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
If Not File.Exists("C:\Windows\System32\dsquery.exe") Then
MsgBox("Do you want install Remote Server Administration Tools?", MsgBoxStyle.Question + MsgBoxStyle.YesNo)
ElseIf MsgBoxResult.Yes Then
System.Diagnostics.Process.Start("http://http://www.microsoft.com/download/en/details.aspx?id=7887")
ElseIf MsgBoxResult.No Then
Exit Sub
End If
The problem is:
I want to if the user doesn't install RSAT or package dsquery.exe Clicking on the message to him referring to the page url and if it clicks in MsgBox not to stop loading the form.
I'm sorry but I am a beginner.
Thanks for the advice
-
Nov 17th, 2011, 07:32 PM
#2
Re: Problem with MsgBoxStyle.YesNo
You are displaying a message box but you are not actually getting the user's response. In pseudo-code, here is what you are currently doing:
Code:
If file does not exist
Display message
Otherwise if MsgBoxResult.Yes is true
Start new process
Otherwise if MsgBoxResult.No is true
Exit sub
Now, how can either MsgBoxResult.Yes or MsgBoxResult.No ever be true? neither of them is a Boolean. What you should be doing is displaying the message if the file doesn't exist and retianing the result, then testing that result to determine whether it is Yes or No:
Code:
If file does not exist
Display message
If user response is MsgBoxResult.Yes
Start new process
Otherwise
Exit sub
Also, you really should be using MessageBox.Show rather than MsgBox.
-
Nov 17th, 2011, 07:46 PM
#3
Thread Starter
New Member
Re: Problem with MsgBoxStyle.YesNo
 Originally Posted by jmcilhinney
You are displaying a message box but you are not actually getting the user's response. In pseudo-code, here is what you are currently doing:
Code:
If file does not exist
Display message
Otherwise if MsgBoxResult.Yes is true
Start new process
Otherwise if MsgBoxResult.No is true
Exit sub
Now, how can either MsgBoxResult.Yes or MsgBoxResult.No ever be true? neither of them is a Boolean. What you should be doing is displaying the message if the file doesn't exist and retianing the result, then testing that result to determine whether it is Yes or No:
Code:
If file does not exist
Display message
If user response is MsgBoxResult.Yes
Start new process
Otherwise
Exit sub
Also, you really should be using MessageBox.Show rather than MsgBox.
Thank you for your quick reply. The structure should look like this:
If the file does not exist -> MsgBox with buttons yes or no. If the user selects Yes -> open url. If the user chooses no -> stop loading the form.
-
Nov 17th, 2011, 07:51 PM
#4
Re: Problem with MsgBoxStyle.YesNo
That's exactly what I said, so now you just have to write code to do that. Remember, MsgBox (and MessageBox.Show too) is just a function, like any other. How would you usually get the value returned by a function and check its value? Here's a hint: you're already doing it with File.Exists.
-
Nov 17th, 2011, 08:06 PM
#5
Member
Re: Problem with MsgBoxStyle.YesNo
which part not stop loading?
if msgbox=yes, the proccess will bring you to the website,
the form will still load
if msgbox=no
exit sub, (means exit the form)
is your qusetion means, when you choose no, the form still loading.
if that is your question
try to use
me.close <<< to close the form when you want to
-
Nov 17th, 2011, 08:23 PM
#6
Re: Problem with MsgBoxStyle.YesNo
Actually what he should be doing is use the Application Startup event and if the file exists or the user selects "no" from the MessageBox.Show() then load the form. If they select "yes" From the MessageBox.Show() then Process.Start() the URL and don't load the form.
If you call 'Me.Close()' in the app's main load form, that's a huge indication you should probably use the Startup event and not have the program load most of the form just to cancel loading it.
-
Nov 17th, 2011, 08:48 PM
#7
Re: Problem with MsgBoxStyle.YesNo
Ah, I didn't pick up the bit about not loading the form. Even re-reading the post it's not too clear, which is presumably a language issue. If you're not a native English speaker then all is forgiven. If you are a native English speaker then you should work on posting a bit more clearly.
Anyway, what I posted before still stands as far as the structure of the code goes. JB is correct that the code should go in the Startup event handler of the application if you may want to not actually display the main form. You can access application events from the Application page of the project properties. To have the application exit without ever creating and displaying the main form, set e.Cancel to True.
-
Nov 17th, 2011, 10:40 PM
#8
Lively Member
Re: Problem with MsgBoxStyle.YesNo
is this what you mean?
Code:
If filedoesntexit() Then
If msgbox("your text here that you will display on the message box", msgboxstyle.question + msgboxstyle.yesno).show() = windows.forms.dialogresult.Yes Then
'your code here when the user clicks yes
else
'your code here for when the user clicks no
end if
End If
-
Nov 18th, 2011, 06:05 AM
#9
Thread Starter
New Member
Re: Problem with MsgBoxStyle.YesNo
 Originally Posted by jmcilhinney
Ah, I didn't pick up the bit about not loading the form. Even re-reading the post it's not too clear, which is presumably a language issue. If you're not a native English speaker then all is forgiven. If you are a native English speaker then you should work on posting a bit more clearly.
Anyway, what I posted before still stands as far as the structure of the code goes. JB is correct that the code should go in the Startup event handler of the application if you may want to not actually display the main form. You can access application events from the Application page of the project properties. To have the application exit without ever creating and displaying the main form, set e.Cancel to True.
O sorry I'm not native speaker .
Once more:
I want to verify when loading applications if exist file in %SystemRoot%\Dsquery.exe . After If file not found, will be loaded msgbox with following message: "Do you want install RSAT?". If user clicks on yes, then open web page e.g. www.google.cz. If user clicks no , then stop loading aplication. Do you understand me?
Regards
V.
-
Nov 18th, 2011, 06:44 AM
#10
Thread Starter
New Member
Re: Problem with MsgBoxStyle.YesNo
 Originally Posted by rqmok
is this what you mean?
Code:
If filedoesntexit() Then
If msgbox("your text here that you will display on the message box", msgboxstyle.question + msgboxstyle.yesno).show() = windows.forms.dialogresult.Yes Then
'your code here when the user clicks yes
else
'your code here for when the user clicks no
end if
End If
Yes yes yes. U're great. It works! Thx very much
-
Nov 18th, 2011, 05:36 PM
#11
Lively Member
Re: [RESOLVED] Problem with MsgBoxStyle.YesNo
You know you're the first one I helped out!
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
|