小弟的代码中要使用定时器每隔30秒去数据库取一次数据。但是现在我的定时器居然不工作了!生成窗体以后并没有去数据库取数据,这是怎么回事了?请教各位高手!Timer1.Enabled我已经设置为true了的。代码如下:
Option Explicit
Const CarTool = 1
Dim st As MapXLib.Style
Dim lyrMyLayer As MapXLib.Layer
Dim iVehicleCount As Integer
Dim iCarNum As IntegerDim para As Integer
Private Type Vehicle
  sName As String
  vehType As String
End TypeDim fArray() As Vehicle
Dim cn As ADODB.Connection
Dim rst As Recordset
Dim longitude As Double
Dim latitude As Double
Dim speed As DoubleDim X1 As Double
Dim Y1 As Double
Dim fNewSymbol As MapXLib.Feature
Dim fNewSymbol1 As MapXLib.Feature
Dim fMapSymbol As MapXLib.Feature
Dim pt As New PointDim servName As String
Dim userName As String
Dim userPwd As String
Dim dbName As StringDim flag As Integer
Dim a As Integer
Dim b As IntegerDim condition As String
Dim iCount As Integer
Dim haha As String
Dim hehe As StringPrivate Sub cmdLayerControl_Click(Index As Integer)
Map1.Layers.LayersDlg
End SubPrivate Sub cmdPlotCar_Click(Index As Integer)
Scout.Show vbModal, Me
iVehicleCount = lstCars.ListCount + 1
Print iVehicleCountReDim Preserve fArray(iVehicleCount)
 fArray(iVehicleCount).sName = Scout.carNum.Text
 fArray(iVehicleCount).vehType = Scout.Combo1.TextPrint fArray(iVehicleCount).sName
Print fArray(iVehicleCount).vehTypeUpdateListCarsEnd SubPrivate Sub cmdSetStyle_Click(Index As Integer)
Map1.DefaultStyle.PickSymbol
End SubPrivate Sub cmdZoomIn_Click(Index As Integer)
Map1.CurrentTool = miZoomInTool
End SubPrivate Sub cmdZoomOut_Click(Index As Integer)
Map1.CurrentTool = miZoomOutTool
End SubPrivate Sub exitMenu_Click()
Unload Me
End SubPrivate Sub Form_Load()
Set lyrMyLayer = Map1.Layers.CreateLayer("Cars", , 1)
Set Map1.Layers.AnimationLayer = lyrMyLayer
Map1.CreateCustomTool CarTool, miToolTypePoint, miSelectCursorMap1.Title.TextStyle.TextFont.Size = 24flag = 0Dim fArray(2000)End SubPrivate Sub lstCars_Click()iCarNum = lstCars.ListIndex + 1VehicleName.Enabled = True
VehicleLongitude.Enabled = True
VehicleLatitude.Enabled = True
VehicleSpeed.Enabled = TrueVehicleName = fArray(iCarNum).sName
VehicleSpeed = fArray(iCarNum).sspeed
VehicleLongitude = fArray(iCarNum).slongitude
VehicleLatitude = fArray(iCarNum).slatitudeEnd SubPrivate Sub Map1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then Map1.PropertyPage
End SubPrivate Sub Timer1_Timer()
Print haha
For iCount = 1 To lstCars.ListIndex + 1
Print hehe
condition = fArray(iCount).sName
Debug.Print condition
servName = loginSer.servName.Text
userName = loginSer.userName.Text
userPwd = loginSer.userPwd.Text
dbName = loginSer.dbName.TextSet cn = New ADODB.Connection
cn.ConnectionString = "Driver={SQL Server};Server=" & servName & ";UID=" & userName & ";PWD=" & userPwd & ";Database=" & dbName
cn.Open
Set rst = New ADODB.Recordset
Set rst = cn.Execute("SELECT * FROM GPSInfo Where licence=" & fArray(iCount).sName)
While Not rst.EOF()
longitude = rst!longitude
latitude = rst!latitude
speed = rst!speed
rst.MoveNext
WendPrint longitude
Print latitude
Print speedX1 = longitude
Y1 = latitudept.Set X1, Y1
If fArray(iCount).vehType = "出租车" Then
With Map1.DefaultStyle
.SymbolFont = "custom symbols"
.SymbolType = 1
.SymbolBitmapName = "TAXI1-32.bmp"
.SymbolBitmapSize = 24
.SymbolBitmapTransparent = True
End With
Else
With Map1.DefaultStyle
.SymbolFont = "custom symbols"
.SymbolType = 1
.SymbolBitmapName = "TRUC1-32.bmp"
.SymbolBitmapSize = 24
.SymbolBitmapTransparent = True
End With
End If
If flag = 0 ThenSet fNewSymbol = Map1.FeatureFactory.CreateSymbol(pt, Map1.DefaultStyle)Set fMapSymbol = lyrMyLayer.AddFeature(fNewSymbol)
a = fMapSymbol.FeatureKeyflag = 1
ElselyrMyLayer.DeleteFeature a
Set fNewSymbol = Map1.FeatureFactory.CreateSymbol(pt, Map1.DefaultStyle)
Set fMapSymbol = lyrMyLayer.AddFeature(fNewSymbol)
a = fMapSymbol.FeatureKeyEnd If
Next
End Sub
Public Sub UpdateListCars()
Dim iCount As Integer
Dim iSelected As IntegeriSelected = lstCars.ListIndex
Print iSelected
lstCars.Clear
For iCount = 1 To iVehicleCount
  lstCars.AddItem fArray(iCount).sName
Next
  lstCars.ListIndex = iSelected
  
Print lstCars.ListIndexEnd SubPrivate Sub setServ_Click()
loginSer.Show vbModal, Me
End Sub
我想就算我的time内部有错误,至少字符串“haha”是应该能显示的啊!但是连这个字符串都显示不了。实在不明白为什么了!

解决方案 »

  1.   

    不要在再代设计的时候设属性,在代码中设一次试一下
    sub form_load()
        timer1.integer=300
        timer1.enable=true 
    end sub
    然后单步调试看一下
      

  2.   

    ////我想就算我的time内部有错误,至少字符串“haha”是应该能显示的啊!但是连这个字符串都显示不了。实在不明白为什么了!
    我只看到你定义了haha为STRING没看到你赋值呀,那么debug.print haha    你当然就看不出来了debug.print haha    把这句换成  msgbox "开始运行TIMER了"   看看timer是否确实不能工作
      

  3.   

    Timer开始的时候设置
    Timer1.Enable = False等Timer1_Timer()这个SUB结束之前设置
    Timer1.Enable = True
      

  4.   

    呵呵,惭愧啊。小弟的本意是想print “haha”来试一下的,居然没想到没有赋值。羞愧的匿~~~~~~不了。