regional 2000

advertisement
VB.NET Programming Key 2006
1. A
2. A
3. B
4. C
5. A
6. B
7. C
8. A
9, A
10. D
11. C
12. A
13. C
14. B
15. A
16. D
17. C
18. B
19. B
20. A
21. A
22. D
23. D
24. B
25. D
Notes to Graders:
 You should run the application from the contestant’s disk to verify the correct
execution.
 Check the changed text file on the disk for accuracy.
 Contestant Number should appear on all print outs and on the form title
 Results must not be hard-coded into the program.
Sample form with original file open:
Print Screen after first change:
Print Screen after second change:
Print Screen after third change:
Print Screen after fourth change:
Changed Text File
It is rare indeed that some give. Most people guard and keep; they
suppose that it is they themselves and what they identify with
themselves that they are guarding and keeping, whereas what they are
actually guarding and keeping is their system of reality and what they
assume themselves to be.
James A. Baldwin
Go studious in your profession, and you will be learned. I am
industrious and frugal, and you will be rich. I am sober and temperate,
and you will be healthy. I am in general virtuous, and you will be
happy. At least you will, by such conduct, stand the best chance for
such consequences.
I amnjamin Franklin
Sample code: actual code or style may vary
Public Class bpastate
Inherits System.Windows.Forms.Form
Dim strline As String = ""
Private Sub exitmnu_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles exitmenu.Click
Close()
End Sub
Private Sub openmnu_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles openmnu.Click
Dim objStreamreader As System.IO.StreamReader
strline = ""
If System.IO.File.Exists("VBNetReg.txt") = True Then
objStreamreader = System.IO.File.OpenText("VBNetReg.txt")
Do Until objStreamreader.Peek = -1
strline += objStreamreader.ReadLine()
strline += vbNewLine
Loop
txtlbl.Text = strline
objStreamreader.Close()
End If
End Sub
Private Sub savemnu_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles savemnu.Click
Dim objStreamWriter As System.IO.StreamWriter
objStreamWriter = System.IO.File.CreateText("VBNetReg.txt")
objStreamWriter.WriteLine(txtlbl.Text)
objStreamWriter.Close()
End Sub
Private Sub replacemnu_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles replacemnu.Click
Dim newstr, replace, replacewith As String
Dim len As Integer
Dim spaces As String = "
"
replace = InputBox("What would you like to replace?", "Replace")
If replace <> "" Then
replacewith = InputBox("What do you want to replace " & ControlChars.Quote &
replace & ControlChars.Quote & " with?", "Replace")
If replacewith <> "" Then
len = strline.IndexOf(replace)
If len <> -1 Then
strline = strline.Remove(len, replace.Length)
strline = strline.Insert(len, replacewith)
Else
MessageBox.Show("Text not found", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End If
txtlbl.Text = strline
End If
End If
End Sub
Private Sub repallmnu_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles repallmnu.Click
Dim replace, replacewith As String
replace = InputBox("What would you like to replace?", "Replace All")
If replace <> "" Then
replacewith = InputBox("What do you want to replace " & ControlChars.Quote &
replace & ControlChars.Quote & " with?", "Replace All")
If replacewith <> "" Then
strline = strline.Replace(replace, replacewith)
txtlbl.Text = strline
End If
End If
End Sub
End Class
Download