Solved

If statement causes for next loop to exit

Posted on 2014-03-20
4
118 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
  • 2
4 Comments
 
LVL 26

Expert Comment

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

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 142

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now