Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ignore the first entry in the loop

Posted on 2011-10-12
7
Medium Priority
?
223 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:csharp_learner
7 Comments
 
LVL 4

Expert Comment

by:Christopher Raymond Mendoza
ID: 36954627
Try using Dim instead of Const.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36954652
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36954669
Move the variable into the sub itself as

Static counter
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:csharp_learner
ID: 36954695
Can you explain it with my code? I'm not very strong in vb so don quite understand.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1600 total points
ID: 36954725
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
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36954754
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
 

Author Closing Comment

by:csharp_learner
ID: 36954755
Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question