Here is my function as it now exists. It has been in many forms, with somewhat the same results. As you see I'm using some data from
Excel to lookup values. The result comes back as an object, which I can easily put into other cells of excel, but can't seem to do
anything with it in this application. (Exception from HRESULT:0x800A03EC)
If I use object as the return type, then Convert.toString, I end up with "System.__Object" as my label text in Bricscad.
public class findbeam
{
[ComVisibleAttribute(true)]
public string FindBeam(double dist2, double w, double V, double M,double wthick)
{
object missing = System.Reflection.Missing.Value;
//object newTemplate = false;
//object docType = 0;
//object isVisible = true;
Excel._Application ExcelApp = new Excel.ApplicationClass();
ExcelApp.Visible = false;
Workbook objBook = ExcelApp.Workbooks._Open("C:\\Beam Data\\Wood.xls", Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Worksheet objSheet = (Worksheet)objBook.Sheets["Sheet1"];
ExcelApp.Visible = true;
ExcelApp.WindowState = XlWindowState.xlMinimized;
objSheet.Cells[12, 15] = w;
Range rang;
int off;
if (wthick < 5.0)
{
rang = objSheet.get_Range("I5", "I10");
off = 5;
}
else
{
rang = objSheet.get_Range("I11", "I15");
off = 11;
}
int Vrow = (int) ExcelApp.WorksheetFunction.Match(V, rang, 1);
Range ranga = objSheet.get_Range(objSheet.Cells[Vrow + off, 3], missing);
//double b = (double)ranga.get_Value(missing);
double b = Convert.ToDouble(ranga.Value2);
objSheet.Cells[2, 1] = b;
ranga = objSheet.get_Range(objSheet.Cells[Vrow + off, 4], missing);
double d = Convert.ToDouble(ranga.Value2);
objSheet.Cells[3, 1] = d;
string dbeam = Convert.ToString(ranga.Value2);
objSheet.Cells[4, 1] = dbeam;
//dbeam = Convert.ToString(dbeam);
//objBook.Close("Save", "C:\\Beam Data\\Wood.xls", Type.Missing);
//-------------------------
//Form1 frm = new Form1();
//frm.txtbx1text = (dist2 / 12.0).ToString("F2");
//frm.ShowDialog(frm);
return dbeam;
}
}
Hope the code doesn't offend you too much. It's pieces from here and there.
Thanks for looking.