首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

BCB能編譯卻跑不出結果?解决方案

2012-02-04 
BCB能編譯卻跑不出結果???#include vcl.h#include math.h#pragma hdrstop#include Unit1.h#include

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'

热点排行