要实现这样的功能!空调控制室内温度,如果设定温度为26度,设一个初始温度,比如29度,空调开始运行,当室内温度低于设定温度1度时,即25度,空调关机,然后室内温度开始上升,当室内温度高于设定温度1度时,即27度,空调再次开启,当温度再次低于设定温度一度,即25度时,空调关机,当再高于27度时,空调开机,开关机状态依次循环。这里有个问题,如果按照温度范围来写代码时,初始时的温度29与25-27度温度段内有冲突,现在主要弄不明白开机(温度29度时)时的代码怎么写能不受后面代码的影响。这个代码应该怎么写啊?

解决方案 »

  1.   

    没有什么矛盾,事实上初始条件29度,是一个无用的数据select case  Temp
    case is >27 
      空调=on
    case is<25 
      空调=off
    end select
      

  2.   

    Private Sub Command11_Click()
        Do While Not Adodc6.Recordset.EOF
            j = 2 + 60 * n
            Do Until i = j
            Select Case Text29.text
                Case Is > (Val(Combo6.text) + Val(Text90.text)) 'temp>27
                    Text93.text = 2600
                    Text94.text = 850
                        newsheet.Cells(i, 1).Value = Text97.text
                        newsheet.Cells(i, 2).Value = Text53.text
                        newsheet.Cells(i, 3).Value = Text28.text
                        newsheet.Cells(i, 4).Value = Text29.text
                        newsheet.Cells(i, 5).Value = Text26.text
                        newsheet.Cells(i, 6).Value = Text93.text
                        newsheet.Cells(i, 7).Value = Text94.text
                        newsheet.Cells(i, 8).Value = Text98.text
                        newsheet.Cells(i, 9).Value = Text99.text
                        newsheet.Cells(i, 10).Value = Text100.text
                    Text29.text = Val(Text29.text) - (Val(Text93.text) - Val(Text26.text)) * 60 / (Text1(0).text * Text1(1).text * Text1(2).text * 1.2 * 1000 + 200000)
                    Text98.text = Val(Text93.text) / 60000 + Val(Text98.text)
                    Text99.text = Val(Text94.text) / 60000 + Val(Text99.text)
                    Text100.text = Val(Text98.text) / Val(Text99.text)
                i = i + 1
                Case Is < (Val(Combo6.text) - Val(Text90.text)) 'temp<25
                Text93.text = 0
                Text94.text = 0
                    newsheet.Cells(i, 1).Value = Text97.text
                    newsheet.Cells(i, 2).Value = Text53.text
                    newsheet.Cells(i, 3).Value = Text28.text
                    newsheet.Cells(i, 4).Value = Text29.text
                    newsheet.Cells(i, 5).Value = Text26.text
                    newsheet.Cells(i, 6).Value = Text93.text
                    newsheet.Cells(i, 7).Value = Text94.text
                    newsheet.Cells(i, 8).Value = Text98.text
                    newsheet.Cells(i, 9).Value = Text99.text
                    newsheet.Cells(i, 10).Value = Text100.text
                Text29.text = Val(Text29.text) - (Val(Text93.text) - Val(Text26.text)) * 60 / (Text1(0).text * Text1(1).text * Text1(2).text * 1.2 * 1000 + 200000)
                Text98.text = Val(Text93.text) / 60000 + Val(Text98.text)
                Text99.text = Val(Text94.text) / 60000 + Val(Text99.text)
                Text100.text = Val(Text98.text) / Val(Text99.text)
            i = i + 1
            End Select
            Loop
            n = n + 1
            Text102.text = Text53.text
            Adodc6.Recordset.MoveNext
        Loop
        MsgBox "计算结束,请点击 计算数据读取 来查看结果"
    End Sub这个循环还是执行不了啊??