【发布时间】:2014-03-23 22:17:28
【问题描述】:
在我努力学习 C# 的过程中,我用 Vb 和 C# 为一个小项目编写了代码。我已经取得了进展,但是在尝试实现在 Vb 中很容易实现的东西时遇到了问题。该例程从色谱系统中读取结果文件。当我尝试确定已处理峰的数组大小时,就会出现问题,这些峰的大小取决于各个峰的积分限制。我的目标是将它们填充到列表中,然后用于在 XY 图上显示峰值。我已经搜索过,通常提供两个选项,但它们对我不起作用,但也许还有其他一些我遗漏的东西。我尝试使用 GetUpperBounds 属性
nPoints = mySliceTable.get_RTsAt(j).GetUpperBound(0);
并引用 Microsoft.VisualBasic 并使用类似的东西
nPoints = Information.UBounds(mySliceTable.get_RTsAt(j);
在任何一种情况下,我都会收到类似“无法将 'System.Double[*]' 类型的对象转换为 'System.Double[]' 类型的错误”。如果我尝试创建数组而不是确定其大小,这将是有意义的。
代码如下所示。我在粘贴整个班级时遇到问题。缺少的是命名空间、using 语句、类 def,然后是第一个显示对话框以获取要读取的文件名的方法。
任何建议将不胜感激。
谢谢,雷
private void readFile(string file)
{
PLCirrusResults myRstFile = new PLCirrusResults();
myRstFile.Load(file);
IPLCirrusRstSampleInfo mySampleInfo ;
IPLCirrusRstSliceTable mySliceTable ;
IPLCirrusRstProcessedPeaks myProcessedPeaks;
mySampleInfo = (IPLCirrusRstSampleInfo)myRstFile;
mySliceTable = (IPLCirrusRstSliceTable)myRstFile;
myProcessedPeaks = (IPLCirrusRstProcessedPeaks)myRstFile;
// read the sample info header
string sampleName = mySampleInfo.SampleName.ToString();
double conc = Convert.ToDouble(mySampleInfo.Concentration);
double injVol = Convert.ToDouble(mySampleInfo.InjectionVolume);
// read Slice Table
int nPeaks = Convert.ToInt32(mySliceTable.NumberOfSliceTablePeaks);
int nPoints = 0;
IList<double> rTs = new List<double>();
List<double> sConcs = new List<double>();
List<double> normHts = new List<double>();
List<double> responses = new List<double>();
for (int j = 1; j <= nPeaks; j++)
{
nPoints = mySliceTable.get_RTsAt(j).GetUpperBound(0);
for (int i = 1; i <= nPoints; i++)
{
rTs.Add(mySliceTable.get_RTsAt(j)(i));
responses.Add(mySliceTable.get_ResponsesAt(j)(i));
normHts.Add(mySliceTable.get_NormalisedHeightsAt(j)(i));
sConcs.Add(mySliceTable.get_ConcentrationsAt(j)(i));
}
}
string msg = String.Format("The sample is: {0}", sampleName);
MessageBox.Show(msg, "file Info");
}
}
补充:抱歉耽搁了,说来话长。
堆栈跟踪:
[External Code]
ElastGPCAnalysis.exe!GPC.Model.CirrusFiles.readFile(string file)` Line 71 -> this is the line with the GetUpperBounds(0);
ElasttGPCAnalysis.exe!GPC.Models.CirrusFiles.openFile()` Line 38
ElastGPC.exe!GPC.GPCViewModel.btnLoadSample()` Line 34
[External Code]
然后调用 Caliburn.micro。
回答有关如何定义 get_RTsAt 的问题。再次粘贴屏幕截图会更容易,但我还不能。所以我会写我能写的。
我引用的 dll 在众多可用接口之一中称为 PCLGRAMLib.dll 和 IPLCirrusRstSliceTable。 动态 get_RTsAt(int Peak) PLCGRAMLib.IPLCirrusRstSliceTable的成员来自对象浏览器。
【问题讨论】:
-
IPLCirrusRstSampleInfo.get_RTsAt()是如何定义的? -
.Length - 1不够用的任何理由? -
请发布一段简单的代码来实际展示问题。扔掉不相关的代码,但包含足以重现问题的代码。例如,这缺少基本的
IPLCirrusRstSampleInfo.get_RTsAt()定义。 -
很难解释 GetUpperBound 是如何失败的。更多关于this question中的不合格数组@
-
@Ray_B123456 查看您的更新,在我看来,失败的行是
myRstFile.Load(file);,与GetUpperBound(0);无关。是什么让你如此相信?
标签: c#