<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        mso-fareast-language:EN-US;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:595.0pt 842.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-AU" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA">Hi Michael,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA">I can’t say what is right or wrong but personally I do tend to find input box popping up from a loop consecutively very annoying. Another way this could be implemented
 is to use one textbox, one add button and a ListBox.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA">Code as follows<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;mso-fareast-language:JA">List</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&lt;</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&gt;
 lst = </span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">new</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;mso-fareast-language:JA">List</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&lt;</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&gt;();</span><span style="font-size:9.5pt;font-family:Consolas;color:green;mso-fareast-language:JA">//global
 list of int</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">private</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">void</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> btnAddItem_Click_1(</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">object</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">
 sender, </span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;mso-fareast-language:JA">EventArgs</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> e){<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lst.Add(</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">.Parse(txtInput.Text));</span><span style="font-size:9.5pt;font-family:Consolas;color:green;mso-fareast-language:JA">//add
 to list</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtInput.Text =
</span><span style="font-size:9.5pt;font-family:Consolas;color:#A31515;mso-fareast-language:JA">&quot;&quot;</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">;
</span><span style="font-size:9.5pt;font-family:Consolas;color:green;mso-fareast-language:JA">//clear for next input</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:9.5pt;font-family:Consolas;color:green;mso-fareast-language:JA">//listBox display should always reflect the array</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lstToListBox(lst,
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">ref</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> lstDisplay);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:9.5pt;font-family:Consolas;color:green;mso-fareast-language:JA">//clear and repropagates listbox display</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">private</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">void</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> lstToListBox(</span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;mso-fareast-language:JA">List</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&lt;</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&gt;
 lst, </span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">ref</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">
</span><span style="font-size:9.5pt;font-family:Consolas;color:#2B91AF;mso-fareast-language:JA">ListBox</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> listBox) {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listBox.Items.Clear();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">foreach</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> (</span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">int</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">
 item </span><span style="font-size:9.5pt;font-family:Consolas;color:blue;mso-fareast-language:JA">in</span><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA"> lst)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listBox.Items.Add(item.ToString());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:JA">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA">Some disadvantages with the lstToListBox procedure, not efficient as it keeps clearing and re-adding old stuff on call which is redundant and refreshes can be noticeable
 when lists are sufficiently large. Advantage: well could easily replace the procedure for another display type and not need to worry about discrepancies in the list and listbox. Also can reuse the procedure in other buttons like delete etc. Hope that helped.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA">Lony<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:JA">From:</span></b><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:JA"> sofdev-bounces@edulists.com.au [mailto:sofdev-bounces@edulists.com.au]
<b>On Behalf Of </b>Cooper, Michael J<br>
<b>Sent:</b> Monday, 6 February 2017 12:58 PM<br>
<b>To:</b> Year 12 Software Development Teachers' Mailing List &lt;sofdev@edulists.com.au&gt;<br>
<b>Subject:</b> [Year 12 SofDev] C# - Adding data to an Array from user input<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Hello fellow SD teachers,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">C# coding question - what is the best way to allow a USER to enter data into an array using a GUI, not the console?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">I’ve used InputBoxes and loops with Visual Basic, however InputBoxes don’t seem to be thing in C#, without adding the Microsoft.VisualBasic namepace.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">I can add data to an array during design time easily enough, but I want the USER to be able to click on a button and be prompted to enter data, which then populates the array.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Or am I going about this the wrong way entirely and should be using another technique?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:&quot;Times New Roman&quot;,serif;mso-fareast-language:EN-GB">Michael Cooper<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:&quot;Times New Roman&quot;,serif;mso-fareast-language:EN-GB">ICT Co-ordinator &amp; Network Support<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:&quot;Times New Roman&quot;,serif;mso-fareast-language:EN-GB"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:&quot;Times New Roman&quot;,serif;mso-fareast-language:EN-GB"><img width="223" height="37" id="_x0000_i1025" src="cid:image001.png@01D28306.1B8466B0" alt="id:image001.png@01D2440D.0D6FCCA0"><o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:&quot;Times New Roman&quot;,serif"><a href="http://www.Braybrooksc.vic.edu.au">braybrooksc.vic.edu.au</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:&quot;Times New Roman&quot;,serif">Ph. 9312 2900<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-GB"><o:p>&nbsp;</o:p></span></p>
<table class="MsoNormalTable" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background:white;padding:.75pt .75pt .75pt .75pt">
<pre><span style="color:black">IMPORTANT - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Training.<o:p></o:p></span></pre>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-family:&quot;Times New Roman&quot;,serif;mso-fareast-language:JA"><o:p>&nbsp;</o:p></span></p>
</div>
</body>
</html>

<table><tr><td bgcolor=#ffffff><font color=#000000><pre>IMPORTANT - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Training.</pre></font></td></tr></table>