VBA code problem...need ur help to find the bug

sachincool786

Member
Join Date
Dec 2014
Location
india
Posts
48
Public WithEvents oGroup1 As TagGroup
Public vidrios1, vidrios2, vidrios3, vidrios4, vidrios5, vidrios6, vidrios7, vidrios8, vidrios9 As String
Public str_vidrios1, str_vidrios2, str_vidrios3, str_vidrios4, str_vidrios5, str_vidrios6, str_vidrios7, str_vidrios8, str_vidrios9 As String


Public Sub Display_AnimationStart()
Dim TagsInError1 As StringList
On Error Resume Next
Err.Clear
If oGroup1 Is Nothing Then
Set oGroup1 = Application.CreateTagGroup(Me.AreaName, 500)
If Err.Number Then
LogDiagnosticsMessage "Error creating TagGroup. Error: " _
& Err.Description, ftDiagSeverityError
Exit Sub
End If
oGroup1.Add "[0]comm_furnace_glasses[0]"
oGroup1.Add "[0]comm_furnace_glasses[1]"
oGroup1.Add "[0]comm_furnace_glasses[2]"
oGroup1.Add "[0]comm_furnace_glasses[3]"
oGroup1.Add "[0]comm_furnace_glasses[4]"
oGroup1.Add "[0]comm_furnace_glasses[5]"
oGroup1.Add "[0]comm_furnace_glasses[6]"
oGroup1.Add "[0]Glass[0]"
oGroup1.Active = True
oGroup1.RefreshFromSource TagsInError1
End If

End Sub


Private Sub oGroup1_Change(ByVal TagNames As IGOMStringList)
On Error Resume Next
Dim oTag11, oTag21, oTag31, oTag41, oTag51, oTag61, oTag71 As Tag
Dim oTag100 As Tag

Dim str_bits1 As String

If Not oGroup1 Is Nothing Then
Set oTag11 = oGroup1.Item("[0]comm_furnace_glasses[0]")
Set oTag21 = oGroup1.Item("[0]comm_furnace_glasses[1]")
Set oTag31 = oGroup1.Item("[0]comm_furnace_glasses[2]")
Set oTag41 = oGroup1.Item("[0]comm_furnace_glasses[3]")
Set oTag51 = oGroup1.Item("[0]comm_furnace_glasses[4]")
Set oTag61 = oGroup1.Item("[0]comm_furnace_glasses[5]")
Set oTag71 = oGroup1.Item("[0]comm_furnace_glasses[6]")
Set oTag100 = oGroup1.Item("[0]Glass[0]")

m_vidrios.str_bits (str_bits1)

str_vidrios1 = str_bits1(CStr(oTag11))
str_vidrios2 = str_bits1(CStr(oTag21))
str_vidrios3 = str_bits1(CStr(oTag31))
str_vidrios4 = str_bits1(CStr(oTag41))
str_vidrios5 = str_bits1(CStr(oTag51))
str_vidrios6 = str_bits1(CStr(oTag61))
str_vidrios7 = str_bits1(CStr(oTag71))
Err.Clear
End If
txtHorno.Value = "Mid(str_vidrios1, 1, 31) & Mid(str_vidrios2, 1, 31) & Mid(str_vidrios3, 1, 31) & Mid(str_vidrios4, 1, 31) & Mid(str_vidrios5, 1, 31) & Mid(str_vidrios6, 1, 31) & Mid(str_vidrios7, 1, 31)"

If Mid(txtHorno, 1, 1) = "1" Then

oTag100.Value = 0

End If

If Mid(txtHorno, 1, 1) = "0" Then

oTag100.Value = 1

End If
End Sub




I have some doubts , please help debugging it :

1) txtHorno is a name of string display object (which is VBA controlled) :

txtHorno.Value = "Mid(str_vidrios1, 1, 31) & Mid(str_vidrios2, 1, 31) & Mid(str_vidrios3, 1, 31) & Mid(str_vidrios4, 1, 31) & Mid(str_vidrios5, 1, 31) & Mid(str_vidrios6, 1, 31) & Mid(str_vidrios7, 1, 31)"

is it right???
should i write "" because this is returning a string???
should i write "txtHorno.Value =" or just "txtHorno ="
if not please tell me the correct way to write it, actually txtHorno is a string in which i want to move the above(function returned) value.


2)m_vidrios is my module name in which i have defined a public function so that i can use it in my form :

m_vidrios.str_bits (str_bits1)

Is it a right way to call it???

The code of module named "m_vidrios" is :

Function str_bits(entrada As String) As String

Dim i, j As Integer
Dim Temp As Double

