Question

In: Computer Science

This is done using Visual Basic. Add three text boxes and three buttons to the form....

This is done using Visual Basic.

Add three text boxes and three buttons to the form. Set the second and third text boxes' Multiline, ReadOnly, and ScrollBars properties to True, True, and Vertical, respectively. The user will enter a number in the first text box and them click the first button. The first buttons click event procedure should write the number on a seperate line in a sequential access file. The second button's click event procedure should read the entire sequential access file at once, and display the file's contents in the third text box; display each number on a separate line. Code the procedures. Save the solution and start the application. Use the first button to write any six numbers to the file. Then, use the second and third buttons to display the contents of the file in their respective text boxes. Close the solution.

Solutions

Expert Solution

In case of any query do comment. Please rate answer as well. Thanks

Note: You didn’t mention the functionality of Third button and second text box. Please do let me know via comment if you require anything for Third button. Right now I am just outputting, on the click of third button push the data to Second text box

Code:

=======Form1.vb======

Imports System.IO

Public Class Form1
Dim data() As String
'handles the click of Button 2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'StreamWrite is used to write lines to the file opened by AppendText
Using writer As StreamWriter = File.AppendText("C:\display.txt")
'Write the content of a text box
writer.WriteLine(TextBox1.Text)
End Using
TextBox1.Clear()
End Sub
'handles the click of Button 2
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'assign the ReadData output to Text box 2
TextBox2.Text = ReadData()
End Sub
'Read the data from the file and join it using new line and return the data
Private Function ReadData() As String
data = File.ReadAllLines("C:\display.txt")
ReadData = Join(data, System.Environment.NewLine)
End Function
'function to read file line by line
Private Function ReadDataLineByLine() As String
Dim reader As StreamReader = My.Computer.FileSystem.OpenTextFileReader("C:\display.txt")
Dim line As String
Do
line = reader.ReadLine
data.Append(line)
Loop Until line Is Nothing
reader.Close()
ReadDataLineByLine = Join(data, System.Environment.NewLine)
End Function
'handles the click of Button 3
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'assign the ReadData output to Text box 3
TextBox3.Text = ReadDataLineByLine()
End Sub
End Class

=====from1.designer.vb========

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Partial Class Form1

    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.

    <System.Diagnostics.DebuggerNonUserCode()> _

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)

        Try

            If disposing AndAlso components IsNot Nothing Then

                components.Dispose()

            End If

        Finally

            MyBase.Dispose(disposing)

        End Try

    End Sub

    'Required by the Windows Form Designer

    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer

    'It can be modified using the Windows Form Designer.

    'Do not modify it using the code editor.

    <System.Diagnostics.DebuggerStepThrough()> _

    Private Sub InitializeComponent()

        Me.TextBox1 = New System.Windows.Forms.TextBox()

        Me.TextBox2 = New System.Windows.Forms.TextBox()

        Me.TextBox3 = New System.Windows.Forms.TextBox()

        Me.Button1 = New System.Windows.Forms.Button()

        Me.Button2 = New System.Windows.Forms.Button()

        Me.Button3 = New System.Windows.Forms.Button()

        Me.SuspendLayout()

        '

        'TextBox1

        '

        Me.TextBox1.Location = New System.Drawing.Point(74, 76)

        Me.TextBox1.Name = "TextBox1"

        Me.TextBox1.Size = New System.Drawing.Size(180, 26)

        Me.TextBox1.TabIndex = 0

        '

        'TextBox2

        '

        Me.TextBox2.Location = New System.Drawing.Point(289, 76)

        Me.TextBox2.Multiline = True

        Me.TextBox2.Name = "TextBox2"

        Me.TextBox2.ReadOnly = True

        Me.TextBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical

        Me.TextBox2.Size = New System.Drawing.Size(195, 103)

        Me.TextBox2.TabIndex = 1

        '

        'TextBox3

        '

        Me.TextBox3.Location = New System.Drawing.Point(509, 76)

        Me.TextBox3.Multiline = True

        Me.TextBox3.Name = "TextBox3"

        Me.TextBox3.ReadOnly = True

        Me.TextBox3.ScrollBars = System.Windows.Forms.ScrollBars.Vertical

        Me.TextBox3.Size = New System.Drawing.Size(195, 103)

        Me.TextBox3.TabIndex = 3

        '

        'Button1

        '

        Me.Button1.Location = New System.Drawing.Point(86, 226)

        Me.Button1.Name = "Button1"

        Me.Button1.Size = New System.Drawing.Size(167, 36)

        Me.Button1.TabIndex = 4

        Me.Button1.Text = "First Button"

        Me.Button1.UseVisualStyleBackColor = True

        '

        'Button2

        '

        Me.Button2.Location = New System.Drawing.Point(317, 226)

        Me.Button2.Name = "Button2"

        Me.Button2.Size = New System.Drawing.Size(167, 36)

        Me.Button2.TabIndex = 5

        Me.Button2.Text = "Second Button"

        Me.Button2.UseVisualStyleBackColor = True

        '

        'Button3

        '

        Me.Button3.Location = New System.Drawing.Point(555, 226)

        Me.Button3.Name = "Button3"

        Me.Button3.Size = New System.Drawing.Size(167, 36)

        Me.Button3.TabIndex = 6

        Me.Button3.Text = "Third Button"

        Me.Button3.UseVisualStyleBackColor = True

        '

        'Form1

        '

        Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 20.0!)

        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

        Me.ClientSize = New System.Drawing.Size(800, 450)

        Me.Controls.Add(Me.Button3)

        Me.Controls.Add(Me.Button2)

        Me.Controls.Add(Me.Button1)

        Me.Controls.Add(Me.TextBox3)

        Me.Controls.Add(Me.TextBox2)

        Me.Controls.Add(Me.TextBox1)

        Me.Name = "Form1"

        Me.Text = "Form1"

        Me.ResumeLayout(False)

        Me.PerformLayout()

    End Sub

    Friend WithEvents TextBox1 As TextBox

    Friend WithEvents TextBox2 As TextBox

    Friend WithEvents TextBox3 As TextBox

    Friend WithEvents Button1 As Button

    Friend WithEvents Button2 As Button

    Friend WithEvents Button3 As Button

