Note that there are some explanatory texts on larger screens.

plurals
  1. POwhile loop not outputting all information from two files
    text
    copied!<p>This may not be a very good question, but I am trying to output two files to one CSV file. I'm using a <code>while</code> loop to read through the two files, and then I'm calling a method that prints it all out, but when it prints out, I'm not getting all of the information that is in both of the files. Here is my <code>while</code> loop code:</p> <pre><code>private void mergeBtn_Click(object sender, EventArgs e) { if (System.IO.File.Exists("OUTPUT.csv")) { System.IO.File.Delete("OUTPUT.csv"); output = new System.IO.StreamWriter("OUTPUT.csv"); } else { output = new System.IO.StreamWriter("OUTPUT.csv"); } String[] head = File.ReadAllLines(textBox3.Text); //header file array foreach (string h in head) { output.WriteLine(QuoteString(h)); } input = new StreamReader(textBox1.Text); input2 = new StreamReader(textBox2.Text); String line, templeaseName2, tempfieldName2, tempreservoir2, tempoperator2, tempcounty2, tempstate2, tempmajo2, tempReserveCat2, tempDiscountRate2, tempnetOil2Int2, tempnetGas2Int2, tempworkingInt2 , tempgrossWells2, tempultOil2, tempultGas2, tempgrossOil2, tempgrossNGL2, tempgrossGas2, tempnetOil2, tempnetGas2, tempnetNGL2, temprevToInt2, tempoperExpense2, temptotInvest2, temprevOil2 , temprevGas2, tempoperatingProfit2, temprevNGL2, tempDiscNetInc, tempseqNum2, tempwellID2, tempincASN2, templifeYears2, tempownQual2, tempprodTax2, tempAdValorem2; while ((line = input2.ReadLine()) != null || (line = input.ReadLine()) != null) { templeaseName2 = line.Substring(0, 33); tempfieldName2 = line.Substring(33, 33); tempreservoir2 = line.Substring(66, 21); tempoperator2 = line.Substring(87, 25); tempcounty2 = line.Substring(112, 21); tempstate2 = line.Substring(133, 2); tempmajo2 = line.Substring(136, 3); tempReserveCat2 = line.Substring(141, 4); tempDiscountRate2 = line.Substring(146, 6); tempnetOil2Int2 = line.Substring(152, 10); tempnetGas2Int2 = line.Substring(162, 10); tempworkingInt2 = line.Substring(172, 10); tempgrossWells2 = line.Substring(182, 6); tempultOil2 = line.Substring(188, 14); tempultGas2 = line.Substring(202, 14); tempgrossOil2 = line.Substring(216, 14); tempgrossNGL2 = line.Substring(230, 14); tempgrossGas2 = line.Substring(244, 14); tempnetOil2 = line.Substring(258, 14); tempnetGas2 = line.Substring(272, 14); tempnetNGL2 = line.Substring(286, 14); temprevToInt2 = line.Substring(300, 14); tempoperExpense2 = line.Substring(314, 14); temptotInvest2 = line.Substring(328, 14); temprevOil2 = line.Substring(342, 14); temprevGas2 = line.Substring(356, 14); tempoperatingProfit2 = line.Substring(370, 14); temprevNGL2 = line.Substring(384, 14); tempDiscNetInc = line.Substring(398, 14); tempseqNum2 = line.Substring(412, 6); tempwellID2 = line.Substring(418, 6); tempincASN2 = line.Substring(425, 6); templifeYears2 = line.Substring(432, 6); tempownQual2 = line.Substring(439, 9); tempprodTax2 = line.Substring(449, 13); tempAdValorem2 = line.Substring(462, 14); add(templeaseName2, tempfieldName2, tempreservoir2, tempoperator2, tempcounty2, tempstate2, tempmajo2, tempReserveCat2, tempDiscountRate2, tempnetOil2Int2, tempnetGas2Int2, tempworkingInt2, tempgrossWells2, tempultOil2, tempultGas2, tempgrossOil2, tempgrossNGL2, tempgrossGas2, tempnetOil2, tempnetGas2, tempnetNGL2, temprevToInt2, tempoperExpense2, temptotInvest2, temprevOil2, temprevGas2, tempoperatingProfit2, temprevNGL2, tempDiscNetInc, tempseqNum2, tempwellID2, tempincASN2, templifeYears2, tempownQual2, tempprodTax2, tempAdValorem2); } printAll(); input.Close(); input2.Close(); output.Close(); } </code></pre> <p>I am really not sure why it is not outputting all of the information in the files, any help would be much appreciated. And I'll put my <code>printall();</code> method in here just in case that's where the problem is as well: </p> <pre><code>public void printAll() { output.WriteLine(); output.WriteLine(); output.WriteLine(); output.WriteLine("Lease Name, Field Name, Reservoir, Operator, County, ST, Majo, Resv Cat, Discount Rate, Net Oil Interest, Net Gas Interest, Working Interest, Gross Wells, Ultimate Oil, Ultimate Gas, Gross Oil, Gross NGL, Gross Gas, Net Oil, Net Gas, Net NGL, Revenue To Int., Oper. Expense, Total Invest., Revenue Oil, Revenue Gas, Operating Profit, Revenue NGL, Disc Net Income, SEQ, Well ID, INC ASN, Life Years, Own Qual, Production Tax, Ad Valorem Tax"); int i = listHead2; //Loops until the end of the list, printing out info while (i != -1) { output.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}", QuoteString(leaseName2[i]), fieldName2[i], QuoteString2(reservoir2[i]), operator2[i], county2[i], state2[i], majo2[i], resvCatgory2[i], disRate2[i], netOil2Int2[i], netGas2Int2[i], workingInt2[i], grossWells2[i] , ultOil2[i], ultGas2[i], grossOil2[i], grossNGL2[i], grossGas2[i], netOil2[i], netGas2[i], netNGL2[i], revToInt2[i], operExpense2[i], totInvest2[i], revOil2[i], revGas2[i], operatingProfit2[i], revNGL2[i], discNetIncome2[i], seqNum2[i], wellID2[i], incASN2[i], lifeYears2[i], ownQual2[i], prodTax2[i], AdValorem2Tax2[i]); i = pointers2[i]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload