Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Объектно-ориентированное программирование на языке Visual Basic 2008 в среде разработки Microsoft Visual Studio 2008 и .NET Framework. Часть 2. Учебно

.pdf
Скачиваний:
0
Добавлен:
07.09.2026
Размер:
2 Мб
Скачать
14
      :
61
15
      :
16
      :
 
1. .
2. .
3. .
4.  .
62
5.    ,   , -
  .
6. 
7. .
   
     1
   ,               .      :  
 ­ .        ­   Data1  Data2.         ,     IShared.
  (Form2)      5 ­ Label, 3  TextBox   RichTextBox.  ­ RichTextBox    .       Microsoft Office Word    4   5    .     ­   RTF    .    ­   RichTextBox1      Data1 :
RichTextBox1.LoadFile("C:\Users\Documents\_.rtf")
      :
63
  InputBox,     ( TextBox1),   ( Label4),     ( TextBox3).
     (Form3)   5 ­ Label, 3  TextBox   RichTextBox,    ­ ComboBox,      ,       .        SelectedIndexChanged      Select Case.   ComboBox1   Form3,         .
      :
   RichTextBox      Microsoft Office Word     RTF.       RichTextBox1      Data2  :
RichTextBox1.LoadFile("C:\Users\Documents\_.rtf")
  RichTextBox1     
 .

   Data1  Data2   IShared,  
 :
Public Interface IShared Sub prototype(ByRef n As String, ByRef st As String, ByRef st1 As String) End Interface
 ,      
   ,      .
   :
64
1. Visual Studio 2008.
2.      (New Project).
3.  . Form1        ­   Button.  (Button1)   «­ »,   «».  ,       ( ->   -> ).
4.   Data1  Data2.
5.    Button1   -
.
6.  ,    Start Debugging.
7. .
  :
Public Class Data1 Implements IShared Public Sub document(ByRef n As String, ByRef firm As String, ByRef provider As String) Implements IShared.prototype n = CStr(InputBox("  ")) firm = CStr(InputBox("  ")) provider = CStr(InputBox(" ")) With Form2 .TextBox1.Text = n .Label4.Text = firm .TextBox3.Text = provider .RichTextBox1.LoadFile("C:\Users\Documents\_.rtf") End With End Sub End Class
Public Class Data2 Implements IShared Public Sub document(ByRef n As String, ByRef firm As String, ByRef address As String) Implements IShared.prototype n = CStr(InputBox("  ")) firm = CStr(InputBox("  ")) address = CStr(InputBox(" ")) With Form3 .TextBox1.Text = n .Label4.Text = firm .Label5.Text = address .ComboBox1.Text = " " .RichTextBox1.LoadFile("C:\Users\Documents\_.rtf") End With End Sub End Class
     With … End With,           .         ,      ,    .
65
  Form1
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim doc As New Data1 Dim doc1 As New Data2 Dim kind As Integer Dim rd As Date = Now '   Dim n As String = "" Dim firm As String = "" Dim bas As String = "" 'MsgBox(TypeOf doc Is IShared)'   ( true,  doc  ) Form2.TextBox2.Text = rd.ToShortDateString '  
kind = CInt(InputBox("  ( -0/ -1)"))
Select Case kind Case 0 doc.document(n, firm, bas) Form2.Show() Case 1 doc1.document(n, firm, bas) Form3.Show() End Select End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub End Class
Form3.TextBox2.Text = rd.ToShortDateString '  
  Form3:
Public Class Form3
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.SelectedIndex Case 0 TextBox3.Text = ComboBox1.Items(0) & "   72/3" Case 1 TextBox3.Text = ComboBox1.Items(1) & "   77/1" Case 2 TextBox3.Text = ComboBox1.Items(2) & "   86/5" Case 3 TextBox3.Text = ComboBox1.Items(3) & "   798/4" Case 4
66
TextBox3.Text = ComboBox1.Items(4) & "   77/2" End Select End Sub
End Class
     .4.1
.4.1
67
     2
    ,  ­ .   (Poly)    ­   ,   Integer. ­   ,       ,    .   (Polymorphism)   ­  
,       ­   .     ­.
 ,       StringBuilder,        .     ,    AppendLine(),        .  StringBuilder   ,            ToString().

   Form1 :
  :
Public Interface IShared Sub sets(ByVal n As Integer, ByRef x() As Integer, ByRef st() As String) End Interface
  :
Public Class Poly Implements IShared
68
Sub shift(ByVal n As Integer, ByRef x() As Integer, ByRef st() As String) Implements IShared.sets Dim mx(n) As String Dim s As Integer For i As Integer = 0 To n s = 0 Do While Math.Abs(x(i)) > 0 s += x(i) Mod 10 x(i) \= 10 Loop x(i) = s Next End Sub End Class
Public Class Polymorphism Implements IShared Sub shift(ByVal n As Integer, ByRef x() As Integer, ByRef st() As String) Implements IShared.sets Dim mst(n) As String Array.Sort(st) For i As Integer = 0 To n st(i) = st(i).ToUpper Next End Sub End Class
   :
Public Class Form1 Public n As Integer Public k As Byte Public x() As Integer = {} Public st() As String = {} Dim r, rn As New System.Text.StringBuilder
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim obj As New Poly k = 1 inputs(k, obj) obj.shift(n, x, st) For i As Integer = 0 To n r = r.AppendLine(String.Format(" | {0:N0} | ", x(i))) Next TextBox2.Text = (" " & vbCrLf) TextBox2.Text = TextBox2.Text & r.ToString End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim obj As New Polymorphism
69
k = 0 inputs(k, obj) obj.shift(n, x, st) For i As Integer = 0 To n r = r.AppendLine(String.Format(" | {0} | ", st(i))) Next TextBox2.Text = (" " & vbCrLf) TextBox2.Text = TextBox2.Text & r.ToString End Sub
Private Sub inputs(ByRef k As Byte, ByRef obj As Object) n = CSng(InputBox("  n")) ReDim x(n), st(n) TextBox1.Text = " " & vbCrLf For i As Integer = 0 To n If k = 1 Then x(i) = InputBox(" " & i & "-    ") rn = rn.AppendLine(String.Format(" | {0:N0} | ", x(i))) Else st(i) = InputBox(" " & i & "-    ") rn = rn.AppendLine(String.Format(" | {0} | ", st(i))) End If Next TextBox1.Text = TextBox1.Text & rn.ToString End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub End Class
      :
70
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]