| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3127 人关注过本帖
标题:新手求助,麻烦大神帮帮看看怎么改
只看楼主 加入收藏
cury
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-11-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:8 
新手求助,麻烦大神帮帮看看怎么改
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
本人刚刚接触vb编程,跟着老师的范例搭过几个程序,对语法完全不熟悉。昨天照着老师给的范例,搭了这个界面,但是我现在不想要主程序界面,只要smarthome界面,我把mainform删掉后,报错了,
图片附件: 游客没有浏览图片的权限,请 登录注册
。麻烦大神帮我看看,怎么修改。
2016-11-04 09:36
cury
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-11-4
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
程序代码:
Public Class Form1
    Dim RXD$
    Dim Temp_val
    Dim LS_val
    Dim auto_temp_crt = 0
    Dim settemp
    Dim auto_ls_crt = 0
    Dim setls


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "客厅_开灯" Then
            ActionMess.Text = "开启客厅灯"
            PictureBox2.Image = My.Resources.客厅开灯
            Button1.Text = "客厅_关灯"
            If SerialPort1.IsOpen Then
                SendCom("S1")
            End If
        Else
            PictureBox2.Image = My.Resources.客厅关灯
            ActionMess.Text = "关闭客厅灯"
            Button1.Text = "客厅_开灯"
            If SerialPort1.IsOpen Then
                SendCom("S2")
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button2.Text = "风扇_开启" Then
            ActionMess.Text = "开启风扇"
            PictureBox3.Image = My.Resources.风扇转
            Button2.Text = "风扇_关闭"
            SendCom("S3")

        Else
            ActionMess.Text = "关闭风扇"
            PictureBox3.Image = My.Resources.风扇停
            Button2.Text = "风扇_开启"
            SendCom("S4")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button3.Text = "台灯_开启" Then
            ActionMess.Text = "开启台灯"
            PictureBox3.Image = My.Resources.台灯亮
            Button3.Text = "台灯_关闭"
            SendCom("S5")
        Else
            ActionMess.Text = "关闭台灯"
            PictureBox3.Image = My.Resources.台灯灭
            Button3.Text = "台灯_开启"
            SendCom("S6")
        End If
    End Sub



    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button4.Text = "电视_开启" Then
            ActionMess.Text = "开启电视"
            PictureBox6.Image = My.Resources.电视开
            SendCom("S7")
            Button4.Text = "电视_关闭"
        Else
            ActionMess.Text = "关闭电视"
            PictureBox6.Image = My.Resources.电视关
            Button4.Text = "电视_开启"
            SendCom("S8")
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button5.Text = "音响_开启" Then
            ActionMess.Text = "开启音响"
            PictureBox5.Image = My.Resources.音响响
            Button5.Text = "音响_关闭"
            SendCom("S9")
        Else
            ActionMess.Text = "关闭音响"
            PictureBox5.Image = My.Resources.音响停
            Button5.Text = "音响_开启"
            SendCom("SA")
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button6.Text = "保全_启动" Then
            ActionMess.Text = "保全启动中"
            PictureBox10.Image = My.Resources.警报停
            PictureBox10.Visible = True
            Button6.Text = "保全_关闭"
        Else
            ActionMess.Text = "保全已解除"
            PictureBox10.Visible = False
            Button6.Text = "保全_启动"
        End If
    End Sub

    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click

    End Sub

    Private Sub SplitContainer1_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button6.Text = "保全_关闭" Then
            PictureBox10.Image = My.Resources.警报响
            SendCom("SB")
        Else
            PictureBox10.Image = My.Resources.警报停
            SendCom("SC")
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        RXD$ = SerialPort1.ReadExisting()
        Dim DataID
        If RXD$ <> "" Then
            Label5.Text = RXD$
            DataID = Mid(RXD, 1, 1)
            Select Case DataID
                Case "T"
                    Temp_val = Mid(RXD, 2, 5)
                    lb_Temp.Text = Temp_val
                Case "L"

                    LS_val = Mid(RXD, 2, 4)
                    lb_LS.Text = LS_val
            End Select
        End If
        If SerialPort1.IsOpen = True Then
            Dim NTCMD = Mid(RXD$, 1, 2)
            Label1.Text = NTCMD

            Select Case NTCMD
                Case "S1"
                    PictureBox2.Image = My.Resources.客厅开灯
                    Button1.Text = "客厅_关灯"
                Case "S2"
                    PictureBox2.Image = My.Resources.客厅关灯
                    Button1.Text = "客厅_开灯"
                Case "S3"
                    PictureBox4.Image = My.Resources.风扇转
                    Button2.Text = "风扇_关闭"
                Case "S4"
                    PictureBox4.Image = My.Resources.风扇停
                    Button2.Text = "风扇_开启"
                Case "S5"
                    PictureBox3.Image = My.Resources.台灯亮
                    Button3.Text = "台灯_关闭"
                Case "S6"
                    PictureBox3.Image = My.Resources.台灯灭
                    Button3.Text = "台灯_开灯"
                Case "S7"
                    PictureBox6.Image = My.Resources.电视开
                    Button4.Text = "电视_关闭"
                    PictureBox6.Visible = True
                Case "S8"
                    PictureBox6.Image = My.Resources.电视关
                    Button4.Text = "电视_开启"
                    PictureBox6.Visible = False
                Case "S9"
                    PictureBox5.Image = My.Resources.音响响
                    Button5.Text = "音响_关闭"
                    PictureBox5.Visible = True
                Case "SA"
                    PictureBox5.Image = My.Resources.音响停
                    Button5.Text = "音响_开启"
                    PictureBox5.Visible = False
                Case "SB"
                    If PictureBox10.Visible = True Then
                        PictureBox10.Image = My.Resources.警报响
                    End If
                Case "SC"
                    If PictureBox10.Visible = True Then
                        PictureBox10.Image = My.Resources.警报停
                    End If
            End Select
            ' get temp
            Label2.Text = lb_Temp.Text
            Dim temp = Val(Mid(Label2.Text, 1, 1)) * 100 + Val(Mid(Label2.Text, 2, 1)) * 10 + Val(Mid(Label2.Text, 4, 1))
            If auto_temp_crt = 1 Then
                If temp > settemp * 10 Then
                    PictureBox4.Image = My.Resources.风扇转
                    Button2.Text = "风扇_关闭"
                    SendCom("0000001")
                Else
                    PictureBox4.Image = My.Resources.风扇停
                    Button2.Text = "风扇_开启"
                    SendCom("0000002")
                End If
            End If
            ' get ls
            Label1.Text = lb_LS.Text
            Dim ls = Val(Mid(Label1.Text, 1, 1)) * 100 + Val(Mid(Label1.Text, 2, 1)) * 10 + Val(Mid(Label1.Text, 3, 1))
            If auto_ls_crt = 1 Then
                If ls < setls Then
                    PictureBox2.Image = My.Resources.客厅开灯
                    Button2.Text = "客厅_开灯"
                    SendCom("0000003")
                Else
                    PictureBox2.Image = My.Resources.客厅关灯
                    Button2.Text = "客厅_关灯"
                    SendCom("0000004")
                End If
            End If
        End If
    End Sub
    Public Sub SendCom(ByVal sendstr)
        If SerialPort1.IsOpen Then
            SerialPort1.Write(sendstr)
        End If

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        SendCom("BS7")
    End Sub

    Private Sub ToolStripLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ToolStripLabel1.Text = "启动温控与光控" Then
            auto_temp_crt = 1
            auto_ls_crt = 1
            ToolStripLabel1.Text = "关闭温控与光控"
        Else
            auto_temp_crt = 0
            auto_ls_crt = 0
            ToolStripLabel1.Text = "启动温控与光控"
        End If
    End Sub

    Private Sub ToolStripLabel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        settemp = InputBox("请输入设定温度" & vbCrLf & "延迟发生时间2秒", "模拟数值", 0)
        Label1.Text = settemp
    End Sub

    Private Sub SmartHome_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        For Each sp As String In (sp)
        Next
    End Sub

    Private Sub StatusStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs)

    End Sub

    Private Sub ToolStripStatusLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripStatusLabel1.Click

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked

    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click

    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub ToolStripLabel3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel3.Click
        setls = InputBox("请输入设定光照度" & vbCrLf & "延迟发生时间2秒", "模拟数值", 0)
        Label1.Text = setls
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click

    End Sub

    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click

    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Try
            SerialPort1.PortName = ComboBox1.Items(ComboBox1.SelectedIndex)
            SerialPort1.Open()
            Timer1.Enabled = True
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click

    End Sub

    Private Sub lb_Temp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lb_Temp.Click

    End Sub

    Private Function ActionMess() As Object
        Throw New NotImplementedException
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

