| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 465 人关注过本帖
标题:谁能帮我改编成DLL?
只看楼主 加入收藏
yalewang
Rank: 2
等 级:论坛游民
帖 子:125
专家分:35
注 册:2010-4-15
结帖率:94.74%
收藏
 问题点数:0 回复次数:0 
谁能帮我改编成DLL?
正在学习编程,VC感觉太难,用读取文件作为例题学了一个月VB,觉得上手很快,可遇到了新问题,想做一个标准输出的DLL,VB不具有这项功能,还要回头学VC,买了孙鑫的光盘,理论太深,还是自己给自己设题学得快,下面是我用VB改编的一段读取.CSV文件并进行数据处理的代码,望热心者能帮忙改成一个标准输出的DLL。

.CSV数据格式如下,很有规则,不过数据实时增加,每次增加一行(一个记录)
 1276855318;1.23900000
 1276855327;1.23910000
 1276855346;1.23920000
 1276855349;1.23930000
 1276855350;1.23940000
 1276855351;1.23940000
 调用格式如下:用C语言调用,看别的程序是这样的。
#import "tttt.DLL"
   int fun;
#import

我的VB代码如下:含有TIMER控件
Private Type datastructure
    time   As Long
    value  As Double
   
End Type

Dim data(1 To 100) As datastructure
Dim data0(1 To 100) As datastructure
Dim d As String, d0 As String
Dim dd As String, dd0 As String ''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''以上定义了一个结构体,并实例化了两个全局变量,
''''''''''''''''''''''''''''''上面的变量在DLL自行运行过程中或被调用后,其值保留。下次再被调用或运算时可以利用。


Private Sub Form_Load() ''''''''''''''''''''''''这一过程是对数组进行初始化,在VC中不知如何实现
Dim FJ() As String
Dim MyRecord As String * 24                    '''''''''''''一个记录有21个字符,实测的长度是24 ,因此长度定义为24
Dim i As Long, i0 As Long
Open "E:\sample1.csv" For Random As #10 Len = Len(MyRecord)
For i = LOF(10) / Len(MyRecord) - 99 To LOF(10) / Len(MyRecord)  '''对文件的后一百个记录进行读,并分割后存入数组
 Seek #10, i                          '''移动指针,从倒数第100至文件最后一行
Get #10, , MyRecord
FJ = Split(MyRecord, ";")
data(i + 100 - LOF(10) / Len(MyRecord)).time = CDbl(FJ(0))
data(i + 100 - LOF(10) / Len(MyRecord)).value = CDbl(FJ(1))
Next i
Close #10

Open "E:\sample2.csv" For Random As #20 Len = Len(MyRecord)
For i0 = LOF(20) / Len(MyRecord) - 99 To LOF(20) / Len(MyRecord)
 Seek #20, i0
Get #20, , MyRecord
FJ = Split(MyRecord, ";")
data0(i0 + 100 - LOF(20) / Len(MyRecord)).time = CDbl(FJ(0))
data0(i0 + 100 - LOF(20) / Len(MyRecord)).value = CDbl(FJ(1))
Next i0
Close #20

End Sub

Public Sub readdata(cs As String)          ''''''''''''''此过程对实时增加的文件进行读操作

Dim FJ() As String
Dim MyRecord As String * 24

Open cs For Random As #10 Len = Len(MyRecord)
Seek #10, LOF(10) / Len(MyRecord)                 ''''''''''''''''''''指针移至最后一行
Get #10, , MyRecord
Close #10
If InStr(1, MyRecord, ";") > 0 Then
    FJ = Split(MyRecord, ";")
         If d <> FJ(0) Or dd <> FJ(1) Then       '''''''''''''判断数据有无更新
                d = FJ(0)
                dd = FJ(1)
                Call adddata(FJ(0), FJ(1))       '''''''''''''''有更新即写入数组
               
          End If
End If
 
End Sub
Public Sub readdata0(cs As String)
Dim FJ0() As String
Dim MyRecord As String * 24
Open cs For Random As #20 Len = Len(MyRecord)
Seek #20, LOF(20) / Len(MyRecord)
Get #20, , MyRecord
Close #20
        If InStr(1, MyRecord, ";") > 0 Then
            FJ0 = Split(MyRecord, ";")
            If d0 <> FJ0(0) Or dd0 <> FJ0(1) Then
                d0 = FJ0(0)
                dd0 = FJ0(1)
                Call adddata0(FJ0(0), FJ0(1))
               
            End If
        End If
End Sub

Public Sub adddata(cs1 As String, cs2 As String)   ''''''''''''数据添加
Dim i As Long
    For i = 2 To 100
      data(i - 1).value = data(i).value
    Next i
      data(100).value = cs2
    For i = 2 To 100
      data(i - 1).time = data(i).time
    Next i
      data(100).time = cs1
   
End Sub

Public Sub adddata0(cs1 As String, cs2 As String)
Dim i As Long
    For i = 2 To 100
      data0(i - 1).value = data0(i).value
    Next i
      data0(100).value = CDbl(cs2)
    For i = 2 To 100
      data0(i - 1).time = data0(i).time
    Next i
      data0(100).time = CDbl(cs1)
   
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public function_tttt()     '''''''''''此函数部分未经测试,想以此作输出函数
     If data(100).value > data(99).value Then
      function_tttt = 1
     End If
     If data0(100).value > data(100).value Then
      function_tttt = 2                         ''''''''''''''其余情况函数值为0
      
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



Private Sub Timer1_Timer()   ''''''''''''''''''''''''''''Timer的interval设置为1,实时监控文件

                                                
    Call readdata("E:\sample1.csv")
    Call readdata0("E:\sample2.csv")
    Call function_tttt                 ''''''''''''''''''实时计算处理读取的数据,结果作为DLL的输出值
   
   
End Sub




搜索更多相关主题的帖子: DLL 改编 
2010-06-18 23:45
快速回复:谁能帮我改编成DLL?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020982 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved