Click here to Skip to main content
15,884,176 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 5: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.

VB
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
 
Share this answer
 
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 :)

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