Solved

If statement causes for next loop to exit

Posted on 2014-03-20
4
124 Views
Last Modified: 2014-08-25
Hello,

I have a for next loop interating over a collection of dataset rows,

I want to insert a couple of if statements to populate a couple of cells in the rows but I'm finding as soon as the first if statement is processed the for next loop is exited.

Am I missing something?

Thanks
0
Comment
Question by:Petermcg001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39942416
Probably a problem with your structure, if you show the code we can help.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39942463
which programming language exactly?
it must be an explicit "code" in your code to "break" to "exit" the loop, please post the relevant part of the code
0
 
LVL 1

Author Comment

by:Petermcg001
ID: 39942504
Thanks for looking at this,

My vb.net code is:-
For Each DeliveryTicketRow As dsDeliveryTickets.UnprintedTicketsRow In DsDeliveryTickets.UnprintedTickets
            AccountsTableAdapter.FillBy(DsAccounts.Accounts, DeliveryTicketRow.Account)
            Account = DsAccounts.Accounts(0)
            With DeliveryTicketRow
                .AccountAddress1 = Account.AddressLine1
                .AccountAddress2 = Account.AddressLine2
                .AccountAddress3 = Account.AddressLine3
                .AccountTown = Account.AddressLine4
                .AccountName = Account.CustomerAccountName
                .AccountPostcode = Account.PostCode
                .AccountTelephoneNumber = Account.TelephoneNumber
                If .StatusFlag = "U" Then .UrgentText = "Urgent"


                If .LineNote = "F" Then .FillText = "Fill"


            End With

        Next

Open in new window


As soon as the first if is processed the loop exits.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39949824
the code as such does not show anything that shall raise this issue.
so, either you have some (unhandled) error somewhere, OR it's the WITH statement structure which might give you that issue.
please try to run the code without the WITH, like this
For Each DeliveryTicketRow As dsDeliveryTickets.UnprintedTicketsRow In DsDeliveryTickets.UnprintedTickets
            AccountsTableAdapter.FillBy(DsAccounts.Accounts, DeliveryTicketRow.Account)
            Account = DsAccounts.Accounts(0)
            
                DeliveryTicketRow.AccountAddress1 = Account.AddressLine1
                DeliveryTicketRow.AccountAddress2 = Account.AddressLine2
                DeliveryTicketRow.AccountAddress3 = Account.AddressLine3
                DeliveryTicketRow.AccountTown = Account.AddressLine4
                DeliveryTicketRow.AccountName = Account.CustomerAccountName
                DeliveryTicketRow.AccountPostcode = Account.PostCode
                DeliveryTicketRow.AccountTelephoneNumber = Account.TelephoneNumber
                If DeliveryTicketRow.StatusFlag = "U" Then DeliveryTicketRow.UrgentText = "Urgent"


                If DeliveryTicketRow.LineNote = "F" Then DeliveryTicketRow.FillText = "Fill"

        Next

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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