0

could anyone please help me with this1. Create a simple Times Table program which will allow the user to enter an integer value n (between 1 and 20) into a textbox. On the click of a button output to a label the n times tables. Use a For…Next loop to perform the repetition.

i can output them to a list box but only last one to a label ive been stuck for 3 days any help would be much appreciated

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ssommaro
0

I have a solution here, but this sounds like homework. Post your code and we'll see if we can tell you where you could improve it.

0

---VB.NET---

Have you thought about using an empty placeholder in your aspx page, and then populating it dynamically when the user presses the button?

What you need is this:

in your aspx:

<asp:Placeholder runat="server" id="phTimesTable"></Placeholder>

(this will be in effect an empty box, but the placeholder by its own nature can contain a collection of controls - which you can manage through code).

Then in your code behind attached to the button:

for i=1 to 12
   Dim strPrintOnScreen as String = i & " x " & me.tbUserInput.Text &  " = " & i * me.tbUserInput.Text 
   Me.phTimesTable.Controls.Add(New LiteralControl("<p>" & strPrintOnScreen & "</p>")
   Next

(You may want to validate that the input is a valid number or the multiplication will crash).
This way you add a <p></p> for each entry, but you can use the add(New literalcontrol) to add any valid html.

Edited by ssommaro: added [CODE] tag to prevent smilies in the code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.