现在被我删除了主界面,只剩下smarthome,运行不了了,
2016-11-04 11:46
gowine
Rank: 2
等 级:论坛游民
帖 子:39
专家分:95
注 册:2016-4-10
收藏
得分:10 
主界面删掉了,那也就附属的对象也一起删掉了吧,还怎么运行呢。。。。
2016-11-04 16:13
cury
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-11-4
收藏
得分:0 
以下是引用gowine在2016-11-4 16:13:34的发言:

主界面删掉了,那也就附属的对象也一起删掉了吧,还怎么运行呢。。。。

我把主界面部分内容做到smarthome里了
2016-11-04 20:47
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:10 
楼主给的信息量太少,帮不到你。
你尝试将启动窗体设为Form1
或者将出错的代码行改为me.mainform=试试。(IoT_DeMo_PlatForm,从图片上看应当是你的项目名称)

图片附件: 游客没有浏览图片的权限,请 登录注册

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-11-05 09:58
cury
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-11-4
收藏
得分:0 
以下是引用不说也罢在2016-11-5 09:58:22的发言:

楼主给的信息量太少,帮不到你。
你尝试将启动窗体设为Form1
或者将出错的代码行改为me.mainform=试试。(IoT_DeMo_PlatForm,从图片上看应当是你的项目名称)

我可以把程序发您看看吗?
IOT_DEMO_SmartHome.rar (8.38 MB)
2016-11-06 01:19
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
答案与我在5楼回复的一样。
图片附件: 游客没有浏览图片的权限,请 登录注册


图片附件: 游客没有浏览图片的权限,请 登录注册

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-11-06 14:48
cury
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-11-4
收藏
得分:0 
以下是引用不说也罢在2016-11-6 14:48:05的发言:

答案与我在5楼回复的一样。

改了,还是出错嘛
2016-11-06 19:11
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
这是项目的压缩包。注意哦,只是解决你的项目不能正常运行的问题。里面的各按钮的功能都未改动,还是你原来的。

WindowsApplication2.rar (9.77 MB)

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2016-11-07 10:10
快速回复:新手求助,麻烦大神帮帮看看怎么改
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.081002 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved