edurant.com > MSOE > SEED > Feasibility > Report > Appendix H: Visual Basic Code

Appendix H: Visual Basic Code

'VERSION 4.00
'______________________________________________
'VB demo program for Senior design project EE-407 @ MSOE
' Simulates the front panel and loads of the power supply
'Allows for functionality of the keypad and adjust current
as per the load applied
'
'Written by Charles Ulmschneider
'8 November 1996
'______________________________________________
'
'Define global variables
Newvolt As String, flgDEC

' Group of subs to change text to overload for appropriate supply

Private Sub overcurentPT()
Form1.Text15.Text = "Overload"
End Sub

Private Sub overcurentS2()
Form1.Text5.Text = "Overload"
End Sub
Private Sub overcurentMT()
Form1.Text4.Text = "Overload"
End Sub
Private Sub overcurentS1()
Form1.Text8.Text = "Overload"
End Sub

' set supply button
Private Sub Command13_Click()

If Form1.Text1.Text = "Tracking" Then

   'check for out of range , if so set to limit
   If Val(Form1.Text3.Text) > 50 Then Form1.Text3.Text = 50

   If Val(Form1.Text3.Text) < 0 Then Form1.Text3.Text = 0

   ' set text to correct voltage
    Form1.Text7.Text = Form1.Text3.Text
    Form1.Text2.Text = "±" & Form1.Text3.Text
End If

If Form1.Text1.Text = "Supply 1" Then

   'check for out of range , if so set to limit
   If Val(Form1.Text3.Text) > 50 Then Form1.Text3.Text = 50

   If Val(Form1.Text3.Text) < 0 Then Form1.Text3.Text = 0

   ' set text to correct voltage
    Form1.Text6.Text = Form1.Text3.Text
    Form1.Text2.Text = Form1.Text3.Text
End If

If Form1.Text1.Text = "Supply 2" Then

   'check for out of range , if so set to limit
   If Val(Form1.Text3.Text) > 50 Then Form1.Text3.Text = 50

   If Val(Form1.Text3.Text) < 0 Then Form1.Text3.Text = 0

   ' set text to correct voltage
    Form1.Text14.Text = Form1.Text3.Text
    Form1.Text2.Text = Form1.Text3.Text
End If
'reset NEWVOLT
Newvolt = ""
Form1.Text3.Text = Newvolt

End Sub
'Select buttons pushed
'Tracking
Private Sub Command14_Click()
Text1.Text = "Tracking"
Text2.Text = "±" & Text7.Text
End Sub
'Supply 1
Private Sub Command15_Click()
Text1.Text = "Supply 1"
Text2.Text = Text6.Text
End Sub
'Supply2
Private Sub Command16_Click()
Text1.Text = "Supply 2"
Text2.Text = Text14.Text
End Sub

'Power on/off Button
Private Sub Command17_Click()
Dim pwr, RP12, RM12, RM15, RP15, R5

'Retrieve current Loads for fixed supplies
RP12 = Form2.Text2.Text
RM12 = Form2.Text3.Text
RP15 = Form2.Text4.Text
RM15 = Form2.Text5.Text
R5 = Form2.Text1

'Check to se if on or off
pwr = Command17.Caption
 If pwr = "OFF" Then
'Turn Power ON, set light to red
Command17.Caption = "ON"
 Shape33.FillColor = &HFF&




 ' calculate currents for fixed supplies using current R's
        Text10.Text = Left(Str(12000 / RP12), 6) & "
ma"
        Text13.Text = Left(Str(12000 / RM12), 6) & "
ma"
        Text9.Text = Left(Str(15000 / RP15), 6) & "
ma"
        Text12.Text = Left(Str(15000 / RM15), 6) & "
ma"
        Text11.Text = Left(Str(5000 / R5), 6) & "
ma"

  ' initialize form1 for set supplies i.e. turn them on
        Text7.Text = 0
        Text15.Text = "0 mA"
        Text4.Text = "0 mA"
        Text1.Text = "NONE"
        Text2.Text = " "
        Text3.Text = " "
        Text6.Text = 0
        Text14.Text = 0
        Text8.Text = "0 mA"
        Text5.Text = "0 mA"

        Newvolt = ""
        flgDEC = 0
Else
 ' initialize form1 to off state
        Text7.Text = ""
        Text15.Text = ""
        Text4.Text = ""
        Text1.Text = ""
        Text2.Text = ""
        Text3.Text = ""
        Text6.Text = ""
        Text14.Text = ""
        Text8.Text = ""
        Text11.Text = ""
        Text10.Text = ""
        Text9.Text = ""
        Text13.Text = ""
        Text12.Text = ""
        Text5.Text = ""
       ' turn power light off
        Shape33.FillColor = &H40&

        Newvolt = ""
        flgDEC = 0
        Command17.Caption = "OFF"
