комментарии - VB

Формулировка задачи:

вот в общем программный код, который нужно полностью закомментировать
Option Explicit
Dim x As Single
Dim y As Single
Dim kol As Integer
Dim I As Integer
Dim t As Single
Const N As Long = 10
Const r = 76
Dim time As Integer
Dim chastic As Integer
Const D As Double = 15
Dim VX(N) As Double, VY(N) As Double, V(N) As Double
Dim a_X(N) As Double, a_Y(N) As Double
Dim TN As Double, tik As Long
Dim II As Integer, JJ As Integer
Dim vXij As Double, vYij As Double
Private Sub Form_Load()
 
Show
Picture1.DrawWidth = 1
Picture1.Scale (0, 0)-(400, 400)
Picture1.Circle (204, 214), r
Dim I As Integer, J As Integer
Timer1.Enabled = False
Me.ScaleWidth = 400
Me.ScaleHeight = 400
Shape1(0).Height = D
Shape1(0).Width = D
 
a_X(0) = 1
Shape1(0).Top = a_X(1) 'X
a_Y(0) = 1
Shape1(0).Left = a_Y(1) 'Y
VX(0) = 110
VY(0) = 40
For I = 1 To N
  Load Shape1(I)
  With Shape1(I)
   .Visible = True
   .Shape = 3
   .Width = D
   .Height = D
   a_X(I) = Int(Rnd * 300 + D) 'a_X(I - 1) + 50
   .Top = a_X(I)
   a_Y(I) = Int(Rnd * 300 + D)
    .Left = a_Y(I)
  End With
Next I
kol = Val(Text1.Text)
time = Val(Text2.Text)
Text1.SetFocus
 
 
End Sub
 
Sub Timer1_Timer()
Dim I As Long
Dim K As Double, dX As Double, dY As Double
Dim VIR As Double, VJR As Double
 
  tik = tik + 1
  If tik > TN Then
    K = TN + 1 - tik
    For I = 0 To N
      a_Y(I) = a_Y(I) + VY(I) * K: Shape1(I).Left = a_Y(I)
      a_X(I) = a_X(I) + VX(I) * K: Shape1(I).Top = a_X(I)
    Next I
    Select Case JJ
      Case -1: VX(II) = -VX(II)
      Case -2: VY(II) = -VY(II)
      Case Else
        dX = (a_X(II) - a_X(JJ)) / D
        dY = (a_Y(II) - a_Y(JJ)) / D
        vXij = VX(JJ) - VX(II)
        vYij = VY(JJ) - VY(II)
        VIR = (dY * vYij + dX * vXij)
        VJR = (dX * vYij - vXij * dY)
        VX(JJ) = VX(II) - VJR * dY
        VY(JJ) = VY(II) + VJR * dX
        VX(II) = VX(II) + VIR * dX
        VY(II) = VY(II) + VIR * dY
    End Select
    near_Bac
  Else
    For I = 0 To N
      a_Y(I) = a_Y(I) + VY(I): Shape1(I).Left = a_Y(I)
      a_X(I) = a_X(I) + VX(I): Shape1(I).Top = a_X(I)
    Next I
  End If
  Timer1.Enabled = True
   Timer1.Interval = 50
   time = 0
   For I = 1 To time
   time = time + 1
   Label4.Caption = time
   Next I
End Sub
Private Sub Command1_Click(Index As Integer)
Call Timer1_Timer
For I = 0 To N
If (a_X(I)) ^ 2 + (a_Y(I)) ^ 2 <= r ^ 2 Then
chastic = chastic + 1
Label5.Caption = chastic
End If
Next I
End Sub
Private Sub Command3_Click(Index As Integer)
For I = 0 To N
Shape1(I).Visible = False
Next I
Timer1.Enabled = False
 
End Sub
Private Sub Command2_Click(Index As Integer)
Timer1.Enabled = False
End Sub
 
 
Sub near_Bac()
Dim I As Integer, J As Integer, t As Double
Dim V As Double, xn As Double, yn As Double
Dim dX As Double, dY As Double
TN = 1.79769313486231E+308
For I = 0 To N - 1
  For J = I + 1 To N
    vXij = VX(J) - VX(I)
    vYij = VY(J) - VY(I)
    If vXij <> 0 Or vYij <> 0 Then
      t = 1.79769313486231E+308
      dX = a_X(I) - a_X(J)
      dY = a_Y(I) - a_Y(J)
      V = Sqr(vXij * vXij + vYij * vYij)
      yn = (dX * vYij - vXij * dY) / V
      If Abs(yn) <= D Then
        xn = (dX * vXij + vYij * dY) / V
        If xn >= 0 Then t = (xn - Sqr(D * D - yn * yn)) / V
      End If
      If t < TN Then TN = t: II = I: JJ = J
    End If
  Next J
Next I
For I = 0 To N
  If VX(I) > 0 Then
    t = (Me.ScaleHeight - a_X(I) - D) / VX(I): If t < TN Then II = I: JJ = -1: TN = t
  ElseIf VX(I) < 0 Then
    t = -a_X(I) / VX(I): If t < TN Then II = I: JJ = -1: TN = t
  End If
  If VY(I) > 0 Then
    t = (Me.ScaleWidth - a_Y(I) - D) / VY(I): If t < TN Then II = I: JJ = -2: TN = t
  ElseIf VY(I) < 0 Then
    t = -a_Y(I) / VY(I): If t < TN Then II = I: JJ = -2: TN = t
  End If
Next I
tik = 0
End Sub
вот и вся программа

Код к задаче: «комментарии - VB»

