Click here to Skip to main content
14,698,806 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
hello everyone
i am doing an if conditional to check a setting called run if it's true so show the form if it's false end the program and show a msgbox but it shows the msgbox and show the form. Can anyone tell me what's wrong with my code
If My.Settings.run = "False" Then
        MsgBox("CAN'T RUN")
        End
    ElseIf My.Settings.run = "True" Then

        'When the form loads
        'Enumerate available Com ports and add to ComboBox1
        comPorts = IO.Ports.SerialPort.GetPortNames()
        For i = 0 To UBound(comPorts)
            ComboBox1.Items.Add(comPorts(i))
        Next
        'Set ComboBox1 text to first available port
        ComboBox1.Text = ComboBox1.Items.Item(0)
        'Set SerialPort1 portname to first available port
        SerialPort1.PortName = ComboBox1.Text
        'Set remaining port attributes
        SerialPort1.BaudRate = 19200
        SerialPort1.Parity = IO.Ports.Parity.None
        SerialPort1.StopBits = IO.Ports.StopBits.One
        SerialPort1.DataBits = 8

    End If
End Sub


Thanks in Advance
Posted
Updated 11-Jul-11 6:55am
v2

1 solution

Assuming you have added the setting run as a boolean varaible. True or false should not be in quotes.

You do not need the ElseIf: second conditional on a boolean test, it's either true or false.

If My.Settings.run = False  Then
    MsgBox("Can't Run")

Else
    'Run your code

End If


You might consider using a phrase other than "Can't Run" in your message box. It sounds unprofessional. You may consider something along the lines of “Unable to perform that action” or something more descriptive of what they are unable to do with a description of what they need to do in order to have the application run.

Regards
   
Comments
Seif Hatem 11-Jul-11 12:28pm
   
Same error, PLease Help
<pre><pre lang="vb">If My.Settings.run = False Then
MsgBox("The lisscence has ended")
Else
'When the form loads
'Enumerate available Com ports and add to ComboBox1
comPorts = IO.Ports.SerialPort.GetPortNames()
For i = 0 To UBound(comPorts)
ComboBox1.Items.Add(comPorts(i))
Next
'Set ComboBox1 text to first available port
ComboBox1.Text = ComboBox1.Items.Item(0)
'Set SerialPort1 portname to first available port
SerialPort1.PortName = ComboBox1.Text
'Set remaining port attributes
SerialPort1.BaudRate = 19200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.DataBits = 8
End If</pre>
</pre>
S Houghtelin 11-Jul-11 12:31pm
   
Is the varaible a boolean variable?How is variable "run" declared? like this?

Dim run as Boolean
Seif Hatem 11-Jul-11 12:32pm
   
I fixed it by adding "End"
but now it gives me error wether it's true or false
Seif Hatem 11-Jul-11 12:35pm
   
I fixed it by adding My.settings.save()
Seif Hatem 11-Jul-11 12:36pm
   
Thanks for your help :)
S Houghtelin 11-Jul-11 12:37pm
   
Thank you, if you found this to be helpful, please mark the answer as solved.
Tarun.K.S 11-Jul-11 13:41pm
   
Good answer. 5+
S Houghtelin 11-Jul-11 13:49pm
   
Appreciated, thanks. :)

BTW, like your blog, good read. Especially the top article for saving forms settings. The Load and Save event section are relavant to the question.
Sergey Alexandrovich Kryukov 11-Jul-11 16:24pm
   
My 5, especially for patience :-)
--SA
Tarun.K.S 11-Jul-11 16:44pm
   
Thank you very much, glad you liked my blog and the article. :)
It's always great to get appreciation from top-class experienced developers like you. :)
S Houghtelin 11-Jul-11 19:02pm
   
I don't know if I would catagorize my self as top class, but thank you for your kind words. :) One could say the same for you.

Have you considered submitting some of your articles here on CP? I think you have a good writing style. The code is easy to follow and understandable.
Tarun.K.S 12-Jul-11 3:42am
   
Actually I thought my articles won´t be accepted well, so I was a bit scared posting it here.
But after reading your comments, I think I should go ahead write some! Thank you for very much for the encouragement. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900