小弟这里有一段DEPHI的代码,希望有大哥给我翻译成VB的。
小弟在这里不胜感激。
unit expgdhdata;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ToolWin, ComCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    OpenDialog1: TOpenDialog;
    Splitter1: TSplitter;
    Edit2: TEdit;
    StatusBar1: TStatusBar;
    procedure SpeedButton1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.SpeedButton1Click(Sender: TObject);
var
 i,k,ii,ik,NumRead,size: Integer;
 weight,speed: Double;
 F: File;
 sxdatet:Tdatetime;
begin
  if OpenDialog1.Execute then     { Display Open dialog box } 
//从对话框获取文件
    begin
     //根据文件名对文件进行关联
     AssignFile(F, OpenDialog1.FileName);
     //打开文件
     Reset(F, 1); { Record size = 1 }
     //得到文件大小
     Size := FileSize(F);
     if size > SizeOf(Tdatetime) then
       begin
         //清楚列表框内容
         ListBox1.Clear;
         ii:=0;
         ik:=0;
         //循环到读取的文件末尾
         while not Eof(F) do
           begin
             //读取sxdatet的值
             BlockRead(F, sxdatet, SizeOf(Tdatetime), NumRead);
             inc(ii);
             //向列表框输入时间的值
             ListBox1.Items.Add(inttostr(ii)+':    '
                                 +Formatdatetime('mm/dd/yyyy hh:mm:ss',sxdatet));
             //读取多少行记录
             BlockRead(F, k, SizeOf(integer), NumRead);
             if (k<0) or (k>200) then
               begin
                 edit2.Text:='   不能读取的数据格式。';
       //          ShowMessage('不能读取的数据格式。' );
                 CloseFile(F);
                 exit;
               end;
             //向列表框输出多少行
             ListBox1.Items.Add('      '+inttostr(k));
             //循环读取每行的数据并输入到列表框中
             for i:=1 to k do
               begin
                 BlockRead(F, weight, SizeOf(Double), NumRead);
                 BlockRead(F, speed, SizeOf(Double), NumRead);
                 ListBox1.Items.Add('      '+inttostr(i)+':    '
                                            +floattostr(weight)
                                            +'                  '
                                            +floattostr(speed));
               end;
             ik:=ik+k;
           end;
       end;
     CloseFile(F);
     statusBar1.Panels[0].Text:= inttostr(ii)+' 列      共:  '+inttostr(ik)+'   节';
   end;end;procedure TForm1.ListBox1Click(Sender: TObject);
begin
  edit2.Text:=listbox1.Items.Strings[listbox1.ItemIndex];
end;end.