textual
'Option Explicit
'Dim x As Single
'Dim y As Single
'Dim kol As Integer
'Dim I As Integer
'Dim t As Single
'Const N As Long = 10
'Const r = 76
'Dim time As Integer
'Dim chastic As Integer
'Const D As Double = 15
'Dim VX(N) As Double, VY(N) As Double, V(N) As Double
'Dim a_X(N) As Double, a_Y(N) As Double
'Dim TN As Double, tik As Long
'Dim II As Integer, JJ As Integer
'Dim vXij As Double, vYij As Double
'Private Sub Form_Load()
 
'Show
'Picture1.DrawWidth = 1
'Picture1.Scale (0, 0)-(400, 400)
'Picture1.Circle (204, 214), r
'Dim I As Integer, J As Integer
'Timer1.Enabled = False
'Me.ScaleWidth = 400
'Me.ScaleHeight = 400
'Shape1(0).Height = D
'Shape1(0).Width = D
 '
'a_X(0) = 1
'Shape1(0).Top = a_X(1) 'X
'a_Y(0) = 1
'Shape1(0).Left = a_Y(1) 'Y
'VX(0) = 110
'VY(0) = 40
'For I = 1 To N
 ' Load Shape1(I)
  'With Shape1(I)
   '.Visible = True
   '.Shape = 3
   '.Width = D
   '.Height = D
  ' a_X(I) = Int(Rnd * 300 + D) 'a_X(I - 1) + 50
   '.Top = a_X(I)
   'a_Y(I) = Int(Rnd * 300 + D)
    '.Left = a_Y(I)
'  End With
'Next I
'kol = Val(Text1.Text)
'time = Val(Text2.Text)
'Text1.SetFocus
 
 
'End Sub
' 
'Sub Timer1_Timer()
'Dim I As Long
'Dim K As Double, dX As Double, dY As Double
'Dim VIR As Double, VJR As Double
 '
  'tik = tik + 1
  'If tik > TN Then
   ' K = TN + 1 - tik
    'For I = 0 To N
     ' a_Y(I) = a_Y(I) + VY(I) * K: Shape1(I).Left = a_Y(I)
      'a_X(I) = a_X(I) + VX(I) * K: Shape1(I).Top = a_X(I)
    'Next I
   ' Select Case JJ
   '   Case -1: VX(II) = -VX(II)
   '   Case -2: VY(II) = -VY(II)
   '   Case Else
   '     dX = (a_X(II) - a_X(JJ)) / D
   '     dY = (a_Y(II) - a_Y(JJ)) / D
   '     vXij = VX(JJ) - VX(II)
   '     vYij = VY(JJ) - VY(II)
   '     VIR = (dY * vYij + dX * vXij)
   '     VJR = (dX * vYij - vXij * dY)
   '     VX(JJ) = VX(II) - VJR * dY
   '     VY(JJ) = VY(II) + VJR * dX
   '     VX(II) = VX(II) + VIR * dX
   '     VY(II) = VY(II) + VIR * dY
   ' End Select
   ' near_Bac
  'Else
  '  For I = 0 To N
   '   a_Y(I) = a_Y(I) + VY(I): Shape1(I).Left = a_Y(I)
    '  a_X(I) = a_X(I) + VX(I): Shape1(I).Top = a_X(I)
   ' Next I
  'End If
  'Timer1.Enabled = True
   'Timer1.Interval = 50
   'time = 0
   'For I = 1 To time
   'time = time + 1
  ' Label4.Caption = time
  ' Next I
'End Sub
'Private Sub Command1_Click(Index As Integer)
'Call Timer1_Timer
'For I = 0 To N
'If (a_X(I)) ^ 2 + (a_Y(I)) ^ 2 <= r ^ 2 Then
'chastic = chastic + 1
'Label5.Caption = chastic
'End If
'Next I
'End Sub
'Private Sub Command3_Click(Index As Integer)
'For I = 0 To N
'Shape1(I).Visible = False
'Next I
'Timer1.Enabled = False
 '
'End Sub
'Private Sub Command2_Click(Index As Integer)
'Timer1.Enabled = False
'End Sub
 '
 
'Sub near_Bac()
'Dim I As Integer, J As Integer, t As Double
'Dim V As Double, xn As Double, yn As Double
'Dim dX As Double, dY As Double
'TN = 1.79769313486231E+308
'For I = 0 To N - 1
 ' For J = I + 1 To N
  '  vXij = VX(J) - VX(I)
   ' vYij = VY(J) - VY(I)
    'If vXij <> 0 Or vYij <> 0 Then
     ' t = 1.79769313486231E+308
      'dX = a_X(I) - a_X(J)
      'dY = a_Y(I) - a_Y(J)
      'V = Sqr(vXij * vXij + vYij * vYij)
      'yn = (dX * vYij - vXij * dY) / V
      'If Abs(yn) <= D Then
       ' xn = (dX * vXij + vYij * dY) / V
        'If xn >= 0 Then t = (xn - Sqr(D * D - yn * yn)) / V
     ' End If
      'If t < TN Then TN = t: II = I: JJ = J
    'End If
 ' Next J
'Next I
'For I = 0 To N
 ' If VX(I) > 0 Then
  '  t = (Me.ScaleHeight - a_X(I) - D) / VX(I): If t < TN Then II = I: JJ = -1: TN = t
  'ElseIf VX(I) < 0 Then
   ' t = -a_X(I) / VX(I): If t < TN Then II = I: JJ = -1: TN = t
  'End If
  'If VY(I) > 0 Then
   ' t = (Me.ScaleWidth - a_Y(I) - D) / VY(I): If t < TN Then II = I: JJ = -2: TN = t
  'ElseIf VY(I) < 0 Then
    't = -a_Y(I) / VY(I): If t < TN Then II = I: JJ = -2: TN = t
  'End If
'Next I
'tik = 0
'End Sub

6   голосов, оценка 3.500 из 5


СОХРАНИТЬ ССЫЛКУ