这是一段VB6的代码,谁能给翻译成C语言

drlqyy 2008-01-22 12:28:38

Public tempdata() As Long
Public NumBase(5) As Long '基数
Public NumUnit(4) As Long '每单位对应的16进制数
Public NumUnitPrice(4) As Long '每单位对于的10进制数,已被从元为单位扩大1000倍
Public Type tempFSTrecord '每一条记录的长度为26字节:
FSTtime As Integer
price As Long
avgPrice As Long
changor As Integer
unUse0 As Integer
unUse1 As Long
unUse2 As Long
unUse3 As Long
End Type
Function LoadFSTdata(ByVal filename As String, fst() As FSTrecord) '240个分记录,26个字节一个记录,6508字节一天
Dim ifile As Integer, i As Integer, j As Integer
Dim TFR As tempFSTrecord
Dim fileP As Long
Dim lenDayFST As Long: longDayFST = 6508
Dim lenminuteFST As Long: lenminuteFST = 26
ifile = FreeFile
Open filename For Binary As ifile
'LoadFSTdata = (LOF(ifile) - 8) / 26 - 10
LoadFSTdata = LOF(ifile) / 6508

ReDim fst(1 To LoadFSTdata, 239)
ReDim tempdata(1 To LoadFSTdata)
ReDim tempMidprice(1 To LoadFSTdata)
ReDim fstMaxPrice(1 To LoadFSTdata)
For j = 1 To LoadFSTdata
Get ifile, 1 + (j - 1) * longDayFST, tempdata(j)
Get ifile, 5 + (j - 1) * longDayFST, tempMidprice(j)
fstMaxPrice(j) = 0
For i = 0 To 239
fileP = (j - 1) * longDayFST + i * lenminuteFST + 8 + 1
Get ifile, fileP, TFR
fst(j, i).FSTtime = TFR.FSTtime + 1 'fst(i).FSTtime = TimeSerial(0, TFR.FSTtime + 1, 0)
fst(j, i).price = TFR.price
fst(j, i).avgPrice = TFR.avgPrice
fst(j, i).changor = TFR.changor
If Abs(TFR.price - tempMidprice(j)) > fstMaxPrice(j) Then
fstMaxPrice(j) = Abs(TFR.price - tempMidprice(j))
End If
Next i
Next j
Close ifile
End FunctionFunction getRealPrice(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
Public Sub main()
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
readZST.Show'由这个窗体去调用以上的函数,自己写
End Sub
...全文
50 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ydlchina 2008-01-22
up
回复
caofusheng 2008-01-22
由于时间关系 和你的VB代码有错误,我大致翻了一下,LoadFSTdata中,好多数组的初始化处理没有写,
fread的读取数据的处理肯定是错误的。不过编译能通过。错误你自己修改吧。


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long tempdata[10000];
long NumBase[5];
long NumUnit[4];
long NumUnitPrice[4];
struct tempFSTrecord
{
int FSTtime;
long price;
long avgPrice;
int changor;
int unUse0 ;
long unUse1 ;
long unUse2 ;
long unUse3;
};
void LoadFSTdata(char *filename, tempFSTrecord fst[][239]);
long getRealPrice(long formerPrice);

void LoadFSTdata(char *filename, tempFSTrecord fst[][239] )
{
int i , j ;
tempFSTrecord TFR;
long fileP,lenDayFST,lenminuteFST,intFilelen;
FILE *fp;
char Temp[100000];

lenDayFST = 6508;
lenminuteFST = 26;
fp = fopen(filename, "r");
if (fp == 0 )
{
return ;
}
else
{
fseek(fp, 0, SEEK_END);
intFilelen = ftell(fp)/6508;


long tempdata[10000];
long tempMidprice[ 10000];
long fstMaxPrice[10000];

for (j = 1 ;j<=intFilelen;j++)
{
fread((char *)tempdata[j],0,1 + (j - 1) * lenDayFST,fp);
fread((char *)tempMidprice[j],0,5 + (j - 1) * lenDayFST,fp);
fstMaxPrice[j] = 0;
for (i = 0;i <= 239;i++)
{
fileP = (j - 1) * lenDayFST + i * lenminuteFST + 8 + 1;
fread( Temp,0,1 + (j - 1) * lenDayFST,fp);
fst[j][i] .FSTtime = TFR.FSTtime + 1;
fst[j][i] .price = TFR.price;
fst[j][i] .avgPrice = TFR.avgPrice;
fst[j][i] .changor = TFR.changor;
if (labs(TFR.price - tempMidprice[j]) > fstMaxPrice[j])
{
fstMaxPrice[j] = labs(TFR.price - tempMidprice[j]);
}
}
}


}
fclose(fp);

}

long getRealPrice(long formerPrice)
{
int i;
long a;
for (i = 1 ;i<=4;i++)
{
if (formerPrice < NumBase[i])
{
a = ((long)((formerPrice - NumBase[i - 1])*1000) / NumUnit[i - 1]) + NumUnitPrice[i - 1];
return a;
}
}
return a;
}


void main()
{
NumBase[0] = 1065353216;
NumBase[1] = 1082130432;
NumBase[2] = 1090519040;
NumBase[3] = 1098907648;
NumBase[4] = 1109655552;
NumUnit[0] = 4194304;
NumUnit[1] = 2097152;
NumUnit[2] = 1048576;
NumUnit[3] = 524288;
NumUnitPrice[0] = 0;
NumUnitPrice[1] = 4000;
NumUnitPrice[2] = 8000;
NumUnitPrice[3] = 16000;

}
回复
ZOU_SEAFARER 2008-01-22
搂住你还是把意图说明白,然后高手就直接参考你的代码写C乐
如果你这样,高手是没有耐心去理解你的代码的,再说你的代码还不完善,不过是判断而已吧
回复
ZOU_SEAFARER 2008-01-22
Get ifile, 1 + (j - 1) * longDayFST, tempdata(j)

‘=================================================================
少了#号
回复
caofusheng 2008-01-22
ifile = FreeFile 意思是取得一个空闲的文件号
ReDim fst(1 To LoadFSTdata, 239) 意思是重新定义数组的大小
回复
drlqyy 2008-01-22
Get ifile, 1 + (j - 1) * longDayFST, tempdata(j)
什么意思?
回复
drlqyy 2008-01-22
文件中的
ifile = FreeFile

ReDim fst(1 To LoadFSTdata, 239)
什么意思?
回复
kelvin357 2008-01-22
这个问题是问题吗, 感觉像在请枪手~``
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告