uc是一个控件名,list1是列表框控件,我使用下面的代码时程序运行没有问题。Private Sub uc_Paint()
    uc.Interval = List1.Text
End Sub但是,向Interval赋值时uc控件好象会处理一些东西,而Paint事件又时常发生,所以我只想在Interval属性与新值不同时才向其赋值,于是我改成这样:Private Sub uc_Paint()
    If uc.Interval <> List1.Text Then
        uc.Interval = List1.Text
    End If
End Sub奇怪的是,程序每运行到If uc.Interval <> List1.Text Then时则报错,说是“属性的使用无效”,我晕!怎么回事啊。

解决方案 »

  1.   

    难道uc的Interval属性是只能写,不能读的?
      

  2.   

    你用MsgBox uc.Interval 测试看有没有错误
      

  3.   

    的确如此,虽然很少有这种情况, 但又确实是存在的,这个Interval属性是只能写的,不可读。
      

  4.   

    Timer控件的Interval属性可读可写啊,而且我就知道timer控件有这个属性,其他的不知道
      

  5.   

    如果是那样,就在写的时候用一个变量保留, 下次写之前取这个变量的值来对比就行了。
    Private Sub uc_Paint()
        static LastInterval
        If LastInterval <> List1.Text Then
            uc.Interval = List1.Text
            LastInterval= List1.Text
        End If
    End Sub
      

  6.   

    你用数值型的INTERVAL和字串型的TEXT比较当然出问题。把TEXT转化为同类型就可以了。
      

  7.   

    可能的原因是List1.Text可能是空字串,这个时候 uc.Interval = "",所以会报错
    前面加个if判断一下就可以了