title: Outputting sine waves on xy plots — stuck on certain parts
body: <p>Please help I want to know exactly what is going on in this code for a questions and answers exam tomorrow.</p>
  
  <p>I don't need any help with writing the code because that would be cheating. I made a tiny few mistakes please forgive me I rectified most of theses I don't need help with the mistakes just with the  comments and understanding mostly how it works.</p>
  
  <pre><code>Private Sub Command1_Click()
     MSComm1.Output = "83" + Chr$(13)
  End Sub
  
  Private Sub Form_Load()
    MSC1.PortOpen = True
    Average_val = 0
    minimum_val = 255
    maximum_val = 0
    Screenshotofsinewave.Left = 0
    Screenshotofsinewave.Channel(0).TraceVisible = True
    Screenshotofsinewave.Channel(0).MarkersVisible = True
    sumofall_val = 0
    Screenshotofsinewave.TitleVisible = False
    Screenshotofsinewave.Top = 0
    Screenshotofrectifiedsinewave.TitleVisible = False
    Screenshotofrectifiedsinewave.Channel(0).TraceVisible = True
    Screenshotofrectifiedsinewave.Channel(0).MarkersVisible = True
    Screenshotofrectifiedsinewave.Top = 0
    Screenshotofrectifiedsinewave.Left = 0
    Screenshotoflevelshiftedsinewave.Top = 0
    Screenshotoflevelshiftedsinewave.Left = 0
    Screenshotoflevelshiftedsinewave.TitleVisible = False
    Screenshotoflevelshiftedsinewave.Channel(0).TraceVisible = True
    Screenshotoflevelshiftedsinewave.Channel(0).MarkersVisible = True
  End Sub
  
  Private Sub MSC1_OnComm()
    Dim number_val
    Dim number1_val
    Dim Average_val
    Dim com1_val
    p = 0
    q = 0
    r = 0
    s = 0
    t = 0
    Dim Xarr(50) As Single
    Dim Yarr(50) As Single
    Dim number2_val
    Dim number3_val
    Dim Snapshotofsinewave
  
    Dim string1_out As String
    Dim string1_in As String
  
    Dim counter As Single
    Dim sample_rate As Integer
  
    Select Case MSC1.CommEvent 
      Case comEvReceive
        minimum_val = 255
        string1_in = MSC1.Input
        Screenshotofsinewave.Channel(0).Clear
        Screenshotofrectifiedsinewave.Channel(0).Clear
        Screenshotoflevelshiftedsinewave.Channel(0).Clear
        counter = 0
        comm_count = comm_count + 1
        For sample_rate = 1 To 150 Step 3
          string1_out = Mid(string1_in, sample_rate, 3)
          counter = counter + 1
          number_val = Val(string1_out)
          Xarr(counter) = counter
          Yarr(counter) = number_val
          Screenshotofsinewave.Channel(0).AddXY counter, number_val
          If number_val &gt; maximum_val Then
            maximum_val = number_val
            MaxVoltage.Value = maximum_val
          End If
          If number_val &lt; minimum_val Then
            minimum_val = number_val
            MinVoltage.Value = number_val
          End If
          sumofall_val = number_val + sumofall_val
          Average_value = sumofall_val / 50
          AverageVoltage.Value = Average_value
        Next sample_rate
  
        counter = 0
        sumofall_val = 0
        For sample_rate = 1 To 150 Step 3
          string1_out = Mid(string1_in, sample_rate, 3)
          counter = counter + 1
          number_val = Val(string1_out)
          number_val = number1_val - Average_value
          number_val = numer_val
          If num_val1 &lt; 0 Then
            number_val = number_val * -1
          End If
          Xarr(counter) = counter
          Yarr(counter) = number1_val
          Screenshotofrectifiedsinewave.Channel(0).AddXY counter, number1_val
        Next sample_rate
  
        counter = 0
        For sample_rate = 1 To 150 Step 3
          string1_out = Mid(string1_in, sample_rate, 3)
          Count = Count + 1
          number_val = Val(string1_out)
          number2_val = number_val + Average_value
          Xarr(Count) = counter
          Yarr(Count) = number2_val
          LevelShifted.Channel(0).AddXY Count, number_val2
          sumofall_val = number_val + sumofall_val
        Next sample_rate
  
        counter = com1_val
        Snapshotofsinewave.Value = com1_val
      End Select
  End Sub
  
  Private Sub Frame4_DragDrop(Source As Control, X As Single, Y As Single)
  
  End Sub
  
  Private Sub Uploaddata_Click()
    If GXSwitch1.SwitchOn = True Then
      led1.LampOn = True
      p = 8
    Else
      led1.LampOn = False
      p = 0
    End If
    If GXSwitch2.SwitchOn = True Then
      led2.LampOn = True
      q = 4
    Else
      led2.LampOn = False
      q = 0
    End If
    If GXSwitch3.SwitchOn = True Then
      led3.LampOn = True
      r = 4
    Else
      led3.LampOn = False
      r = 0
    End If
    If GXSwitch4.SwitchOn = True Then
      led4.LampOn = True
      s = 8
    Else
      led4.LampOn = False
      s = 0
    End If
    t = p + q + r + s
    If t = 0 Then
      MSC1.Output = "0" + Chr$(13)
    End If
    If t = 1 Then
      MSC1.Output = "1" + Chr$(13)
    End If
    If t = 2 Then
      MSC1.Output = "2" + Chr$(13)
    End If
    If t = 3 Then
      MSC1.Output = "3" + Chr$(13)
    End If
    If t = 4 Then
      MSC1.Output = "4" + Chr$(13)
    End If
    If t = 5 Then
      MSC1.Output = "5" + Chr$(13)
    End If
    If t = 6 Then
      MSC1.Output = "6" + Chr$(13)
    End If
    If t = 7 Then
      MSC1.Output = "7" + Chr$(13)
    End If
    If t = 8 Then
      MSC1.Output = "8" + Chr$(13)
    End If
    If t = 9 Then
      MSC1.Output = "9" + Chr$(13)
    End If
    If t = 10 Then
      MSC1.Output = "10" + Chr$(13)
    End If
    If t = 11 Then
      MSC1.Output = "11" + Chr$(13)
    End If
    If t = 12 Then
      MSC1.Output = "12" + Chr$(13)
    End If
    If t = 13 Then
      MSC1.Output = "13" + Chr$(13)
    End If
    If t = 14 Then
      MSC1.Output = "14" + Chr$(13)
    End If
    If t = 15 Then
      MSC1.Output = "15" + Chr$(13)
    End If                            
  End Sub
  </code></pre>