非常感谢!!!!!急.....
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。
************** 异常文本 **************
System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。
参数名: length
在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
在 System.String.Substring(Int32 startIndex, Int32 length)
在 报表智能软件.Form1.PserverReadData(String temp)
在 报表智能软件.Form1.button1_Click(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
13 个解决方案
#1
你的代码有问题了
很可能是因为中文字符的问题
很可能是因为中文字符的问题
#2
把这个代码贴出来就知道了 报表智能软件.Form1.PserverReadData(String temp)
#3
但代码没中文的呀.
#4
这是代码
PISDK.PISDK pisdk = new PISDK.PISDKClass();
PISDK.Server myServer; // 默人服务器
PISDK.PIPoints myPoints; // 测点集合
PISDK.PIPoint snapPoint; // 测点
PISDK.PIValue myValue;//测点值
PISDK.PIValue archiveValue;//历史值
PITimeServer.PITimeFormat piTime=new PITimeServer.PITimeFormat();//pi数据库时间格式对象
string yearText = this.Datecombox.Text.Trim();//年份
string monthText = this.Monthcombox.Text.Trim();//月份
string dayText = this.Daycombox.Text.Trim();//日
string hourText = this.HourComBox.Text.Trim();//小时
string minuteText = this.Minutecombox.Text.Trim();//分钟
string queryDateString =(yearText + "-" + monthText + "-" + dayText + " " + hourText + ":" + minuteText);
piTime.InputString = queryDateString;
Excel.Application exp3 = new Excel.ApplicationClass();//打开excel进程
exp3.Visible = false;
// Hashtable table = new Hashtable();
Excel.Workbook exwork3 = exp3.Workbooks._Open(@"D:\cedian.xls",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
Excel.Worksheet xpsheet = (Excel.Worksheet)exwork3.Worksheets[1];//默认打开sheet1
ArrayList ay2 = new ArrayList();
ArrayList ay3 = new ArrayList();
ArrayList aytemp = new ArrayList();
ArrayList ay2Result = new ArrayList();
ArrayList ay3Result = new ArrayList();
for (int n = 0; n < 991; n++)
{
Excel.Range rng3 = xpsheet.get_Range(xpsheet.Cells[n + 1, 2], xpsheet.Cells[n + 1, 2]);
Excel.Range rng4 = xpsheet.get_Range(xpsheet.Cells[n + 1, 3], xpsheet.Cells[n + 1, 3]);
ay2.Add(rng3.Value2);
ay3.Add(rng4.Value2);
string changzhanText =this.ChangzhancomboBox.Text.Trim ();
string ExcelStr = (string)ay2[n];
string ExcelStr1 = (string)ay3[n];
if (ExcelStr == null && ExcelStr1==null)
continue;
else
{
if (ExcelStr.Substring(0, 3).Equals(changzhanText))
{
aytemp.Remove(changzhanText);
ay2Result.Add(rng3.Value2);
ay3Result.Add(rng4.Value2);
for (int e = 0; e < ay2Result.Count; e++)
{////判断e的值来确定开始第几行写入数据
if (e == 0)
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
else
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
}
for (int e = 0; e < ay3Result.Count; e++)
{////判断e的值来确定开始第几行写如数据
if (e == 0)
{
string cedian;
cedian = (string)ay3Result[e];
myServer = pisdk.Servers.DefaultServer;
myPoints = myServer.PIPoints;
snapPoint = myPoints[cedian];
myValue = snapPoint.Data.Snapshot;
archiveValue = snapPoint.Data.ArcValue(piTime, PISDK.RetrievalTypeConstants.rtAuto, new PISDKCommon.PIAsynchStatus());//pitime历史时间,PISDK.RetrievalTypeConstants.rtAuto是取值模式,
if (archiveValue.IsGood() == false)//PI数据库中得到数据为null,archiveValue为false;
{
this.axSpreadsheet1.Cells[e + 2, 3] = "Nodata";
this.axSpreadsheet1.Cells[e + 2, 4] = "Nodata";
}
else
{
this.axSpreadsheet1.Cells[e + 2, 3] = archiveValue.Value.ToString();
this.axSpreadsheet1.Cells[e + 2, 4] = Convert.ToDecimal(archiveValue.Value) / Convert.ToDecimal(this.textBox1.Text);
}
}
PISDK.PISDK pisdk = new PISDK.PISDKClass();
PISDK.Server myServer; // 默人服务器
PISDK.PIPoints myPoints; // 测点集合
PISDK.PIPoint snapPoint; // 测点
PISDK.PIValue myValue;//测点值
PISDK.PIValue archiveValue;//历史值
PITimeServer.PITimeFormat piTime=new PITimeServer.PITimeFormat();//pi数据库时间格式对象
string yearText = this.Datecombox.Text.Trim();//年份
string monthText = this.Monthcombox.Text.Trim();//月份
string dayText = this.Daycombox.Text.Trim();//日
string hourText = this.HourComBox.Text.Trim();//小时
string minuteText = this.Minutecombox.Text.Trim();//分钟
string queryDateString =(yearText + "-" + monthText + "-" + dayText + " " + hourText + ":" + minuteText);
piTime.InputString = queryDateString;
Excel.Application exp3 = new Excel.ApplicationClass();//打开excel进程
exp3.Visible = false;
// Hashtable table = new Hashtable();
Excel.Workbook exwork3 = exp3.Workbooks._Open(@"D:\cedian.xls",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
Excel.Worksheet xpsheet = (Excel.Worksheet)exwork3.Worksheets[1];//默认打开sheet1
ArrayList ay2 = new ArrayList();
ArrayList ay3 = new ArrayList();
ArrayList aytemp = new ArrayList();
ArrayList ay2Result = new ArrayList();
ArrayList ay3Result = new ArrayList();
for (int n = 0; n < 991; n++)
{
Excel.Range rng3 = xpsheet.get_Range(xpsheet.Cells[n + 1, 2], xpsheet.Cells[n + 1, 2]);
Excel.Range rng4 = xpsheet.get_Range(xpsheet.Cells[n + 1, 3], xpsheet.Cells[n + 1, 3]);
ay2.Add(rng3.Value2);
ay3.Add(rng4.Value2);
string changzhanText =this.ChangzhancomboBox.Text.Trim ();
string ExcelStr = (string)ay2[n];
string ExcelStr1 = (string)ay3[n];
if (ExcelStr == null && ExcelStr1==null)
continue;
else
{
if (ExcelStr.Substring(0, 3).Equals(changzhanText))
{
aytemp.Remove(changzhanText);
ay2Result.Add(rng3.Value2);
ay3Result.Add(rng4.Value2);
for (int e = 0; e < ay2Result.Count; e++)
{////判断e的值来确定开始第几行写入数据
if (e == 0)
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
else
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
}
for (int e = 0; e < ay3Result.Count; e++)
{////判断e的值来确定开始第几行写如数据
if (e == 0)
{
string cedian;
cedian = (string)ay3Result[e];
myServer = pisdk.Servers.DefaultServer;
myPoints = myServer.PIPoints;
snapPoint = myPoints[cedian];
myValue = snapPoint.Data.Snapshot;
archiveValue = snapPoint.Data.ArcValue(piTime, PISDK.RetrievalTypeConstants.rtAuto, new PISDKCommon.PIAsynchStatus());//pitime历史时间,PISDK.RetrievalTypeConstants.rtAuto是取值模式,
if (archiveValue.IsGood() == false)//PI数据库中得到数据为null,archiveValue为false;
{
this.axSpreadsheet1.Cells[e + 2, 3] = "Nodata";
this.axSpreadsheet1.Cells[e + 2, 4] = "Nodata";
}
else
{
this.axSpreadsheet1.Cells[e + 2, 3] = archiveValue.Value.ToString();
this.axSpreadsheet1.Cells[e + 2, 4] = Convert.ToDecimal(archiveValue.Value) / Convert.ToDecimal(this.textBox1.Text);
}
}
#5
这句出错了 ExcelStr.Substring(0, 3).Equals(changzhanText))
changzhanText 不足3个字符
changzhanText 不足3个字符
#6
changzhanText 这个值是Combox中的值,读出来是"宁西变"中文字符,怎么会不足3个字符!
#7
没有什么不可能的啊
加个判断前面吧
或者看看你的Combox中的值是怎么赋值进去的
加个判断前面吧
或者看看你的Combox中的值是怎么赋值进去的
#8
Combox中的值是从excle文件中读出来的,而且excel中每一列值多是跟"宁西变"这样3个中文字构成的.那为什么在我的电脑上运行一点多没出错,在测试电脑上出现这样的问题?
#9
测试电脑上可能没有读取到excle文件,或者读到的"宁西变" 是乱码等等
#10
如果是不是乱码怎么解决乱码的问题?谢谢....
#11
substring 索引id溢出
#12
怎么解决益出.?
#13
ExcelStr这个值由问题,长度没有三个。你还是在前面判断一下长度吧。
string str = string.Empty;
if(ExcelStr.Length > 3){
str = ExcelStr.Substring(0, 3);
}
else
{
str = ExcelStr;
}
if (str.Equals(changzhanText))
{ ....
string str = string.Empty;
if(ExcelStr.Length > 3){
str = ExcelStr.Substring(0, 3);
}
else
{
str = ExcelStr;
}
if (str.Equals(changzhanText))
{ ....
#1
你的代码有问题了
很可能是因为中文字符的问题
很可能是因为中文字符的问题
#2
把这个代码贴出来就知道了 报表智能软件.Form1.PserverReadData(String temp)
#3
但代码没中文的呀.
#4
这是代码
PISDK.PISDK pisdk = new PISDK.PISDKClass();
PISDK.Server myServer; // 默人服务器
PISDK.PIPoints myPoints; // 测点集合
PISDK.PIPoint snapPoint; // 测点
PISDK.PIValue myValue;//测点值
PISDK.PIValue archiveValue;//历史值
PITimeServer.PITimeFormat piTime=new PITimeServer.PITimeFormat();//pi数据库时间格式对象
string yearText = this.Datecombox.Text.Trim();//年份
string monthText = this.Monthcombox.Text.Trim();//月份
string dayText = this.Daycombox.Text.Trim();//日
string hourText = this.HourComBox.Text.Trim();//小时
string minuteText = this.Minutecombox.Text.Trim();//分钟
string queryDateString =(yearText + "-" + monthText + "-" + dayText + " " + hourText + ":" + minuteText);
piTime.InputString = queryDateString;
Excel.Application exp3 = new Excel.ApplicationClass();//打开excel进程
exp3.Visible = false;
// Hashtable table = new Hashtable();
Excel.Workbook exwork3 = exp3.Workbooks._Open(@"D:\cedian.xls",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
Excel.Worksheet xpsheet = (Excel.Worksheet)exwork3.Worksheets[1];//默认打开sheet1
ArrayList ay2 = new ArrayList();
ArrayList ay3 = new ArrayList();
ArrayList aytemp = new ArrayList();
ArrayList ay2Result = new ArrayList();
ArrayList ay3Result = new ArrayList();
for (int n = 0; n < 991; n++)
{
Excel.Range rng3 = xpsheet.get_Range(xpsheet.Cells[n + 1, 2], xpsheet.Cells[n + 1, 2]);
Excel.Range rng4 = xpsheet.get_Range(xpsheet.Cells[n + 1, 3], xpsheet.Cells[n + 1, 3]);
ay2.Add(rng3.Value2);
ay3.Add(rng4.Value2);
string changzhanText =this.ChangzhancomboBox.Text.Trim ();
string ExcelStr = (string)ay2[n];
string ExcelStr1 = (string)ay3[n];
if (ExcelStr == null && ExcelStr1==null)
continue;
else
{
if (ExcelStr.Substring(0, 3).Equals(changzhanText))
{
aytemp.Remove(changzhanText);
ay2Result.Add(rng3.Value2);
ay3Result.Add(rng4.Value2);
for (int e = 0; e < ay2Result.Count; e++)
{////判断e的值来确定开始第几行写入数据
if (e == 0)
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
else
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
}
for (int e = 0; e < ay3Result.Count; e++)
{////判断e的值来确定开始第几行写如数据
if (e == 0)
{
string cedian;
cedian = (string)ay3Result[e];
myServer = pisdk.Servers.DefaultServer;
myPoints = myServer.PIPoints;
snapPoint = myPoints[cedian];
myValue = snapPoint.Data.Snapshot;
archiveValue = snapPoint.Data.ArcValue(piTime, PISDK.RetrievalTypeConstants.rtAuto, new PISDKCommon.PIAsynchStatus());//pitime历史时间,PISDK.RetrievalTypeConstants.rtAuto是取值模式,
if (archiveValue.IsGood() == false)//PI数据库中得到数据为null,archiveValue为false;
{
this.axSpreadsheet1.Cells[e + 2, 3] = "Nodata";
this.axSpreadsheet1.Cells[e + 2, 4] = "Nodata";
}
else
{
this.axSpreadsheet1.Cells[e + 2, 3] = archiveValue.Value.ToString();
this.axSpreadsheet1.Cells[e + 2, 4] = Convert.ToDecimal(archiveValue.Value) / Convert.ToDecimal(this.textBox1.Text);
}
}
PISDK.PISDK pisdk = new PISDK.PISDKClass();
PISDK.Server myServer; // 默人服务器
PISDK.PIPoints myPoints; // 测点集合
PISDK.PIPoint snapPoint; // 测点
PISDK.PIValue myValue;//测点值
PISDK.PIValue archiveValue;//历史值
PITimeServer.PITimeFormat piTime=new PITimeServer.PITimeFormat();//pi数据库时间格式对象
string yearText = this.Datecombox.Text.Trim();//年份
string monthText = this.Monthcombox.Text.Trim();//月份
string dayText = this.Daycombox.Text.Trim();//日
string hourText = this.HourComBox.Text.Trim();//小时
string minuteText = this.Minutecombox.Text.Trim();//分钟
string queryDateString =(yearText + "-" + monthText + "-" + dayText + " " + hourText + ":" + minuteText);
piTime.InputString = queryDateString;
Excel.Application exp3 = new Excel.ApplicationClass();//打开excel进程
exp3.Visible = false;
// Hashtable table = new Hashtable();
Excel.Workbook exwork3 = exp3.Workbooks._Open(@"D:\cedian.xls",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
Excel.Worksheet xpsheet = (Excel.Worksheet)exwork3.Worksheets[1];//默认打开sheet1
ArrayList ay2 = new ArrayList();
ArrayList ay3 = new ArrayList();
ArrayList aytemp = new ArrayList();
ArrayList ay2Result = new ArrayList();
ArrayList ay3Result = new ArrayList();
for (int n = 0; n < 991; n++)
{
Excel.Range rng3 = xpsheet.get_Range(xpsheet.Cells[n + 1, 2], xpsheet.Cells[n + 1, 2]);
Excel.Range rng4 = xpsheet.get_Range(xpsheet.Cells[n + 1, 3], xpsheet.Cells[n + 1, 3]);
ay2.Add(rng3.Value2);
ay3.Add(rng4.Value2);
string changzhanText =this.ChangzhancomboBox.Text.Trim ();
string ExcelStr = (string)ay2[n];
string ExcelStr1 = (string)ay3[n];
if (ExcelStr == null && ExcelStr1==null)
continue;
else
{
if (ExcelStr.Substring(0, 3).Equals(changzhanText))
{
aytemp.Remove(changzhanText);
ay2Result.Add(rng3.Value2);
ay3Result.Add(rng4.Value2);
for (int e = 0; e < ay2Result.Count; e++)
{////判断e的值来确定开始第几行写入数据
if (e == 0)
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
else
{
this.axSpreadsheet1.Cells[e + 2, 1] = ay2Result[e];
}
}
for (int e = 0; e < ay3Result.Count; e++)
{////判断e的值来确定开始第几行写如数据
if (e == 0)
{
string cedian;
cedian = (string)ay3Result[e];
myServer = pisdk.Servers.DefaultServer;
myPoints = myServer.PIPoints;
snapPoint = myPoints[cedian];
myValue = snapPoint.Data.Snapshot;
archiveValue = snapPoint.Data.ArcValue(piTime, PISDK.RetrievalTypeConstants.rtAuto, new PISDKCommon.PIAsynchStatus());//pitime历史时间,PISDK.RetrievalTypeConstants.rtAuto是取值模式,
if (archiveValue.IsGood() == false)//PI数据库中得到数据为null,archiveValue为false;
{
this.axSpreadsheet1.Cells[e + 2, 3] = "Nodata";
this.axSpreadsheet1.Cells[e + 2, 4] = "Nodata";
}
else
{
this.axSpreadsheet1.Cells[e + 2, 3] = archiveValue.Value.ToString();
this.axSpreadsheet1.Cells[e + 2, 4] = Convert.ToDecimal(archiveValue.Value) / Convert.ToDecimal(this.textBox1.Text);
}
}
#5
这句出错了 ExcelStr.Substring(0, 3).Equals(changzhanText))
changzhanText 不足3个字符
changzhanText 不足3个字符
#6
changzhanText 这个值是Combox中的值,读出来是"宁西变"中文字符,怎么会不足3个字符!
#7
没有什么不可能的啊
加个判断前面吧
或者看看你的Combox中的值是怎么赋值进去的
加个判断前面吧
或者看看你的Combox中的值是怎么赋值进去的
#8
Combox中的值是从excle文件中读出来的,而且excel中每一列值多是跟"宁西变"这样3个中文字构成的.那为什么在我的电脑上运行一点多没出错,在测试电脑上出现这样的问题?
#9
测试电脑上可能没有读取到excle文件,或者读到的"宁西变" 是乱码等等
#10
如果是不是乱码怎么解决乱码的问题?谢谢....
#11
substring 索引id溢出
#12
怎么解决益出.?
#13
ExcelStr这个值由问题,长度没有三个。你还是在前面判断一下长度吧。
string str = string.Empty;
if(ExcelStr.Length > 3){
str = ExcelStr.Substring(0, 3);
}
else
{
str = ExcelStr;
}
if (str.Equals(changzhanText))
{ ....
string str = string.Empty;
if(ExcelStr.Length > 3){
str = ExcelStr.Substring(0, 3);
}
else
{
str = ExcelStr;
}
if (str.Equals(changzhanText))
{ ....