解决方案 »

  1.   

    DEPHI不是很熟,vb也是初学,不过可以帮忙的就是帮忙顶一顶!支持一下!
      

  2.   

    gei 100分, 我帮你翻译。
      

  3.   

    pigsanddogs,我已经加分了。希望你快点看到,我着急用。
      

  4.   

    其实就是用VB读取一个二进制文件。文件格式在这个代码里说明了。只是我实在不会。又着急用。只好求救了。有意者可以跟我邮箱联系。[email protected]
    我把DELPHI代码给你。
      

  5.   

    快点好吗,我这里很着急。我不会吝啬这100分的。。能留下你的MSN吗?
      

  6.   

    SizeOf(Tdatetime)   8字节  同vb中date
    SizeOf(integer)   4字节    同vb中long
    SizeOf(Double)   8字节     同vb中double文件格式很简单,先读8个字节date, 然后读4个字节的记录行数
    每个行树读16个字节的2个double表示weight, speed。关键代码
    list1.clear
    open file as binary as #1
      dim thedate as date
      dim recordcount as long
      dim weight as double, speed as double
      do until eof(1)
        get #1,,thedate
        list1.add format("'mm/dd/yyyy hh:mm:ss", thedate)
        get #1,,recordcount
        list1.add "  " & recordcount 
        dim i as long 
        for i = 1 to recordcount
          get #1,, weight
          get #1,, speed
          list1.add i & ":     " & weight & "       " & speed
        next i
      loop
    close #1
      

  7.   

    1.把文件内容写到数据库中 
    Const BLOCKSIZE As Long = 4096 
    Sub FileToColumn(Col As ADODB.Field, DiskFile As String) 
    '从一个临时文件中获取数据,并把它保存到数据库中 
    'col为一个ADO字段,DiskFile为一个文件名,它可以为一个远程文件。 
    Dim strData() As Byte '声明一个动态数组 
    Dim NumBlocks As Long '读写块数 
    Dim FileLength As Long '文件长度 
    Dim LeftOver As Long '剩余字节数 
    Dim SourceFile As Long ‘文件句柄  
    Dim i As Long  
    SourceFile = FreeFile '获得剩余的文件句柄号 
    Open DiskFile For Binary Access Read As SourceFile '以二进制读方式打开源文件。 
    FileLength = LOF(SourceFile) '获得文件长度  
    If FileLength = 0 Then  
    Close SourceFile '关闭文件  
    Peedy.Speak DiskFile & " Empty or Not Found." ‘调用Msagent控件,提示信息 
    Else 
    NumBlocks = FileLength \ BLOCKSIZE ‘获得块数 
    LeftOver = FileLength Mod BLOCKSIZE ‘最后一块的字节数 
    Col.AppendChunk Null ‘追加空值,清除已有数据  
    ReDim strData(BLOCKSIZE) ‘从文件中读取内容并写到文件中。  
    For i = 1 To NumBlocks 
    Get SourceFile, , strData 
    Col.AppendChunk strData 
    Next I  
    ReDim strData(LeftOver) 
    Get SourceFile, , strData 
    Col.AppendChunk strData 
    Close SourceFile 
    End If 
    End Sub 
     
    2.从数据库中把文件内容读出来,并写到一个文件中。 
     
    Private Sub ColumnToFile(Col As ADODB.Field, DiskFile As String, rsset As Recordset) 
    '从数据库获得数据并把它们写到硬盘上的一个临时文件中。 
    '快的大小以4096为单位 
     
    Dim NumBlocks As Long '注释见上文 
    Dim LeftOver As Long ' 
    Dim strData() As Byte 
     
    Dim DestFileNum As Long 
    Dim i As Long 
    Dim ColSize As Long 
     
    '确保你存取的不是一个空记录集 
    If Not rsset.EOF And Not rsset.BOF Then 
    ColSize = Col.ActualSize 
    '获得列的实际大小 
    '如果文件长度为零,将删除文件内容 
    If Len(Dir$(DiskFile)) > 0 Then 
    Kill DiskFile 
    End If 
    DestFileNum = FreeFile 
    Open DiskFile For Binary As DestFileNum 
    NumBlocks = ColSize \ BLOCKSIZE 
    LeftOver = ColSize Mod BLOCKSIZE 
    '把数据写到文件中 
    For i = 1 To NumBlocks 
    ReDim strData(BLOCKSIZE) 
    strData = Col.GetChunk(BLOCKSIZE) 
    Put DestFileNum, , strData 
    Next i 
     
    ReDim strData(LeftOver) 
    strData = Col.GetChunk(LeftOver) 
    Put DestFileNum, , strData 
    Close DestFileNum 
    End If 
    End Sub 
      

  8.   

    麻烦楼上的ctrl+v也要看下题目啊。
      

  9.   

    有问题。。和原来的程序读出来的数据不一下,少一组数据。06-24-2006 16:56:55
    14
    1 80.152 12.41
    2 80.152 12.41
    3 80.152 12.41
    1 80.152 12.41

    14 80.152 12.41
    dephi的程序读出来有三组这样的数据。我安装你的说发,读出来第三组数据只有一个日期。后面就没有了。
    这是为什么