1.将000001.day 文件数据格式   转换成-----000001.txt
 2.反之。
---------------------------------------------------------------
000001.day数据格式:1-4字节 Date:LongInt; //日期
5-8字节 OPen:LongInt; //开盘*100(元)
9-12字节 High:LongInt; //最高价*100(元)13-16字节 Low:LongInt; //最低价*100(元)
17-20字节 Close:LongInt; //收盘*100(元)21-24字节 single; //Amount
25-28字节 Volume:LongInt; //Volume 成交量(股)
29-32字节 // Reserved000001.txt文件数据格式:
------------------------------------------------------------------
10/29/2007,4152,4208,4152,4204,232,582
10/30/2007,4166,4178,4147,4168,206,604
10/31/2007,4111,4174,4111,4135,118,576
11/01/2007,4185,4185,4148,4148,100,580
11/02/2007,4099,4116,4082,4089,366,668
11/05/2007,4066,4116,4066,4093,90,674
11/06/2007,4096,4150,4096,4149,186,644
11/07/2007,4180,4185,4137,4142,140,606参考代码:
-----------------------------------------------------
其数据结构定义如下:typedef struct mystructtag
{
    int date;
    int open;
    int high;
    int low;
    int close;
    int amount;
    int vol;
    int reservation;
} StockData;
 
 
基本声明
    Public NumBase(5) As Long '通达信格式基数
    Public NumUnit(4) As Long '每单位对应的16进制数
    Public NumUnitPrice(4) As Long '每单位对于的10进制数,已被从元为单位扩大1000倍 基本模块
    Public Sub intTDXelg()Sub intTDXelg()
        NumBase(0) = 1065353216 : NumBase(1) = 1082130432 : NumBase(2) = 1090519040 : NumBase(3) = 1098907648 : NumBase(4) = 1109655552 ': NumBase(5) = 1118830592
        NumUnit(0) = 4194304 : NumUnit(1) = 2097152 : NumUnit(2) = 1048576 : NumUnit(3) = 524288 ': NumUnit(4) = 262144
        NumUnitPrice(0) = 0 : NumUnitPrice(1) = 4000 : NumUnitPrice(2) = 8000 : NumUnitPrice(3) = 16000 ': NumUnitPrice(4) = 32000
    End Sub
在form load 事件中调用intTDXelg    Public Structure stockDayRecordStructure stockDayRecord '保存一门股票的日数据信息
        Dim stockdate As Date
        Dim openor As Single
        Dim hightor As Single
        Dim lowor As Single
        Dim endor As Single
        Dim changor As Integer
        Dim id As Integer
        Dim VbP As Integer
    End Structure
     Public Function getRealPrice()Function getRealPrice(ByVal formerPrice As Long) As Long  '注意移植此函数是要把公共变量NumBase预NumUnit移动移植
        Dim i As Integer
        For i = 1 To 4                                 '该函数可返回32元人民币以下对于的准确价格
            If formerPrice < NumBase(i) Then
                getRealPrice = (Val((formerPrice - NumBase(i - 1)) & "000") / NumUnit(i - 1)) + NumUnitPrice(i - 1)
                Exit For                                  ' & 000 相当于 * 1000,以‰为单位
            End If
        Next i
    End Function读取模块
Function LoadDayData()Function LoadDayData(ByVal filename As String, ByRef dr() As stockDayRecord, ByVal t As Short) As Long
 '股票读取接口,第一个参数为装载股票数据的结构体
        Dim fs As FileStream = File.OpenRead(filename)
        Dim br As New BinaryReader(fs)
        Dim n As Integer
        Dim i As Integer, j As Integer
        Select Case t
            Case 1 '中天
              Case 2 '通达信 暂时不用
                n = (fs.Length - 4) / 32
                LoadDayData = n
                ReDim dr(n)
                br.ReadInt32() '文件头到底是什么,另外是头天顺序颠放到了某个地方
                For i = 1 To n
                    Dim d As Integer = br.ReadInt32()
                    dr(i).stockdate = DateSerial(d / 10000, (d Mod 10000) / 100, d Mod 100)
                    dr(i).openor = getRealPrice(br.ReadInt32) / 1000
                    dr(i).hightor = getRealPrice(br.ReadInt32) / 1000
                    dr(i).lowor = getRealPrice(br.ReadInt32) / 1000
                    dr(i).endor = getRealPrice(br.ReadInt32) / 1000
                    br.ReadInt32()
                    dr(i).changor = br.ReadInt32
                    dr(i).id = i
                    If (dr(i).hightor <> dr(i).lowor) Then dr(i).VbP = dr(i).changor / ((dr(i).hightor - dr(i).lowor) * 1000)
                    br.ReadInt32()
                Next
        End Select
        fs.Dispose()
        LoadDayData = j
    End Function

解决方案 »

  1.   

    二进制读写Get/Put 语句,具体去查 MSDN。
      

  2.   

    好久都没来这儿了。
    刚才给你写了段转换代码,其它部分的你自己考虑,我没兴趣。
    我测试过了,从 000001.txt转换到 Out.day ,其内容跟 000001.day 是一样的。
    从 000001.day 中转换到 Out.txt ,其内容跟 000001.txt 是一样的。
    000001.txt 中的内容,就是你在上面列出的那段。代码中没有进行错误捕获处理,这部分的你也自己考虑加入。我不清楚具体应用情况,想得再多也是白搭。
    整个工程到这儿下载吧:
    点此进入下载网页代码中 X:\Temp 是我测试用的路径,如果用得上,具体的路径和文件名你自己处理。
      

  3.   

    O(∩_∩)O谢谢O(∩_∩)O哈!万分感谢呵呵