In: Computer Science
Using C# visual basics
Can someone show a calculator with a button that does a FOR LOOP about 10x time and does a print out of a name 10x
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Visula Basic :
Here a new Windows Forms Application in VB is created using Visual Studio 2017 with name "CalculatorForLoop".This application contains a form with name "Form1.vb".Below are the files associated with form1.
1.Form1.vb[Design]
2.Form1.vb
Public Class Form1
'button name click
Private Sub btnName_Click(sender As Object, e As EventArgs) Handles
btnName.Click
'taking name entered by user
Dim name As String = txtName.Text
'using for loop print name
For index = 1 To 10
'concate and print names entered by the user
lblNames.Text = lblNames.Text & name & " " &
Environment.NewLine
Next
End Sub
End Class
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2 :Screen when user enters the name
********************************************************************
C# :
Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "PrintNamesApp".This application contains a form with name "Form1.cs".Below are the files associated with form1.
1.Form1.cs[Design]
2.Form1.cs
//namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//application namespace
namespace PrintNamesApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//button name click
private void btnName_Click(object sender, EventArgs e)
{
//taking name entered by user
string name = txtName.Text;
//using for loop print name
for (int i = 0; i < 10; i++)
{
//using for loop print name
lblNames.Text += name + " " + Environment.NewLine;
}
}
}
}
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2 :
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.