End Class

=========screen shot of the code=========

Output:

X Form 1.Designer.vb Form1.vb C# DisplayButtonn Imports System.IO Form 1.vb [Design] Form1 . . ReadData 1 reference Public.Class Form1 F... Dimdata().As String Hoc.'handles.the-click-of-Button-2 O references ... Private Sub-Button1_Click(sender. As. Object, e. As - EventArgs) - Handles Button1. Click ..'Streamwrite is used to write lines to the file opened.by. AppendText ...Using writer. As-StreamWriter.=. File. AppendText("C:\display.txt") ...... 'Write the content of a text box -writer.WriteLine(TextBox1.Text) ...End-Using ...TextBox1.Clear() End Sub ...'handles-the-click-of-Button-2 O references ...Private Sub-Button2_Click(sender. As. Object, .e-As.EventArgs). Handles. Button2. Click ......'assign-the-ReadData-output-to-Textbox3 ...TextBox3.Text = ReadData() ... End Sub ... 'Read the data from the file and join it.using.new-line and return the data 3 references ... Private. Function. ReadData() - As String ...... data = File. ReadAllLines ("C:\display.txt") S ct... ReadData = Join(data,System.Environment. NewLine) ... End- Function .'handles the click.of. Button-3 O references ... Private Sub-Button3_Click(sender. As. Object, e As.EventArgs) - Handles Button3. Click ... ..'assign-the-ReadData.outputto-Text-box-2 Fot...TextBox2.Text =- ReadData() + ... End Sub End.Class

Form1 - 0 x First Button Second Button Third Button

Form1 - O X First Button Second Button Third Button

Form1 - O x First Button Second Button Third Button

. Form1 - O X First Button Second Button Third Button

. Form1 - O X First Button Second Button Third Button

Form1 - O x First Button Second Button Third Button

. Form1 - 0 X First Button Second Button Third Button

o Form1 - D x WN - First Button Second Button Third Button

HNM HNM in

