Private Sub BreakdownFilesToCompare (ByRef file1BReader As BinaryReader, _
ByRef file2BReader As BinaryReader, _
ByRef firstFile As StandardFormatFile, _
ByRef secondFile As StandardFormatFile)
file1BReader.ReadInt32()< br /> file2BReader.ReadInt32()
firstFile.numberOfSeries = file1BReader.ReadInt32
secondFile.numberOfSeries = file2BReader.ReadInt32
If firstFile.numberOfSeries <> secondFile. numberOfSeries Then
WriteToConsole("The number of Elements the two files do not match...Stopping")
Exit Sub
End If
For i As Integer = 0 To firstFile.numberOfSeries-1
Dim tempSeriesData1 As New StandardFormatFileSeries
Dim tempSeriesData2 As New StandardFormatFileSeries
tempSeriesData1.standardNumOfElements = file1BReader.ReadInt32
tempSeriesData1.standardSeriesName = GetSeriesName(file1BReader)
tempSeriesData2.standardNumOfElements = file2BReader.ReadInt32
tempSeriesData2.standard (file2BReader)
For j As Integer = 0 To tempSeriesData1.standardNumOfElements-1
Dim tempElementData1 As New StandardFormatFileElement
tempElementData1. standardX_TimeValue = file1BReader.ReadSingle
tempElementData1.standardY_SampleValue = file1BReader.ReadSingle
tempSeriesData1.standardDataElements.Add(tempElementData1)
Next
For k As Integer = 0 To tempSeriesData2. standardNumOfElements-1
Dim tempElementData2 As New StandardFormatFileElement
tempElementData2.standardX_TimeValue = file2BReader.ReadSingle
tempElementData2.standardY_SampleValue = file2BReader.ReadSingle
tempSeriesData2.standardDataElements.Add(tempElementData2)
Next
firstFile. standardSeriesData.Add(tempSeriesData1)
secondFile.standardSeriesData.Add(tempSeriesData2)
Next
End Sub
Private Function GetSeriesName(ByRef bReader As BinaryReader) As String
Dim enc As New System.Text.UTF8Encoding()
Dim title As Byte()
title = bReader.ReadBytes(128 )
Return enc.GetString(title)
End Function
Now this is what I have in C#
private void compareStandardFormat(ref BinaryReader file1breader,ref BinaryReader file2breader,
ref FileStructure firstfile,ref FileStructure secondfile)
{
file1breader.ReadInt32();
file2breader.ReadInt32( );
firstfile .numberofseries = file1breader.ReadInt32();
secondfile.numberofseries = file2breader.ReadInt32();
if (firstfile.numberofseries != secondfile.numberofseries)
{
writeToConsole("The number of Elements the two files do not match...Stopping");
return;
}
for (int i = 0; i{
StandardFormatFileSeries tempseriesdata1 = new StandardFormatFileSeries();
StandardFormatFileSeries tempseriesdata2 = new StandardFormatFileSeries();
tempseriesdata1.standardnumofelements = file1breader. ReadInt32();
tempseriesdata1.standardseriesname = getSeriesName(ref file1breader).Trim();
tempseriesdata2.standardnumofelements = file2breader.ReadInt32();
tempseriesdata2.seriesstandardname = getSeriesName( ref file2breader).Trim();
for (int j = 0; j{
StandardFormatFileElement tempElementData1 = new StandardFormatFileElement();
tempElementData1.standardx_timevalue = Convert.ToString ( file1breader.ReadSingle());
tempElementData1.standardy_samplevalue = Convert.ToString(file1breader.ReadSingle());
tempseriesdata1.standarddataelements.Add(tempElementData1);
}
for (int k = 0; k{
StandardFormatFileElement tempElementData2 = new StandardFormatFileElement();
tempElementData2. standardx_timevalue = Convert.ToString(file2breader.ReadSingle());
tempElementData2.standardy_samplevalue = Convert.ToString(file2breader.ReadSingle());
tempseriesdata2.standarddatae lements.Add(tempElementData2);
}
firstfile.standardseriesdata.Add(tempseriesdata1);
secondfile.standardseriesdata.Add(tempseriesdata2);
}
}
private string getSeriesName(ref BinaryReader bReader)
{
UTF8Encoding enc = new UTF8Encoding();
byte[] title;
title = bReader.ReadBytes(128);
return enc.GetString(title);
}
The VB method is correct Read the binary reader and index to the next position correctly… C# doesn’t work. It lost track after the first iteration… Why???
Please help.
For i As Integer = 0 To firstFile.numberOfSeries-1
for (int i = 0; iI think the direct C# translation is:
for (int i = 0; i <= firstfile.numberofseries-1; i++)or better:
for (int i = 0; i
Newbie to C# and trying to expand my abilities. I have this code in VB:
Private Sub BreakdownFilesToCompare(ByRef file1BReader As BinaryReader, _
ByRef file2BReader As BinaryReader, _
ByRef firstFile As StandardFormatFile, _
ByRef secondFile As StandardFormatFile)
file1BReader.ReadInt32()
file2BReader.ReadInt32()
firstFile.numberOfSeries = file1BReader.ReadInt32
secondFile.numberOfSeries = file2BReader.ReadInt32
If firstFile.numberOfSeries <> secondFile.numberOfSeries Then
WriteToConsole("The number of Elements the two files do not match...Stopping")
Exit Sub
End If
For i As Integer = 0 To firstFile.numberOfSeries-1
Dim tempSeriesData1 As New StandardFormatFileSeries
Dim tempSeriesData2 As New StandardFormatFileSeries
tempSeriesDa ta1.standardNumOfElements = file1BReader.ReadInt32
tempSeriesData1.standardSeriesName = GetSeriesName(file1BReader)
tempSeriesData2.standardNumOfElements = file2BReader.ReadInt32
tempSeriesData2.standardSeriesName = GetSeriesName(file2BReader)
For j As Integer = 0 To tempSeriesData1.standardNumOfElements-1
Dim tempElementData1 As New StandardFormatFileElement
tempElementData1.standardX_TimeValue = file1BReader.ReadSingle
tempElementData1.standardY_SampleValue = file1BReader.ReadSingle
tempSeriesData1.standardDataElements.Add(tempElementData1)
Next
For k As Integer = 0 To tempSeriesData2.standardNumOfElements-1
Dim tempElementData2 As New StandardFormatFileElement
tempElementData2.standardX_TimeValue = file2BReader.ReadSingle
tempElementData2.stand ardY_SampleValue = file2BReader.ReadSingle
tempSeriesData2.standardDataElements.Add(tempElementData2)
Next
firstFile.standardSeriesData. Add(tempSeriesData1)
secondFile.standardSeriesData.Add(tempSeriesData2)
Next
End Sub
Private Function GetSeriesName (ByRef bReader As BinaryReader) As String
Dim enc As New System.Text.UTF8Encoding()
Dim title As Byte()
title = bReader.ReadBytes(128)< br /> Return enc.GetString(title)
End Function
Now this is what I have in C#
private void compareStandardFormat(ref BinaryReader file1breader,ref BinaryReader file2breader,
ref FileStructure firstfile,ref FileStructure secondfile)
{
file1breader.ReadInt32();
file2breader.ReadInt32();
firstfile.numberofseries = file1breader.Re adInt32();
secondfile.numberofseries = file2breader.ReadInt32();
if (firstfile.numberofseries != secondfile.numberofseries)
{
writeToConsole("The number of Elements the two files do not match...Stopping");
return;
}
for (int i = 0; i{
StandardFormatFileSeries tempseriesdata1 = new StandardFormatFileSeries();
StandardFormatFileSeries tempseriesdata2 = new StandardFormatFileSeries();
tempseriesdata1.standardnumofelements = file1breader.ReadInt32();< br /> tempseriesdata1.standardseriesname = getSeriesName(ref file1breader).Trim();
tempseriesdata2.standardnumofelements = file2breader.ReadInt32();
tempseriesdata2.standardseriesname = getSeriesName(ref file2breader).Trim ();
for (int j = 0; j{
StandardFormatFileElement tempElementData1 = new StandardFormatFileElement();
tempElementData1.standardx_timevalue = Convert.ToString (file1breader.ReadSingle());
tempElementData1.standardy_samplevalue = Convert.ToString(file1breader.ReadSingle());
tempseriesdata1.standarddataelements.Add(tempElementData1);
}
for (int k = 0; k{
StandardFormatFileElement tempElementData2 = new StandardFormatFileElement();
tempElementData2.standardx_timevalue = Convert.ToString(file2breader.ReadSingle ());
tempElementData2.standardy_samplevalue = Convert.ToString(file2breader.ReadSingle());
tempseriesdata2.standarddataelements.Add(tempElementData2);
}
firstfile.standardseriesdata.Add(tempseriesdata1);
secondfile.standardseriesdata.Add(tempseriesdata2);
}
}
private string getSeriesName(ref BinaryReader bReader)
{
UTF8Encoding enc = new UTF8Encoding();
byte[] title;
title = bReader .ReadBytes(128);
return enc.GetString(title);
}
The VB method correctly reads the binary reader and indexes it correctly The next position... C# doesn’t work. It lost track after the first iteration... Why???
Please help.
< p>I think these are different:
For i As Integer = 0 To firstFile.numberOfSeries-1
for (int i = 0; iI think the direct C# translation is:
for (int i = 0; i <= firstfile.numberofseries -1; i++)Or better:
for (int i = 0; i< /p>