www.pudn.com > sock_server.rar > sockmodle.bas


Attribute VB_Name = "Module1" 
Option Explicit 
'''''''''''''''''''''''''''''''''''''''''''''' 
Public Const send_type1 As String = "%" 
Public Const send_type2 As String = "#" 
Public Const send_type3 As String = "!" 
Public Const count_init As Integer = 100 
Public sta_name(1 To 10) As String 
Public Type sta_sock 
       sta_no As Integer 
       sock_no As Integer 
       End Type 
Public Type inp_type 
       sta_no As Integer 
       inp_L(1 To 8) As Double 
       inp_M(1 To 6) As Double 
       inp_S(1 To 10) As Double 
       End Type 
'十六进制转换为十进制 
Public Function hex_10(ByVal hhex As String) As Long 
    Const M As Integer = 16 
    Dim hh As Long 
    Dim i As Long 
    Dim j As Long 
    Dim lin As Integer 
    j = Len(hhex) 
    For i = 1 To Len(hhex) 
       Select Case Mid$(hhex, i, 1) 
              Case "A" 
                    lin = 10 
              Case "B" 
                    lin = 11 
              Case "C" 
                    lin = 12 
              Case "D" 
                    lin = 13 
              Case "E" 
                    lin = 14 
              Case "F" 
                    lin = 15 
              Case Else 
                    lin = Val(Mid$(hhex, i, 1)) 
       End Select 
       j = j - 1 
      hh = hh + M ^ j * lin 
    Next i 
    hex_10 = hh 
End Function 
 
Public Function pro_data(ByVal sta_no As Integer, ByVal data_str As String) As inp_type 
Dim i As Long 
Dim data_rtn As inp_type 
For i = 1 To Len(data_str) 
     
Next i 
data_rtn.sta_no = sta_no 
End Function 
Public Sub write_lib_sql(ByVal sub_no As Integer) 
 
Dim cn As ADODB.Connection 
Dim cn_str  As String 
Dim rs As ADODB.Recordset 
Dim rs_str As String 
Set cn = New ADODB.Connection 
cnstr = "Provider=SQLOLEDB.1;Password=zhi;Persist Security Info=True;User ID=sa;Initial Catalog=giga;Data Source=ZHI" 
Set rs = New ADODB.Recordset 
rs_str = "select * from [test_g]" 
Call cn.Open(constr) 
Call rs.Open(rs_str, cn, adOpenDynamic, adLockOptimistic) 
      
End Sub 
Public Sub fresh_list() 
Dim i As Integer 
Dim cn As ADODB.Connection 
Dim cn_str As String 
Dim rs As ADODB.Recordset 
Dim rs_str As String 
Set cn = New ADODB.Connection 
cn_str = "Provider=SQLOLEDB.1;Password=zhi;Persist Security Info=True;User ID=sa;Initial Catalog=giga;Data Source=ZHI" 
Set rs = New ADODB.Recordset 
rs_str = "select * from [test_g] order by [date_sub] desc" 
Call cn.Open(cn_str) 
Call rs.Open(rs_str, cn, adOpenDynamic, adLockReadOnly) 
If rs.EOF = True And rs.BOF = True Then Exit Sub 
Form1.lvw_ma.ListItems.Clear 
Form1.lvw_mm.ListItems.Clear 
Form1.lvw_ser.ListItems.Clear 
rs.MoveFirst 
For i = 1 To 8 
Form1.lvw_ma.ListItems.Add 
Form1.lvw_mm.ListItems.Add 
Form1.lvw_ser.ListItems.Add 
With Form1.lvw_ma.ListItems.Item(i) 
     .Text = sta_name(rs.Fields(0)) 
     .SubItems(1) = rs.Fields(1) 
     .SubItems(2) = Format$(rs.Fields(2), "#0.0") & "/" & Format$(rs.Fields(3), "#0.0") 
     .SubItems(3) = Format$(rs.Fields(4), "#0.0") & "/" & Format$(rs.Fields(5), "#0.0") 
     .SubItems(4) = Format$(rs.Fields(6), "#0.0") & "/" & Format$(rs.Fields(7), "#0.0") 
     .SubItems(5) = Format$(rs.Fields(8), "#0.0") & "/" & Format$(rs.Fields(9), "#0.0") 
     .SubItems(6) = Format$(rs.Fields(10), "#0.0") & "/" & Format$(rs.Fields(11), "#0.0") 
     .SubItems(7) = Format$(rs.Fields(12), "#0.0") & "/" & Format$(rs.Fields(13), "#0.0") 
     .SubItems(8) = Format$(rs.Fields(14), "#0.0") & "/" & Format$(rs.Fields(15), "#0.0") 
     .SubItems(9) = Format$(rs.Fields(16), "#0.0") & "/" & Format$(rs.Fields(17), "#0.0") 
End With 
With Form1.lvw_mm.ListItems.Item(i) 
     .Text = sta_name(rs.Fields(0)) 
     .SubItems(1) = rs.Fields(1) 
     .SubItems(2) = Format$(rs.Fields(18), "#0.0") 
     .SubItems(3) = Format$(rs.Fields(19), "#0.0") 
     .SubItems(4) = Format$(rs.Fields(20), "#0.0") 
     .SubItems(5) = Format$(rs.Fields(21), "#0.0") 
     .SubItems(6) = Format$(rs.Fields(22), "#0.0") 
     .SubItems(7) = Format$(rs.Fields(23), "#0.0") 
End With 
rs.MoveNext 
If rs.EOF = True Then Exit For 
Next i 
End Sub 
Sub main() 
   Dim i As Integer 
    sta_name(1) = "子站1" 
    sta_name(2) = "子站2" 
    sta_name(3) = "子站3" 
    sta_name(4) = "子站4" 
    sta_name(5) = "子站5" 
    sta_name(6) = "子站6" 
    sta_name(7) = "子站7" 
    sta_name(8) = "子站8" 
    sta_name(9) = "子站9" 
    sta_name(10) = "子站10" 
    Form1.Show 
End Sub