如果有条件的话 [英] If conditional Problem

查看:117
本文介绍了如果有条件的话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在做一个if条件检查一个名为run的设置,如果它为true,则显示它,如果为false则显示该窗体,结束该程序并显示一个msgbox,但它显示msgbox并显示该窗体.谁能告诉我我的代码有什么问题

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



在Advance中致谢



Thanks in Advance

推荐答案

假设您已将设置运行添加为布尔变量.正确或错误不应用引号引起来.

在布尔测试中,您不需要ElseIf:第二个条件,它可以是true或false.

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


这篇关于如果有条件的话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