读书人

BCB能跑不出果?解决方案

发布时间: 2012-02-04 15:43:08 作者: rapoo

BCB能跑不出果???

#include <vcl.h>
#include <math.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------

void __fastcall TForm2::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
//需使用OpenDialog1, Memo1
Form1->Hide();

AnsiString filepath;

if(OpenDialog1->Execute()) //若案成功
{
filepath= OpenDialog1->FileName.c_str(); //把案路存 filepath
}


//declaration of variables of type variant 宣告
Variant XL,v0,v1,vcell;
int i,j,count=StrToInt(InputBox("Excel","入料:",""));


//a string where you will temporarily put the content of a single Cell 存Excel格料
AnsiString tmp,x[1000],y[1000],z[1000 ];

//create an object which is an excel application and store it to XL
XL=Variant::CreateObject("excel.application");

//Set the Excel Application as invisible once you have opened it Excel用程序置不可
XL.OlePropertySet("Visible",false);

//Get the workbooks while has a path stored in “file” variable and open it.

XL.OlePropertyGet("Workbooks").OleProcedure("Open", filepath.c_str() );

//Get the Sheet which has a title “Sheet1〃

v0=XL.OlePropertyGet("Sheets","Sheet1");

//Get the Cells of that particular Sheet. 取Excel格料表。

v1=v0.OlePropertyGet("Cells");



for(i=10;i<=count;i++)
{
vcell=v1.OlePropertyGet("Item",i,2);//定要取的位置 at row i and column j
x[i]=vcell.OlePropertyGet("Value");

vcell=v1.OlePropertyGet("Item",i,3);
y[i]=vcell.OlePropertyGet("Value");

vcell=v1.OlePropertyGet("Item",i,4);
z[i]=vcell.OlePropertyGet("Value");
//重 上行定要的字
//印出

}
XL.OleProcedure("Quit"); //案
XL=Unassigned;

double Vector_N[3],Vector_U[3],Vector_V[3],x0,y0,z0; //向量N,U,V 心x0,y0,z0
double a=StrToInt(Edit1->Text),b=StrToInt(Edit1->Text),c=StrToInt(Edit1->Text),temp_N,temp_U;

temp_N=sqrt(pow(a,2)+pow(b,2)+pow(c,2)); //求N向量
Vector_N[0]=a/temp_N;
Vector_N[1]=b/temp_N;
Vector_N[2]=c/temp_N;

x0=(x[count]+x[1])/2;
y0=(y[count]+y[1])/2;
z0=(z[count]+z[1])/2;

temp_U=sqrt(pow((x[0]-x0),2)+pow((y[0]-y0),2)+pow((z[0]-z0),2));//求U向量

Vector_U[0]=(x[0]-x0)/temp_U;
Vector_U[1]=(y[0]-y0)/temp_U;
Vector_U[2]=(z[0]-z0)/temp_U;

Vector_V[0]=(Vector_N[1]*Vector_U[2]-Vector_N[2]*Vector_U[1]);
Vector_V[1]=(Vector_N[2]*Vector_U[0]-Vector_N[0]*Vector_U[1]);
Vector_V[2]=(Vector_N[0]*Vector_U[1]-Vector_N[1]*Vector_U[0]);



// float H[3][3]={{Vector_U[0],Vector_V[0],x0},
// {Vector_U[1],Vector_V[1],y0},
// {Vector_U[2],Vector_V[2],z0}};




//3x3反矩//n矩大小,source原始矩,data反矩之後
//本副函式用於3*3 矩

double detA,H_Inverse[3][3];
{
double detA = Vector_U[0]*Vector_V[1]*z0
+Vector_U[1]*Vector_V[2]*x0
+Vector_U[2]*Vector_V[0]*Vector_V[0]
-Vector_U[0]*Vector_V[0]*Vector_V[2]
-Vector_U[1]*Vector_V[0]*z0
-Vector_U[2]*x0*Vector_V[1];
if(detA != 0)
{
H_Inverse[0][0] = (Vector_V[1]*z0 -
Vector_V[0]*Vector_V[2])/detA;
H_Inverse[0][1] = (x0*Vector_V[2] -
Vector_V[0]*z0)/detA;
H_Inverse[0][2] = (Vector_V[0]*Vector_V[0] -
Vector_V[1]*x0)/detA;
H_Inverse[1][0] = (Vector_U[2]*Vector_V[0] -
Vector_U[1]*z0)/detA;
H_Inverse[1][1] = (Vector_U[0]*z0 -
x0*Vector_U[2])/detA;
H_Inverse[1][2] = (Vector_U[1]*x0 -
Vector_U[0]*Vector_V[0])/detA;
H_Inverse[2][0] = (Vector_U[1]*Vector_V[2] -
Vector_U[2]*Vector_V[1])/detA;
H_Inverse[2][1] = (Vector_V[0]*Vector_U[2] -
Vector_U[0]*Vector_V[2])/detA;
H_Inverse[2][2] = (Vector_U[0]*Vector_V[1] -
Vector_V[0]*Vector_U[1])/detA;
}
}

double X[1000],Y[1000];
for (i=10;i<=count;i++)
{
X[i]=x[i]*H_Inverse[0][0]+x[i]*H_Inverse[0][1]+x[i]*H_Inverse[0][2];
Y[i]=y[i]*H_Inverse[1][0]+y[i]*H_Inverse[1][1]+y[i]*H_Inverse[1][2];
Memo1->Lines->Add("X[i]\t Y[i]" );
}


}


出息
Project Project1.exe raised exception class EConverError with message "0.999' is not a valid'.
Process stoped . Use Step or Run to continue.
我看看是哪出
感~~~~

[解决办法]
转换错误,你要保证所有StrToInt函数里的字符串都能转成数字才行。或者把所有的StrToInt(xxx)改成StrToIntDef(xxx,0)
[解决办法]
0.999应该用StrToFloat吧
[解决办法]
做了个尝试
StrToInt("0.999");
报错是
Project Project1.exe raised exception class EConvertError with message ''0.999' is not a valid integer value'. Process stopped. Use Step or Run to continue.

你的是
with message "0.999' is not a valid'

读书人网 >C++ Builder

热点推荐