Declare Function Bit_weight Lib "C:\Ioexp\Wlib1.dll" (ByVal X As Integer) As Integer
Declare Function read_game_port Lib "C:\Ioexp\Wlib1.dll" (ByVal X As Integer) As Integer
Declare Function Write_game_port Lib "c:\Ioexp\Wlib1.dll" () As Integer
Declare Function Interval_game_port Lib "c:\Ioexp\Wlib1.dll" (ByVal led_selected As Integer) As Integer

Sub Command1_Click ()
    DoEvents
    For i = 12 To 15
    status(i) = read_game_port(20 - i)
    If status(i) = 1 Then Shape1(i).BackColor = &HFF& Else Shape1(i).BackColor = black
    Next i
    DoEvents
    period = Interval_game_port(led_selected) * .838
    If period <> 0 Then
    Label2.Caption = "Period of Multivibrator: " & Format(period, "#####.#")
    Else
    Label2.Caption = "Error reading Multivibrator"
    End If

    Label5.Caption = "Resistance: " & Format(resistance(period), "###.#")
End Sub

Sub Command1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
     label6.Caption = " Get botton status and period of multivibrators"
End Sub

Sub Command2_Click (index As Integer)
    
    status(index) = 1 - status(index)
    If status(index) = 1 Then Shape1(index).BackColor = &HFF& Else Shape1(index).BackColor = black
    
    For i = 12 To 15
    status(i) = (read_game_port(i - 11) And Bit_weight(i - 11)) / Bit_weight(i - 11)
    If status(i) = 1 Then Shape1(i).BackColor = &HFF& Else Shape1(i).BackColor = black
    Next i
End Sub

Sub Command3_Click ()
    MsgBox ("Short the terminals of the selected resistance input. The selected channel is " & led_selected)
    interval_0(led_selected) = Interval_game_port(led_selected) * .838
    MsgBox ("Connect a standard resistor to the selected resistance input. The selected channel is " & led_selected)
    Standard_r(led_selected) = InputBox("Input the Resisance: ", "Calibration of resistance input", "1")
    interval_R(led_selected) = Interval_game_port(led_selected) * .838
End Sub

Sub Command3_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
    label6.Caption = " Generate Resistance vs. period curve"
End Sub

Sub Command4_Click ()
    End
End Sub

Sub Command4_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
    label6.Caption = " Quit the program"
End Sub

Sub Form_Load ()
    For i = 0 To 16
        status(i) = 0
    Next i

End Sub

Sub Option1_Click (index As Integer)
    led_selected = index + 1
End Sub

Sub Option1_MouseMove (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    label6.Caption = " Select No." & index + 1 & " resistance input channel"
End Sub

Function resistance (ByVal period As Single) As Single
    dummy2 = (interval_R(led_selected) - interval_0(led_selected))
    If Abs(dummy2) < .001 Then dummy2 = 1
    dummy = Standard_r(led_selected) / dummy2 * (period - interval_0(led_selected))
    If Abs(dummy) > 200 Then resistance = 200 Else resistance = dummy
End Function