Temp = Abs(CDbl(entrada))

str_bits = "0000000000000000000000000000000"

i = 0

If Temp = 1 Then

str_bits = "10000000000000000000000000000000"

GoTo A:

ElseIf Temp = 0 Then

str_bits = "00000000000000000000000000000000"

GoTo A:

End If

For i = 31 To 1 Step -1

If Temp / 2 ^ i >= 1 Then

str_bits = Mid(str_bits, 2, i - 1) & "1" & Mid(str_bits, i + 1, Len(str_bits) - i)

Temp = Temp - (2 ^ i)

Else:

str_bits = Mid(str_bits, 2, i - 1) & "0" & Mid(str_bits, i + 1, Len(str_bits) - i)

End If

Next i

If Temp = 1 Then

str_bits = "1" & str_bits

Else:
str_bits = "0" & str_bits

End If





A:

End Function





3) oTag100.Value = 1

will update my PLC tag "[0]Glass[0]" high automatically or i have to write anything else???
 
I have some doubts , please help debugging it :

1) txtHorno is a name of string display object (which is VBA controlled) :

txtHorno.Value = "Mid(str_vidrios1, 1, 31) & Mid(str_vidrios2, 1, 31) & Mid(str_vidrios3, 1, 31) & Mid(str_vidrios4, 1, 31) & Mid(str_vidrios5, 1, 31) & Mid(str_vidrios6, 1, 31) & Mid(str_vidrios7, 1, 31)"

is it right???
should i write "" because this is returning a string???
should i write "txtHorno.Value =" or just "txtHorno ="
if not please tell me the correct way to write it, actually txtHorno is a string in which i want to move the above(function returned) value.
You should definitely NOT enclose the entire thing in quotes ("") - that just makes the entire thing a literal string. Mid is a function which returns a substring and the '&' thing concatenates those individual strings together.
I think the assignment should be to txtHorno.Text (but that's from my VB6 experience - not sure if the VBA is exactly the same).

2)m_vidrios is my module name in which i have defined a public function so that i can use it in my form :

m_vidrios.str_bits (str_bits1)

Is it a right way to call it???

The code of module named "m_vidrios" is :

Function str_bits(entrada As String) As String

Dim i, j As Integer
Dim Temp As Double

Temp = Abs(CDbl(entrada))

str_bits = "0000000000000000000000000000000"

i = 0

If Temp = 1 Then

str_bits = "10000000000000000000000000000000"

GoTo A:

ElseIf Temp = 0 Then

str_bits = "00000000000000000000000000000000"

GoTo A:

End If

For i = 31 To 1 Step -1

If Temp / 2 ^ i >= 1 Then

str_bits = Mid(str_bits, 2, i - 1) & "1" & Mid(str_bits, i + 1, Len(str_bits) - i)

Temp = Temp - (2 ^ i)

Else:

str_bits = Mid(str_bits, 2, i - 1) & "0" & Mid(str_bits, i + 1, Len(str_bits) - i)

End If

Next i

If Temp = 1 Then

str_bits = "1" & str_bits

Else:
str_bits = "0" & str_bits

End If





A:

End Function
That appears to be okay.
You can also just replace the 'Goto A' with 'End Function'. But what you have also works.



3) oTag100.Value = 1

will update my PLC tag "[0]Glass[0]" high automatically or i have to write anything else???
[/quote]
I cannot say for certain - never used VBA with FTSE.
But, it looks like it could work.
 
Dear Sir,

Want your help badly...please help...


If you just set it to a value, does it work?

txtHorno.Value = "Test String"

?

I think so..it should work..VB is not giving me any error..Is there any other way to write it????How can i write it then...Please help

Is txtHorno exposed to vba as a control?



txtHorno is my string display on the screen which is VBA controlled
 

Similar Topics

Hello Every one, I need a help on vba code for getting data from MSSQL server 2014 to display in FTview SE client version 12 . Thanks. Please...
Replies
4
Views
1,832
Hoping for some help on this one, we are running FTVIEW SE distributed on a server. The client file runs fine on this server. We have...
Replies
4
Views
3,782
Hello, it's been a little over a year now that I've been learning citect scada alone in version 7.2, I know how to make pages, synoptics, create...
Replies
4
Views
7,084
Hello guys, can anyone help me with FactoryTalk View Studio. I need to use a Global Object that contains VBA Macros in different displays, but it...
Replies
1
Views
1,689
I have VBA code on a FactorTalk View SE v11 project that reads various PLC tags in a FOR loop. All is good if the PLC tag exist. But for a...
Replies
4
Views
3,564
Back
Top Bottom