Question Text file search, combobox and Datagridview

Snoochie

New member
Joined
Jul 5, 2017
Messages
3
Programming Experience
Beginner
I have the following on a Winform:

- Button - to open *.txt file, code already done and works
- Combo Box - Display the dates found
- Datagridview - show information for the date selected

What code I have so far is:

C#:
private void Historybutton_Click(object sender, EventArgs e)
    {
        SSBPgroupBox.Enabled = false;
        DataTable HFdt = new DataTable();
        DialogResult result1 = openFileDialog2.ShowDialog();
    
        if (result1 == DialogResult.OK) // Test result.
        {
    
            String Fname = openFileDialog2.FileName;
            string raw_text = System.IO.File.ReadAllText(Fname);
    
    
            //add headers to datagrid view
            HFdt.Columns.Add("Sequence");
            HFdt.Columns["Sequence"].DataType = Type.GetType("System.Int32");
            HFdt.Columns.Add("Timing");
            HFdt.Columns["Timing"].DataType = Type.GetType("System.Int32");
        }
    
        HistorydataGridView.DataSource = HFdt;
    }

Sample of text file:

17/05/15-16:40:13:BLAST DRIVER ON

BLASTING PLAN

PU1053 (0005 DETS):

1/7B7C35;11/7B70B2;21/7B7058;31/7B83A1;41/7B70D1;

BLAST SUMMARY

1 PU, 00005 DETS

DELAYS MIN/MAX IN MS : 00001 / 00041

GAP MIN/MAX IN MS : 00010 / 00010

16:40:32:LINE TEST

CALIBRATION

EXTRA DETS :None

INTERMITTENT CONNECTION DETS :None

TEST DETS

MISSING DETS :None

OUT OF ORDER DETS :None

INCOHERENT DETS :None

DELAY ERRORS DETS :None

16:41:52:TEST END

16:44:02:CHARGE

CHECK ENERGIE

ADDITIONAL MISSING DETS :None

LOW ENERGY DETS :None

ADDITIONAL INCOHERENT DETS :None

16:44:29:FIRE

What I want exactly is to show the date as follows in the combo box:

17/05/15 - 0005 Dets

When the user selects this date the datagridview will show:

Sequence Timing

1 1

2 11

3 21

4 31

5 41

I have struggled finding a way to do this so any and all help will be appreciated.
 
What I want exactly is to show the date as follows in the combo box:



When the user selects this date the datagridview will show:

That's all well and good but what are the rules for extracting that information from the raw data? We can't help you write code to do something if we don't know what the something is.
 
The Something I hope

That's all well and good but what are the rules for extracting that information from the raw data? We can't help you write code to do something if we don't know what the something is.

I am going to try to answer you as best possible and hope it is the answer you need.

The user opens the file using a button.
The general format of the file is:

17/05/15-16:40:13:BLAST DRIVER ON

BLASTING PLAN

PU1053 (0005 DETS):

1/7B7C35;11/7B70B2;21/7B7058;31/7B83A1;41/7B70D1;

BLAST SUMMARY

1 PU, 00005 DETS

DELAYS MIN/MAX IN MS : 00001 / 00041

GAP MIN/MAX IN MS : 00010 / 00010

16:40:32:LINE TEST

CALIBRATION

EXTRA DETS :None

INTERMITTENT CONNECTION DETS :None

TEST DETS

MISSING DETS :None

OUT OF ORDER DETS :None

INCOHERENT DETS :None

DELAY ERRORS DETS :None

16:41:52:TEST END

16:44:02:CHARGE

CHECK ENERGIE

ADDITIONAL MISSING DETS :None

LOW ENERGY DETS :None

ADDITIONAL INCOHERENT DETS :None

16:44:29:FIRE

When the user selects the file, I want the app to search for all dates in the text file and return the dates to a Combobox showing the Date it found and the amount of dets for that date marked in BOLD in the above txt lines.
For example 17/05/15-16:40:13 - 0005 DETS

When the user selects this date from the combobox, the app will display the the information marked in red text in the above txt lines in a datagridview as follows:

1/7B7C35;11/7B70B2;21/7B7058;31/7B83A1;41/7B70D1;

changes to:


Column 1 Column 2
1 1

2 11

3 21

4 31

5 41
 
You say that you want to search for all the dates but the example you've shown only contains one. Are you saying, without actually saying, that that block of data may be repeated an arbitrary number of times, with different values? Is the line that contains the number of DETS always going to be two lines later? Is the line containing the numbers to display always the line after that? When I say "rules" I mean "rules". Code has to be specific. If you're going to write code then you need to understand your task down to the level where you can actually write instructions, e.g.

