Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the Code - Having trouble with each of these tasks. Imports System.IO Public Class Form1 Dim C As Integer Const n = 5

image text in transcribed

image text in transcribed

Here is the Code - Having trouble with each of these tasks.

Imports System.IO

Public Class Form1

Dim C As Integer

Const n = 5

Dim A(n) As Integer

Dim TextColor(n) As Integer

Dim BackGroundColor(n) As Integer

Dim Brushes(11) As System.Drawing.Brush

Dim r As Random

Dim prefix As String

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint

Dim G As Graphics

G = e.Graphics

Dim P As Pen

Const cellsize = 50

P = New Pen(Drawing.Brushes.Black, 1)

Dim i As Integer

Const lm = 400

Const tm = 25

Dim f As Font

f = New Font("times new roman", 12)

Const MARGIn = 3

For i = 0 To n

Dim str As String

str = A(i)

G.FillRectangle(Brushes(BackGroundColor(i)), lm + MARGIn, tm + i * cellsize + MARGIn, cellsize - MARGIn, cellsize - MARGIn)

G.DrawString(str, f, Brushes(TextColor(i)), lm, tm + i * cellsize)

Next

G.DrawLine(P, lm, tm, lm, tm + n * cellsize + cellsize) ' left side of boxes

G.DrawLine(P, lm + cellsize, tm, lm + cellsize, tm + n * cellsize + cellsize) ' right side of boxes

' draw horizontal lines separating cells'

For i = 0 To n + 1

G.DrawLine(P, lm, tm + i * cellsize, lm + cellsize, tm + i * cellsize)

Next

End Sub

Private Sub Reset()

For i = 0 To n

TextColor(i) = 0

BackGroundColor(i) = 1

Next

End Sub

Private Sub Button0_Click(sender As Object, e As EventArgs) Handles Button0.Click

Dim pos As Integer

Dim value As Integer

' set array to random numbers from zero to ten

For i = 0 To n

A(i) = r.NextDouble() * 10

Next

Me.Refresh()

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim pos As Integer

Dim value As Integer

' put button one code to put a number, given by text box "txt1Value"

' at the position indicated by txt1 text box

' leave this alone

Me.Refresh()

End Sub

Public Sub New()

' This call is required by the designer.InitializeComponent()

InitializeComponent()

Brushes(0) = Drawing.Brushes.Black : Brushes(1) = Drawing.Brushes.Red : Brushes(2) = Drawing.Brushes.LimeGreen : Brushes(3) = Drawing.Brushes.Blue : Brushes(4) = Drawing.Brushes.Yellow

Brushes(5) = Drawing.Brushes.Orange : Brushes(6) = Drawing.Brushes.Purple : Brushes(7) = Drawing.Brushes.Brown : Brushes(8) = Drawing.Brushes.Chartreuse : Brushes(9) = Drawing.Brushes.Cyan

Brushes(10) = Drawing.Brushes.DarkKhaki : Brushes(11) = Drawing.Brushes.White

Reset()

r = New Random()

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Reset()

' display even numbers in red

' Leave This Alone

Me.Refresh()

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

' display odd numbers on a yellow background

' leave this alone

Me.Refresh()

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

prefix = ""

End Sub

' leave these three radio button stuff alone

Private Sub rb1_CheckedChanged(sender As Object, e As EventArgs) Handles rb1.CheckedChanged

prefix = ""

End Sub

Private Sub rb2_CheckedChanged(sender As Object, e As EventArgs) Handles rb2.CheckedChanged

prefix = Environment.GetEnvironmentVariable("HOME") + "\"

End Sub

Private Sub rb3_CheckedChanged(sender As Object, e As EventArgs) Handles rb3.CheckedChanged

prefix = "P:\"

End Sub

' provided code leave alone

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

' zero out array

For I = 0 To n

A(I) = 0

Next

End Sub

' Read in Data from file

' Leave Alone

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

Dim AFile As FileStream

Dim str As String

str = prefix + "ala.txt"

AFile = New FileStream(prefix + "ala.txt", FileMode.Open, FileAccess.Read)

Dim AStream As StreamReader

AStream = New StreamReader(AFile)

For i = 0 To n

A(i) = AStream.ReadLine()

Next

AFile.Close()

Me.Refresh()

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

Dim OFile As FileStream

Dim str As String

str = prefix + "ala.txt"

OFile = New FileStream(prefix + "ala.txt", FileMode.OpenOrCreate, FileAccess.Write)

Dim OStream As StreamWriter

OStream = New StreamWriter(OFile)

For i = 0 To n

OStream.WriteLine(A(i))

Next i

OStream.Close()

End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click

Dim rangestart As Integer

Dim rangeend As Integer

' read in rangestart from textbox txt3

' range in rangeend from textbox txt4

' make numbers in range on green background

' leave alone

Me.Refresh()

End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click

Dim rangestart As Integer

Dim rangeend As Integer

' read in rangestart from textbox txt3

' read in rangeend from textbox txt4

' make numbers outside of range in blue text

' leave alone

Me.Refresh()

End Sub

' Restore Colors

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click

Me.Reset()

Me.Refresh()

End Sub

End Class

e unzip it to give the project airectoTy Note, that there are a serie We use ALA to ALE in this lab s of files of the form AL? where ? is a single character from a to z. Task Zero BUTTON I Change the number at txt2 text box. Here is a hint: pos txt 1 . Text a specific position, from the txtl textbox, to the value given in the value A(pos) txt2.Text value Task One Button2 Display the numbers that are even in red That is, go through the e for that position to one. Put your code after the comment, displayed in green, 'display even numbers in red hint: For i = 0 To n If A(1) Mod 2 = 0 Then TextColor (1) = 1 End If Next e unzip it to give the project airectoTy Note, that there are a serie We use ALA to ALE in this lab s of files of the form AL? where ? is a single character from a to z. Task Zero BUTTON I Change the number at txt2 text box. Here is a hint: pos txt 1 . Text a specific position, from the txtl textbox, to the value given in the value A(pos) txt2.Text value Task One Button2 Display the numbers that are even in red That is, go through the e for that position to one. Put your code after the comment, displayed in green, 'display even numbers in red hint: For i = 0 To n If A(1) Mod 2 = 0 Then TextColor (1) = 1 End If Next

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information System

Authors: James A. Hall

7th Edition

978-1439078570, 1439078572

Students also viewed these Databases questions