SysIntegrator
Member
Hey,
I'm looking for a bit of guidance on some vba code in RSView32. For the record I know zero (I know its shameful) VBA code.
What I'm trying to do is take 8 Digital tags and convert it back to an Analog tag. I don't have any means to transmit this data as an analog value.
I've never written any VBA code before so I did some looking around and found this site:
http://www.vb-helper.com/howto_decimal_to_binary.html
But I'm not sure how it all looks when it gets finished. I know I need to go and fetch all my discrete tags, but I'm not really sure where my variables get dropped into that example code. So far I've got this:
Public Function GROB35_ERRORCODE(Binary As String) As Long
Set gTagDb.GetTag("GROBS\35_ERROR_0") = BIT_0
Set gTagDb.GetTag("GROBS\35_ERROR_1") = BIT_1
Set gTagDb.GetTag("GROBS\35_ERROR_2") = BIT_2
Set gTagDb.GetTag("GROBS\35_ERROR_3") = BIT_3
Set gTagDb.GetTag("GROBS\35_ERROR_4") = BIT_4
Set gTagDb.GetTag("GROBS\35_ERROR_5") = BIT_5
Set gTagDb.GetTag("GROBS\35_ERROR_6") = BIT_6
Set gTagDb.GetTag("GROBS\35_ERROR_7") = BIT_7
Dim n As Long
Dim s As Integer
For s = 1 To Len(Binary)
n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ _
(s - 1)))
Next s
BinaryToDecimal = n
Set Error = gTagDb.GetTag("GROBS\35_ERROR")
End Function
Any guidance is appreciated, thanks.
I'm looking for a bit of guidance on some vba code in RSView32. For the record I know zero (I know its shameful) VBA code.
What I'm trying to do is take 8 Digital tags and convert it back to an Analog tag. I don't have any means to transmit this data as an analog value.
I've never written any VBA code before so I did some looking around and found this site:
http://www.vb-helper.com/howto_decimal_to_binary.html
But I'm not sure how it all looks when it gets finished. I know I need to go and fetch all my discrete tags, but I'm not really sure where my variables get dropped into that example code. So far I've got this:
Public Function GROB35_ERRORCODE(Binary As String) As Long
Set gTagDb.GetTag("GROBS\35_ERROR_0") = BIT_0
Set gTagDb.GetTag("GROBS\35_ERROR_1") = BIT_1
Set gTagDb.GetTag("GROBS\35_ERROR_2") = BIT_2
Set gTagDb.GetTag("GROBS\35_ERROR_3") = BIT_3
Set gTagDb.GetTag("GROBS\35_ERROR_4") = BIT_4
Set gTagDb.GetTag("GROBS\35_ERROR_5") = BIT_5
Set gTagDb.GetTag("GROBS\35_ERROR_6") = BIT_6
Set gTagDb.GetTag("GROBS\35_ERROR_7") = BIT_7
Dim n As Long
Dim s As Integer
For s = 1 To Len(Binary)
n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ _
(s - 1)))
Next s
BinaryToDecimal = n
Set Error = gTagDb.GetTag("GROBS\35_ERROR")
End Function
Any guidance is appreciated, thanks.