1. Read lines until finding a line starting with a date in dd/MM/yy format and extract that date.
2. Discard the next line.
3. Read the next line, which will end with a number and the word DETS in parentheses and extract the text inside those parentheses.
4. Read the following line and split on semicolons, then split each substring on a slash, extracting the first substring in each case as an integer.
5. Go to 1.

It's from instructions like that that you can write your actual code.
 
Ok rules:

1. This is an extract from the txt file and it contains up to 10 dates and their information.
2. The number of DETS is always 2 lines later.
Another extract from the file is as follows:

17/04/20-17:27:30:BLAST DRIVER ON
-
BLASTING PLAN
PU0527 (0295 DETS):
1539/F53F23;2031/115544;1588/117A35;2080/11541C;1637/F5363C;2129/11921B;1686/119026;2178/F59E70;1735/F5729B;2227/F57D20;
1784/F61B6B;2276/F5EE45;1833/F536D8;2325/F57F47;1882/F548E5;2374/F53E56;1931/F5B4C7;2423/F5937F;1980/F58F0F;2472/F5A73F;
2029/F5FDDE;2521/F5A179;2078/F57D0E;2570/F5978B;2127/F5EED3;2619/F5D16E;2176/F593F4;2668/F5787D;2225/F59955;2717/F5E8FD;
2274/F5A463;2766/F5ECF7;2323/F60166;2815/F5404D;2372/F54295;2864/F53964;2421/F59F94;2913/F591DD;2470/F59494;2962/F5E7D2;
1155/F59B81;1347/F542EA;1204/F53E47;1396/F52FA6;1253/F61F2D;1445/F540EC;1302/F5EBBB;1494/F5E9CF;1351/F52F0C;1543/F53CE4;
1400/F5356D;1592/F5E232;1449/F57047;1641/F54849;1498/F541B9;1690/F5860C;1547/F5387B;1739/F5E765;1596/F5999C;1788/F5F3A8;
1645/F572DB;1837/F5B238;1694/F5F378;1886/F5F205;1743/F537CC;1935/F53DFD;1792/F5C886;1984/F5776A;1841/F56E6C;2033/F58688;
1890/F5AB3D;2082/F598BB;1939/F542D4;2131/F5F4F1;1988/F57DFA;2180/F57C7C;2037/F53477;2229/F57762;2086/F53121;2278/F539DA;
771/F53B40;963/F530DB;820/F5326B;1012/F5358E;869/F546F4;1061/F53FC1;918/F541E0;1110/F5382C;967/F53E72;1159/11E241;
1016/115568;1208/F57880;1065/11E700;1257/118E17;1114/1152FF;1306/1155EB;1163/F56FFB;1355/11FE42;1212/F5717E;1404/F54D1E;
1261/F570B7;1453/F53A85;1310/F574E4;1502/F574CD;1359/F5356A;1551/F53926;1408/F53CAD;1600/F53F3B;1457/F572B5;1649/F53060;
1506/F5F2BB;1698/F5A921;1555/F5F2B5;1747/F5B1F2;1604/F537D3;1796/F58111;1653/F61A00;1845/F5742E;1702/F5750D;1894/F53C31;
387/F53C7C;579/F5734E;436/F53C60;628/F57021;485/F5E5CF;677/F5E94F;534/F57792;726/F53DA1;583/F5E5E6;775/F5B34F;
632/F53C41;824/F53CBE;681/F57763;873/F57723;730/F57182;922/F57701;779/F53A83;971/F534D0;828/F547A7;1020/F5B598;
877/F53E13;1069/F53686;926/F5462F;1118/F5720F;975/F533C7;1167/F57308;1024/F5702F;1216/F58233;1073/F5E30D;1265/F5726B;
1122/F53745;1314/F57545;1171/F58E6A;1363/F5987D;1220/F54D91;1412/F5ABF3;1269/F54440;1461/F537F4;1318/F57C31;1510/F57749;
1367/F56EC2;1559/F5EF73;1416/F59059;1608/F59D79;1465/F5493E;1657/F56ED2;1514/F53235;1706/F543FD;1563/F61C7C;1755/F52F99;
1612/F5467C;1804/F57877;1661/F543C3;1853/F5F5E3;1710/F58CDA;1902/F5F651;1759/F545EE;1951/F57023;1808/F58099;2000/F534DA;
1751/F59824;1943/F57B0E;1800/F5490C;1992/F54532;1849/F541C6;2041/F59309;1898/F53E9D;2090/F53BBD;1947/F5FB8D;2139/F56E31;
1996/F57FDD;2188/F59B54;2045/F598E4;2237/F597A0;2094/F5703E;2286/F5F2FF;2143/F57326;2335/F572BE;2192/F54086;2384/F53C22;
2135/F61800;2327/F58249;2184/F571C0;2376/F5816A;2233/F61F28;2425/F573FC;2282/F60FEE;2474/F58974;2331/F5972B;2523/F59711;
2380/F57403;2572/F53769;2429/F61BC5;2621/F5E4D8;2478/F57CB7;2670/F53ADF;2527/F59FF7;2719/F5E07F;2576/F5ED50;2768/F5952E;
2519/F5B499;3011/F58F1E;2568/F5394E;3060/F599E7;2617/F57976;3109/F548FE;2666/F5AECE;3158/F540DB;2715/F5B2BE;3207/F537B3;
2764/F5AE12;3256/F61A28;2813/F548EE;3305/F57A99;2862/F61DF2;3354/F5AA16;2911/F5901C;3403/F57D9F;2960/F54D4F;3452/F5997E;
3009/F57A3F;3501/F59FB3;3058/F59A2B;3550/F5BDF6;3107/F5763A;3599/F53055;3156/F5A115;3648/F577EF;3205/F54117;3997/F5F542;
3554/F61B24;2625/F59DF7;2817/F576F2;2674/F57F5B;2866/F5A03C;2723/F5E514;2915/F61FC3;2772/F59C84;2964/F5C82E;2821/F5342D;
3013/F5F1B1;2870/F570C0;3362/F54206;3219/F5EDC2;2241/F56F81;2433/F59F2A;2290/F53528;2482/F54550;2339/F57F1B;2531/F57FDC;
2388/F5EE98;2580/F572FA;2437/F53B6C;2486/F5B0B7;2486/F5A84A;2294/F53F7C;2629/F53726;2678/F57E70;2678/F57AFA;2835/F61778;
3027/F5B596;3027/F5B2E0;1857/F57FD5;2049/F5F69E;1906/F5813D;2098/F57933;1955/F5868B;2147/F57975;2004/F5AA5E;2196/F54B1E;
2053/F57120;2245/F53DBE;2102/F58F77;2451/F5AD8F;2643/F53160;
PU0528 (0272 DETS):
2029/F58D7F;1537/F5AA3F;2078/F5AB37;1586/F57F5C;2127/F5B00E;1635/F53F41;2176/F53F5D;1684/F54236;2225/F53079;1733/F56F35;
2274/F581A0;1782/12F43C;2323/12C912;1831/1315B0;2372/12EC84;1880/12CFE6;2421/12EC57;1929/12F4A9;2470/12ECAC;1978/131A82;
2519/131D1A;2027/12D392;2568/12C961;2076/12CB4B;2617/1316C9;2125/12CFAA;2666/12CA7E;2174/12D423;2715/1153CE;2223/1151DB;
2764/115334;2272/12D473;2813/131975;2321/115381;2862/117A0D;2370/131AF0;2911/114AB8;2419/115482;2960/119A66;2468/128098;
3009/1191A7;2517/12ED0B;3058/115645;2566/13156A;3107/11D9ED;2615/12CFF4;3156/12CFB3;2664/13196A;3205/12D53A;2713/131B16;
3254/115638;2762/11538E;3303/12CF54;2811/12D55A;3352/115683;2860/114B30;3401/114A73;2909/1319F9;3450/11DA6A;2958/131A52;
3499/114027;3007/131A08;3548/11BCF2;3056/117945;3597/131AA8;3105/1179B7;3646/119222;3154/131AA0;3995/1150DA;3503/117911;
1345/F53CC8;1153/F5B196;1394/F57499;1202/F54AC4;1443/F587AE;1251/F59B42;1492/12F417;1300/131A84;1541/12F40D;1349/12D6DA;
1590/12C41D;1398/12ED14;1639/12F3F7;1447/131A76;1688/131C2C;1496/12D424;1737/12C5D6;1545/131D5B;1786/12EC91;1594/12C9DC;
1835/131CCD;1643/12CA16;1884/12B8CE;1692/12C3D3;1933/12D372;1741/12CA87;1982/131AED;1790/12CE89;2031/131C03;1839/1322E3;
2080/13235C;1888/1322B7;2129/1314B6;1937/1322A8;2178/132333;1986/1315B1;2227/1314FC;2035/13234B;2276/1315AA;2084/1322C3;
2325/13232B;2133/1323DC;2374/12D022;2182/1316A2;2423/12CB39;2231/12CDDC;2472/131AE1;2280/12CE10;2521/1315E6;2329/12CC72;
2570/12EBFC;2378/12EC19;2619/12CE6B;2427/12EC43;2668/12CA62;2476/12CE52;2717/12CE99;2525/12CAF4;2766/12F402;2574/12D051;
2815/12CE03;2623/12CB15;2864/131A2C;2672/12EC59;2913/115618;2721/12EC13;2962/125658;3070/115108;3311/12CFA4;3311/12CF89;
961/F5702A;769/F5E34A;1010/F57710;818/F5741C;1059/F544A6;867/F53685;1108/F5D7CD;916/1324E5;1157/12EC71;965/131A5B;
1206/131A88;1014/12CB1B;1255/12ECE8;1063/12F3E6;1304/131AD0;1112/12C9B4;1353/131D1D;1161/12ECC7;1402/12C90F;1210/12EC10;
1451/131CF5;1259/12B852;1500/12ECED;1308/13163D;1549/12EC2D;1357/12EBDF;1598/12CDF9;1406/1314C7;1647/131701;1455/131586;
1696/132389;1504/131E4B;1745/1322E4;1553/1326B0;1794/132325;1602/1326E6;1843/1322BC;1651/11E696;1892/1153DE;1700/119147;
1941/119D53;1749/11568F;1990/1315EC;1798/11530D;2039/131474;1847/131AEC;2088/12CED1;1896/12CE2E;2137/12CC67;1945/12CDFA;
2186/12CBD0;1994/12CE48;2235/12EBD3;2043/12EBE5;2284/12EC40;2092/131953;2333/12EC29;2141/12D02F;2382/12F373;2190/12CE0B;
2431/12C925;2239/12ED0A;2480/12CE30;2288/12CB02;2529/12D53D;2637/12CB67;2878/12C949;577/F56FCC;385/F53B45;626/F54405;
434/F54BFA;675/F5E5D6;483/F53FD5;724/F54AC6;532/F54298;773/12C95F;581/12C934;822/131A60;630/12CAB7;871/12C955;
679/131956;920/132055;728/13161F;969/131C7F;777/12C551;1018/12C55D;826/12EC94;1067/12B939;875/12EC26;1116/132092;
924/12CF06;1165/131FA3;973/12D0D2;1214/132294;1022/1322BE;1263/132352;1071/13238B;1312/131527;1120/131DBC;1361/13154D;
1169/1323D1;1410/1326B3;1218/1322D9;1459/132309;1267/1150D0;1508/1155E2;1316/11519B;1557/118EB9;1365/115234;1606/115463;
1414/12CE56;1655/12CEBD;1463/12CBBF;1704/12CB58;1512/12CE2F;1753/12F357;1561/12F41B;1802/131B04;1610/12CEEC;1851/12C8B8;
1659/12F38B;1900/12CC1C;1708/12CE38;1949/12CC40;1757/12CBC7;1998/12CC2D;1806/12D238;2047/12C8FE;2155/12D4E5;2155/12D160;
2396/12C8DC;2396/12D0A0;
-
BLAST SUMMARY
2 PU, 00567 DETS
DELAYS MIN/MAX IN MS : 00385 / 03997
GAP MIN/MAX IN MS : 00000 / 00347
-
17:27:56:LINE TEST

3. The lines after that could be upto 3 PU and 1500 DETS per PU that needs to be split as a substring on a slash in each case as an integer

I am sorry, I am really new to programming and I am trying to teach myself to ease my workload.
 
You say that you want to search for all the dates but the example you've shown only contains one. Are you saying, without actually saying, that that block of data may be repeated an arbitrary number of times, with different values? Is the line that contains the number of DETS always going to be two lines later? Is the line containing the numbers to display always the line after that? When I say "rules" I mean "rules". Code has to be specific. If you're going to write code then you need to understand your task down to the level where you can actually write instructions, e.g.

1. Read lines until finding a line starting with a date in dd/MM/yy format and extract that date.
2. Discard the next line.
3. Read the next line, which will end with a number and the word DETS in parentheses and extract the text inside those parentheses.
4. Read the following line and split on semicolons, then split each substring on a slash, extracting the first substring in each case as an integer.
5. Go to 1.

It's from instructions like that that you can write your actual code.
 

Latest posts

Back
Top Bottom