Слайд 1Visual Basic 2010
Создание меню
Работа с файлами и таблицами.
Слайд 19Программный код
Public Class Form1
Dim n As Integer
Private Sub mnuExit_Click(sender As Object, e As System.EventArgs) Handles
mnuExit.Click
End
End Sub
Private Sub mnuOpen_Click(sender As Object, e As System.EventArgs) Handles mnuOpen.Click
Dim filename1 As String
Dim file1 As Object
Dim stroka As String, i As Integer, a(,) As Single, dlin As Integer, k As Integer
Dim stroka2 As String, simv As String, stroka3 As String
Dim dt As New DataTable
OpenFileDialog1.ShowDialog()
filename1 = OpenFileDialog1.FileName
file1 = New System.IO.StreamReader(filename1)
stroka = file1.ReadLine()
ListBox1.Items.Add(stroka)
n = CInt(stroka)
ReDim a(0 To n - 1, 0 To n - 1)
- 1
stroka3 = ""
stroka = file1.ReadLine()
dlin = Len(stroka)
k = 0
stroka2 = ""
For j = 1 To dlin
simv = Mid(stroka, j, 1)
If simv <> " " Then
stroka2 = stroka2 + simv
Else
a(i, k) = CSng(stroka2)
stroka2 = ""
stroka3 = stroka3 + CStr(a(i, k)) + " "
k = k + 1
End If
Next j
a(i, k) = CSng(stroka2)
stroka3 = stroka3 + CStr(a(i, k)) + " "
ListBox1.Items.Add(stroka3)
Next i
Слайд 21 DataGridView1.DataSource = dt
For j =
1 To n
dt.Columns.Add(New DataColumn(CStr(j),
GetType(String)))
Next j
For i = 0 To n - 1
dt.Rows.Add(New String() {a(i, 0), a(i, 1), a(i, 2), a(i, 3), a(i, 4)})
Next i
file1.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ColorDialog1.ShowDialog()
Button1.BackColor = ColorDialog1.Color
End Sub
Слайд 22
Private Sub mnuSaveAS_Click(sender As Object, e As System.EventArgs)
Handles mnuSaveAS.Click
Dim a(n, n) As Single,
i As Integer, j As Integer, filename1 As String, stroka As String
Dim file1 As Object
Dim dt As New DataTable
SaveFileDialog1.ShowDialog()
filename1 = SaveFileDialog1.FileName
file1 = New System.IO.StreamWriter(filename1)
file1.WriteLine(CStr(n))
dt = DataGridView1.DataSource
For i = 0 To n - 1
stroka = ""
For j = 0 To n - 1
a(i, j) = dt.Rows.Item(i).Item(j)
stroka = stroka + CStr(a(i, j)) + " "
Next j
file1.WriteLine(stroka)
Next i
file1.Close()
End Sub
End Class