DMain
01-14-2015, 02:44 AM
Hello,
I am trying to create a digital flip flop in VBA in order to test some data. The basics of the function are that it has 2 inputs, set and reset, and an output Q as follows in the Table bellow.
Input S
Input R
Output Q
1
1
1
1
0
1
0
1
0
0
0
Q(previous)
The function will only ever use binary values, 1 or 0. My code is basically 4 ifelse statements - for example if s and r = 1 then q = 1. My issue occurs when both the input S and R are zero. The output of the function should do nothing, i.e. hold the previous value however in my code the answer always defaults to zero. I am very new to VBA so any help would be appreciated. My code is as follows;
Function FLIP_FLOP(S, R) As Double
If S = 0 And R = 0 Then
Exit Function
ElseIf S = 0 And R = 1 Then
FLIP_FLOP = 0
ElseIf S = 1 And R = 0 Then
FLIP_FLOP = 1
ElseIf S = 1 And R = 1 Then
FLIP_FLOP = 1
ElseIf S = 0 And R = 0 Then
End If
End Function
Thanks for any help,
DMain
I am trying to create a digital flip flop in VBA in order to test some data. The basics of the function are that it has 2 inputs, set and reset, and an output Q as follows in the Table bellow.
Input S
Input R
Output Q
1
1
1
1
0
1
0
1
0
0
0
Q(previous)
The function will only ever use binary values, 1 or 0. My code is basically 4 ifelse statements - for example if s and r = 1 then q = 1. My issue occurs when both the input S and R are zero. The output of the function should do nothing, i.e. hold the previous value however in my code the answer always defaults to zero. I am very new to VBA so any help would be appreciated. My code is as follows;
Function FLIP_FLOP(S, R) As Double
If S = 0 And R = 0 Then
Exit Function
ElseIf S = 0 And R = 1 Then
FLIP_FLOP = 0
ElseIf S = 1 And R = 0 Then
FLIP_FLOP = 1
ElseIf S = 1 And R = 1 Then
FLIP_FLOP = 1
ElseIf S = 0 And R = 0 Then
End If
End Function
Thanks for any help,
DMain