End If
End Sub

'Keypad routine sets NEWVOLT=typed in value

Private Sub Command1_Click(Index As Integer)
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "7"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command10_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "0"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command11_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "."
Form1.Text3.Text = Newvolt
End Sub

' delete key option on keypad removes one character from
NEWVOLT string
Private Sub Command12_Click()
Newvolt = Left(Newvolt, Len(Newvolt) - 1)
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command2_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "8"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command3_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "9"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command4_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "4"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command5_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "5"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command6_Click()

Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "6"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command7_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "1"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command8_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "2"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Command9_Click()
Newvolt = (Form1.Text3.Text)
Newvolt = Newvolt & "3"
Form1.Text3.Text = Newvolt
End Sub

Private Sub Form_Load()
'load form 1 set defaults and start form 2(loads)

    Dim RP12, RM12, RP15, RM15, R5, RTP, RTM, RS1, RS2, pwr

'Display load form
Form2.Show


  ' initialize form1
        Text7.Text = ""
        Text15.Text = ""
        Text4.Text = ""
        Text1.Text = ""
        Text2.Text = ""
        Text3.Text = ""
        Text6.Text = ""
        Text14.Text = ""
        Text8.Text = ""
        Text11.Text = ""
        Text10.Text = ""
        Text9.Text = ""
        Text13.Text = ""
        Text12.Text = ""
        Text5.Text = ""


        Newvolt = ""
        flgDEC = 0
        Command17.Caption = "OFF"

End Sub

Private Sub Text14_Change()
'Change in load on supply 2
Dim numtest As Boolean
Dim RS2, RS2C, Crange, VT
numtest = IsNumeric(Form2.Text9.Text) And IsNumeric(Text14.Text)


'check to see if it is a number
If numtest Then
VT = 1000 * Val(Form1.Text14.Text)
    'Calculate current
        RS2 = Form2.Text9.Text
        If VT = 0 Then
        RS2C = 0
        Else
        RS2C = (VT / RS2)
        End If

    ' check for overload condition
        If RS2C > 1000 Then
         overcurentS2
        Else
            'set Range
If RS2C < 1 Then
                RS2C = RS2C * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
    'update current in textbox
    Form1.Text5.Text = Left(Str(RS2C), 6) & Crange
    End If


Else
' set to 0 if non number
    Form1.Text5.Text = "0.0 ma"
End If

End Sub

Private Sub Text6_Change()
'Change in load on supply 1
Dim numtest As Boolean
Dim RS1, RS1C, Crange, VT
numtest = IsNumeric(Form2.Text8.Text) And IsNumeric(Text6.Text)


' check to see if load is a number
If numtest Then
VT = 1000 * Val(Form1.Text6.Text)
    ' calculate current
        RS1 = Form2.Text8.Text
        If VT = 0 Then
        RS1C = 0
        Else
        RS1C = (VT / RS1)
        End If

    ' check for overload
        If RS1C > 1000 Then
         overcurentS1
        Else
 'set range
            If RS1C < 1 Then
                RS1C = RS1C * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
        'update texxbox with current
    Form1.Text8.Text = Left(Str(RS1C), 6) & Crange
    End If


Else
'set to 0 if non numeric
    Form1.Text8.Text = "0.0 ma"
End If

End Sub

Private Sub Text7_Change()
'Change in load on tracking supply
Dim numtest As Boolean
Dim RMT, RMTC, Crange, VT
numtest = IsNumeric(Form2.Text7.Text) And IsNumeric(Text7.Text)


'check for non numeric entry in load
If numtest Then
VT = 1000 * Val(Form1.Text7.Text)
    'calculate current
        RMT = Form2.Text7.Text
        If VT = 0 Then
        RMTC = 0
        Else
        RMTC = (VT / RMT)
        End If

    ' check for overload
        If RMTC > 1000 Then
         overcurentMT
        Else
 'set range
            If RMTC < 1 Then
                RMTC = RMTC * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
      'update text box with current
    Form1.Text4.Text = Left(Str(RMTC), 6) & Crange
    End If


Else
'set to 0 for non numeric
    Form1.Text4.Text = "0.0 ma"
End If

Dim RPT, RPTC
'tracking supply calculations part two
numtest = IsNumeric(Form2.Text6.Text) And IsNumeric(Form1.Text7.Text)


'check load on neg. side
If numtest Then
VT = 1000 * Val(Form1.Text7.Text)
    'calculate current
        RPT = Form2.Text6.Text
        If VT = 0 Then
        RPTC = 0
        Else
        RPTC = (VT / RPT)
        End If

    'check for overload
        If RPTC > 1000 Then
         overcurentPT
        Else
 'set range
            If RPTC < 1 Then
                RPTC = RPTC * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If

    Form1.Text15.Text = Left(Str(RPTC), 6) & Crange
    End If


Else
    Form1.Text15.Text = "0.0 ma"
End If
End Sub

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@

VERSION 4.00
'Load form
'subs to display over current on front panel if loads change
causes overcurrent
Private Sub overcurent5()
Form1.Text11.Text = "Overload"
End Sub
Private Sub overcurentS2()
Form1.Text5.Text = "Overload"
End Sub
Private Sub overcurentS1()
Form1.Text8.Text = "Overload"
End Sub
Private Sub overcurentP15()
Form1.Text9.Text = "Overload"
End Sub
Private Sub overcurentMT()
Form1.Text4.Text = "Overload"
End Sub
Private Sub overcurentPT()
Form1.Text15.Text = "Overload"
End Sub
Private Sub overcurentM15()
Form1.Text12.Text = "Overload"
End Sub
Private Sub overcurentP12()
Form1.Text10.Text = "Overload"
End Sub
Private Sub overcurentM12()
Form1.Text13.Text = "Overload"
End Sub

'Terminate program and unload
Private Sub Command1_Click()
End
End Sub

'set initial values for loads on startup
Private Sub Form_Load()
Text1.Text = 1000
Text2.Text = 2500
Text3.Text = 3300
Text4.Text = 10000
Text5.Text = 10000
Text6.Text = 20000
Text7.Text = 20000
Text8.Text = 1000
Text9.Text = 1000
End Sub

Private Sub Text1_Change()
Dim numtest As Boolean

Dim R5, R5C, Crange

numtest = IsNumeric(Text1.Text)
'check for non numeric load
If numtest Then
    R5 = Text1.Text
'never let load go to 0
    If R5 <= 0 Then R5 = 0.0001

     'calculate current
    R5C = (5000 / R5)

'check for overload
    If R5C > 1000 Then
    overcurent5
    Else
 'set range
        If R5C < 1 Then
            R5C = R5C * 1000
            Crange = " uA"
            Else
                Crange = " mA"
        End If
        'update text box on front panel with current
    Form1.Text11.Text = Left(Str(R5C), 6) & Crange
    End If
Else
    Form1.Text11.Text = "0.0 ma"
End If

End Sub


Private Sub Text2_Change()
Dim numtest As Boolean
Dim RP12, RP12C, Crange
numtest = IsNumeric(Text2.Text)
'check for non numeric load
If numtest Then
    RP12 = Text2.Text
'load never 0
    If RP12 <= 0 Then RP12 = 0.0001

 'calculate current
    RP12C = (12000 / RP12)

    'check for overload
    If RP12C > 1000 Then
    overcurentP12
    Else
'set range
        If RP12C < 1 Then
            RP12C = RP12C * 1000
            Crange = " uA"
            Else
                Crange = " mA"
        End If
       'update textbox on front panel with current
    Form1.Text10.Text = Left(Str(RP12C), 6) & Crange
    End If
Else
    Form1.Text10.Text = "0.0 ma"
End If
End Sub

Private Sub Text3_Change()
Dim numtest As Boolean
Dim RM12, RM12C, Crange
numtest = IsNumeric(Text3.Text)

'check for non numeric in load
If numtest Then
    RM12 = Text3.Text
'load never 0
    If RM12 <= 0 Then RM12 = 0.0001

'Calculate current
    RM12C = (12000 / RM12)

'check for overload
    If RM12C > 1000 Then
    overcurentM12

'set range
    Else
        If RM12C < 1 Then
            RM12C = RM12C * 1000
            Crange = " uA"
            Else
                Crange = " mA"
        End If

        'update textbox on front panel with current
    Form1.Text13.Text = Left(Str(RM12C), 6) & Crange
    End If
Else
    Form1.Text13.Text = "0.0 ma"
End If
End Sub

Private Sub Text4_Change()
Dim numtest As Boolean
Dim RP15, RP15C, Crange
numtest = IsNumeric(Text4.Text)

'check for non numeric load
If numtest Then
    RP15 = Text4.Text
'load never 0
    If RP15 <= 0 Then RP15 = 0.0001

'calculate current
    RP15C = (15000 / RP15)

'check for overload
    If RP15C > 1000 Then
    overcurentP15

    Else
'set range
        If RP15C < 1 Then
            RP15C = RP15C * 1000
            Crange = " uA"
            Else
                Crange = " mA"
        End If
    'update textbox on front panel with current
    Form1.Text9.Text = Left(Str(RP15C), 6) & Crange
    End If
Else
    Form1.Text9.Text = "0.0 ma"
End If
End Sub

Private Sub Text5_Change()
Dim numtest As Boolean
Dim RM15, RM15C, Crange
numtest = IsNumeric(Text5.Text)
'check for non numeric load
If numtest Then
    RM15 = Text5.Text

'load never 0
    If RM15 <= 0 Then RM15 = 0.0001
   'calculate current
    RM15C = (15000 / RM15)
    'check for overload
    If RM15C > 1000 Then
    overcurentM15
    Else
'set range
        If RM15C < 1 Then
            RM15C = RM15C * 1000
            Crange = " uA"
            Else
                Crange = " mA"
        End If
     'update text box on front panel with current
    Form1.Text12.Text = Left(Str(RM15C), 6) & Crange
    End If
Else
    Form1.Text12.Text = "0.0 ma"
End If
End Sub

Private Sub Text6_Change()
Dim numtest As Boolean
Dim RPT, RPTC, Crange, VT
numtest = IsNumeric(Text6.Text)

'check for non numeric load
If numtest Then
VT = 1000 * Val(Form1.Text7.Text)

        RPT = Text6.Text
'load never =0
        If RPT <= 0 Then RPT = 0.0001

        If VT = 0 Then
        RPTC = 0
        Else
 'calculate current
        RPTC = (VT / RPT)
        End If

    'check for overload
        If RPTC > 1000 Then
         overcurentPT
        Else
'set range
            If RPTC < 1 Then
                RPTC = RPTC * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
       'update text box on front panel with current
    Form1.Text15.Text = Left(Str(RPTC), 6) & Crange
    End If
    Else
    Form1.Text15.Text = "0.0 ma"
End If
End Sub

Private Sub Text7_Change()
Dim numtest As Boolean
Dim RMT, RMTC, Crange, VT
numtest = IsNumeric(Text7.Text)
'check for non numeric load
If numtest Then
VT = 1000 * Val(Form1.Text7.Text)

        RMT = Text7.Text
'load never =0
        If RMT <= 0 Then RMT = 0.0001

        If VT = 0 Then
        RMTC = 0
        Else
'calculate current
        RMTC = (VT / RMT)
        End If

    'check for overload
        If RMTC > 1000 Then
         overcurentMT
        Else
'set range
            If RMTC < 1 Then
                RMTC = RMTC * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
        'update text box on front panel with current
    Form1.Text4.Text = Left(Str(RMTC), 6) & Crange
    End If
Else
    Form1.Text4.Text = "0.0 ma"
End If
End Sub

Private Sub Text8_Change()
Dim numtest As Boolean
Dim RS1, RS1C, Crange, VT
numtest = IsNumeric(Text8.Text)
'check for non numeric load
If numtest Then
VT = 1000 * Val(Form1.Text6.Text)

        RS1 = Text8.Text
'load never =0
        If RS1 <= 0 Then RS1 = 0.0001

        If VT = 0 Then
        RS1C = 0
'calculate current
        Else
        RS1C = (VT / RS1)
        End If

    'check for overload
        If RS1C > 1000 Then
         overcurentS1
        Else
'set range
            If RS1C < 1 Then
                RS1C = RS1C * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
        'update text box on front panel with current
    Form1.Text8.Text = Left(Str(RS1C), 6) & Crange
    End If
    Else
    Form1.Text8.Text = "0.0 ma"
End If
End Sub

Private Sub Text9_Change()
Dim numtest As Boolean
Dim RS2, RS2C, Crange, VT
numtest = IsNumeric(Text9.Text)

'Check for non numeric load
If numtest Then
VT = 1000 * Val(Form1.Text14.Text)

        RS2 = Text9.Text
'load never =0
        If RS2 <= 0 Then RS2 = 0.0001

        If VT = 0 Then
        RS2C = 0
        Else
'calculate current
        RS2C = (VT / RS2)
        End If

    'check for over load
        If RS2C > 1000 Then
         overcurentS2
        Else
'set range
            If RS2C < 1 Then
                RS2C = RS2C * 1000
                Crange = " ua"
            Else
                Crange = " mA"
        End If
        'update text box on front panel with current
    Form1.Text5.Text = Left(Str(RS2C), 6) & Crange
    End If
    Else
    Form1.Text5.Text = "0.0 ma"
End If
End Sub