PDA

View Full Version : visual basic (msflexgrid)



JuAn
04-19-2008, 08:44 AM
Private Sub Form_Load()
FillFlex
'Dim dbAvg As Database
'Adodc1.Recordset.AddNew


End Sub

Private Sub FillFlex()
On Error Resume Next
Dim lAvg As Long, iCOunt As Integer
Dim intTime As Date

strSql = "SELECT CarID, TimeIn, TimeOut, TimeDuration, Speed" & _
" FROM Car_Details" ' WHERE CarTime >=cdate('2008-03-31 7:00')"

' MsgBox strSql
iCOunt = 0
FlxRs.Open strSql, DE.Conn, adOpenForwardOnly, adLockReadOnly
Flex.Rows = 1
If FlxRs.RecordCount > 0 Then

For i = 1 To FlxRs.RecordCount
Flex.Rows = Flex.Rows + 1
Flex.TextMatrix(i, 0) = FlxRs(0)
Flex.TextMatrix(i, 1) = FlxRs(1)
Flex.TextMatrix(i, 2) = FlxRs(2)
Flex.TextMatrix(i, 3) = FlxRs(3)
If FlxRs(2).Value <> "" Then
iCOunt = iCOunt + 1
End If
Flex.TextMatrix(i, 4) = FlxRs(4)

FlxRs.MoveNext

lAvg = lAvg + Flex.TextMatrix(i, 4) '= FlxRs(3)
lAvg = Math.Round(lAvg, 2)
Next i
lblNum.Caption = iCOunt
lblAverage.Caption = lAvg / lblNum
lblAverage.Caption = Math.Round(lblAverage.Caption, 2)
Else
lblNum.Caption = ""
End If
FlxRs.Close

End Sub

1. How to store the data that has been display on the msflexgrid to a database access

2. and how to display data in the msflexgrid for every 5 min


Plz guide me. tq

debu
04-19-2008, 10:51 AM
@JuAn: Quite off-topic, for a robotics forum. :roll:

However,

1. How to store the data that has been display on the msflexgrid to a database access
You need to create a ADO object for accessing the Access Database, it will look like:



Public Function DB_INIT ()
Dim c1 As ADODB.Connection
Dim c1str As String
c1str = "Provider=MSAccess; DSN=db_alias; UID=userid; PWD=password"
c1.Open c1str
............
............
............


You can access your data using simple SQL Commands.


2. and how to display data in the msflexgrid for every 5 min

You need a "timer" object that creates a tick event every 5 mins (5mins = 1000 * 60 * 5 milliseconds = 300000ms) then you need to enter your code in the tick event. It will look like:


Private Sub Timer1_Tick()
'Refresh Data for MSFlexGrid Code Goes Here
End Sub


Regards,

Debu :)