X Form 1.Designer.vb Form1.vb C# DisplayButtonn Imports System.IO Form 1.vb [Design] Form1 . . ReadData 1 reference Public.Class Form1 F... Dimdata().As String Hoc.'handles.the-click-of-Button-2 O references ... Private Sub-Button1_Click(sender. As. Object, e. As - EventArgs) - Handles Button1. Click ..'Streamwrite is used to write lines to the file opened.by. AppendText ...Using writer. As-StreamWriter.=. File. AppendText("C:\display.txt") ...... 'Write the content of a text box -writer.WriteLine(TextBox1.Text) ...End-Using ...TextBox1.Clear() End Sub ...'handles-the-click-of-Button-2 O references ...Private Sub-Button2_Click(sender. As. Object, .e-As.EventArgs). Handles. Button2. Click ......'assign-the-ReadData-output-to-Textbox3 ...TextBox3.Text = ReadData() ... End Sub ... 'Read the data from the file and join it.using.new-line and return the data 3 references ... Private. Function. ReadData() - As String ...... data = File. ReadAllLines ("C:\display.txt") S ct... ReadData = Join(data,System.Environment. NewLine) ... End- Function .'handles the click.of. Button-3 O references ... Private Sub-Button3_Click(sender. As. Object, e As.EventArgs) - Handles Button3. Click ... ..'assign-the-ReadData.outputto-Text-box-2 Fot...TextBox2.Text =- ReadData() + ... End Sub End.Class

We were unable to transcribe this image

We were unable to transcribe this image

We were unable to transcribe this image

. Form1 - O X First Button Second Button Third Button

We were unable to transcribe this image

We were unable to transcribe this image

We were unable to transcribe this image

We were unable to transcribe this image

HNM HNM in


Related Solutions

Please note: This is in Visual Basic. Create an application. Add two text boxes, a label,...
Please note: This is in Visual Basic. Create an application. Add two text boxes, a label, and a button to the form. The button’s Click event procedure should assign the contents of the text boxes to Double variables named dblNum1 and dblNum2. It then should divide the dblNum1 variable’s value by the dblNum2 variable’s value, assigning the result to a Double variable named dblAnswer. Display the answer in the label. Code the procedure. Save the solution and then start the...
NOTE: This is done using Visual Basic. Create an application named You Do It 2. Add...
NOTE: This is done using Visual Basic. Create an application named You Do It 2. Add a text box, a label, and a button to the form. Enter the following three Option statements above the Public Class clause in the Code Editor window: Option Explicit On, Option Strict Off, and Option Infer Off. In the button’s Click event procedure, declare a Double variable named dblNum. Use an assignment statement to assign the contents of the text box to the Double...
NOTE: This is done using Visual Basic. Create an application named You Do It 1. Add...
NOTE: This is done using Visual Basic. Create an application named You Do It 1. Add a text box, a label, and a button to the form. The button’s Click event procedure should store the contents of the text box in a Double variable named dblCost. It then should display the variable’s contents in the label. Enter the three Option statements above the Public Class clause in the Code Editor window, and then code the procedure. Save the solution and...
Please note: This is in Visual Basic. Create an application. Add a text box, a label,...
Please note: This is in Visual Basic. Create an application. Add a text box, a label, and a button to the form. If the user enters a number that is greater than 100 in the text box, the button's "click" event procedure should display the result of multiplying the number by 5. Otherwise, it should display the result of dividing the number by 5. Code the procedure.
Using C#: Create a Form that consists of 4 checkboxes, three radio buttons, a label and...
Using C#: Create a Form that consists of 4 checkboxes, three radio buttons, a label and a button. The 4 checkboxes represent pizza toppings. The three radiobuttons should represent three sizes of pizza, namely “small”, “medium” and “large”. When the user clicks the button you need to calculate the price of the pizza. The calculation should be done as follows: count up the cost of the selected ingredients (you may assign your own prices for the ingredients) and then multiply...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Using Visual Basic 2017, Create a form with two textboxes and one button. A user enters...
Using Visual Basic 2017, Create a form with two textboxes and one button. A user enters the course she is taking in the first text box and then clicks on the button. Then if the user entered "Program Language" in the first text box, the second text box will show "Awesome pick!". If the user entered something else, the text box shows "Ok." Please write the correct code.
using visual basic how would i go about coding: if checkbox 1 is checked add 10...
using visual basic how would i go about coding: if checkbox 1 is checked add 10 to subtotal if checkbox 2 is checked add 50 to subtotal if checkbox 3 is checked add 100 to subtotal subtotal label is 'lblSubtotal' all 3 boxes are independent. example if checkboxes 1 and 3 are checked 110 would be added to subtotal.
Add a radio Button in UI , by using Visual Studio code Add a Radio button...
Add a radio Button in UI , by using Visual Studio code Add a Radio button in UI , by Using visual Studio code in Angular or Angular Js Format.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT