ignore the first entry in the loop

Hi,

I am stuck in vb script coding.

The thing i want to achieve is to bypass the codes and do nothing during my first entry into the Private Sub ObjOPCGroup_DataChange

I tried using a Const but an error was given saying i cannot set a constant.
Can any experts help on this?
Const counter = 0

Private Sub ObjOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
    Dim i As Integer
    Dim strChanges As String
    
    If counter = 0 Then
    MsgBox "first time in the loop, do nothing"
    Else
    counter = 1
    For i = 1 To NumItems
        strChanges = "do somthing"
    Next i
    
    MsgBox strChanges
    End If
End Sub

Open in new window

csharp_learnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Christopher Raymond MendozaCommented:
Try using Dim instead of Const.
0
Patrick MatthewsCommented:
Also, this is NOT VBScript.  VB6, perhaps, but not VBScript.  (For one thing, VBScript is weakly typed, so you cannot declare a variable or a constant as any particular data type.)
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Move the variable into the sub itself as

Static counter
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

csharp_learnerAuthor Commented:
Can you explain it with my code? I'm not very strong in vb so don quite understand.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
i.e.
Private Sub ObjOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)

Static counter as integer
    Dim i As Integer
    Dim strChanges As String
    
    If counter = 0 Then
    MsgBox "first time in the loop, do nothing"
    Else
    counter = 1
    For i = 1 To NumItems
        strChanges = "do somthing"
    Next i
    
    MsgBox strChanges
    End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pratima PharandeCommented:
Static counter as integer = 0

Private Sub ObjOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)

    Dim i As Integer
    Dim strChanges As String
   
    If counter = 0 Then
    MsgBox "first time in the loop, do nothing"
    Else
    counter = 1
    For i = 1 To NumItems
        strChanges = "do somthing"
    Next i
    counter = counter  +1
    MsgBox strChanges
    End If
End Sub
0
csharp_learnerAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.