Sign in to follow this  
Followers 0
sachincool786

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

6 posts in this topic

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???

Share this post


Link to post
Share on other sites

i recommend when writing programs to use modular approach and test each method/function individually. also avoid long expressions, it is easier to step through and debug. and yes you can use debug mode to step through code and see what each line does.

for example here you are fighting with Mid() method. Also it is unclear what exactly is " txtHorno".

so.... first things first:

"" are used when specifying string constant (value). do not use "" if evaluating function.

example:

Sub test()

Dim s1, s2 As String

s1 = "hello world" ' assigning constant
s2 = Mid(s1, 4, 5) ' evaluating function - returns "lo wo"

End Sub

notice that Mid() is not placed inside ""

if txtHorno is a string, then you would assign value to it just like we did with S1 and S2.

if txtHorno is a label or text box, you would use dot operator to drill down to appropriate parameter (.text, .caption, .value etc.). normally your environment will provide intelisense (offer help as you type).

VBA is very common scripting language. it is used in MANY programs, including Microsoft Office. For example, i can test (and debug) above example in Excel (notice use of breakpoint and displayed value of S2 when hovering mouse over variable):

 

 

VBA.png

Share this post


Link to post
Share on other sites

This one i understood..What about the other 2 questions???

 

The problem is: no error is coming when I debug the code.

Share this post


Link to post
Share on other sites

Where are you declaring txtHorno?

Share this post


Link to post
Share on other sites

also try to provide complete information with each question. i am pretty busy and quickly lose interest if things that are not affecting me directly. sure it is nice to help others but by the time i dig out all the details, explain what is missing, locate and read datasheets, or make guess what the question is all about, i may get bored.  i do not promise to get back to this (it is a holiday season and i have family too) and i am pretty sure others value their time too. if you want others to help you, you need to make it much easier. for example:

1. you did not mention what product you are working with (I am assuming  it is FT View SE v8.0 since you had other posts but still, this is just a guess).

2. you don't mention type of driver or interface you are using - for all we know, it could be one of many products out there (i have used various OPC and ActiveX over the years). 

3. you still did not explain what is  txtHorno, where is declared and how. (you have been asked twice already).

 

Did you read documentation and check examples included with your product?

Finally did you search forum? Many things are likely already discussed, for example:

http://forums.mrplc.com/index.php?/topic/23632-factorytalk-view-se/

 

 

Share this post


Link to post
Share on other sites

I am using FT View SE v8.0

Communicating "control logix" and "FT View SE v8.0" through RSLinx

txtHorno is a hidden "string display" which is VBA controlled on the screen

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0