Community
Showing results for 
Search instead for 
Do you mean 
Reply

How to exit code?

Accepted Solution Solved
Copper Super Contributor
Posts: 478
Country: Australia
Accepted Solution

How to exit code?

Hi All

 

Over the years i have built code for my Act database it is however rather raw, i have one lot of code that relies on about 30 fields being not NULL, if one is NULL it kicks the code out with an error message exception and its a pain to work out which one kicked the code

 

I want to write some checking code eg: IF NULL or IF NOT NULL which i know how to do

 

But if it triggers the NULL code whats the line to kick the process out and finish the code??? Or how to build in specific exceptions?

 

Thanks


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6

Accepted Solutions
Highlighted
Solution
Accepted by topic author JasonD
2 weeks ago
Nickel Contributor
Posts: 172
Country: USA

Re: How to exit code?

That's much simpler than what I thought earlier. The code below is off the top of my head as I'm creating this post, so there could be issues.

Private Function HasNull(byval data as System.Data.Datarow) As Boolean
    Dim nullValue as Boolean = False
    For each o as Object in data.ItemArray
         If o = DBNull.Value Then
            nullValue=True
            Exit For
        End If
    Next
    Return nullValue

End Function

 

So that would be the test. Then you'd just need to call that in your main method, such as:

'... previous code

If HasNull(myDataRow) = False Then

    ' Do all of your processing here

End If

 

This is a very basic/generic example, so if you need more complexity, you'll have to build it up. If you want a list of fields that are null, you'd want to return a list of strings or something like that instead of Boolean.

View solution in original post


All Replies
Nickel Contributor
Posts: 172
Country: USA

Re: How to exit code?

It sounds like you have a bit of restructuring to do. You're going to have to look over your existing code and processes. For each field, you'll have to ask questions like "Can I safely skip over this field or does something later on depend on this?" Based on the answers, you'll have to develop a means of handling the zero to many NULL fields. Without knowing anything about your code, my thought process went to how I would do this. For me, it would be nice to pass my row or data structure to a routine that spits out a list of fields that are null. In my main processing routine, I'd try to loop through that list or use it in a test (if field in Null-List, skip it), but it really depends on what you are trying to accomplish. Other than that, that's all I can really provide. Hopefully this will spark an idea or two.

Copper Super Contributor
Posts: 478
Country: Australia

Re: How to exit code?

Thanks for the reply
The code in question is one that produces a summary report on the client and time spent working on the client file

It access standard contact fields (about 15) History of the contact for the last 12 months and dumps it into contact fields (about 12) along with the Groups table and a custom table for commission payments

Because there is so many my plan was to put right up front a "test" or "check" code where it will basically just go and check the fields are not Null

My problem is how do i end/exit the code if there is a Null field?
I can do a standard If statement and if a field is null throw up a message to tell me but whats the next line of code to kill it and stop the code from continuing

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Nickel Contributor
Posts: 172
Country: USA

Re: How to exit code?

I want to clarify to make sure I'm understanding this correctly. If you come across a null value in a field, you want to stop execution of the whole routine.

Is this correct?
Copper Super Contributor
Posts: 478
Country: Australia

Re: How to exit code?

yes please

I have googled and searched this site without having much luck.. little bits of a teaser but nothing complete

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Highlighted
Solution
Accepted by topic author JasonD
2 weeks ago
Nickel Contributor
Posts: 172
Country: USA

Re: How to exit code?

That's much simpler than what I thought earlier. The code below is off the top of my head as I'm creating this post, so there could be issues.

Private Function HasNull(byval data as System.Data.Datarow) As Boolean
    Dim nullValue as Boolean = False
    For each o as Object in data.ItemArray
         If o = DBNull.Value Then
            nullValue=True
            Exit For
        End If
    Next
    Return nullValue

End Function

 

So that would be the test. Then you'd just need to call that in your main method, such as:

'... previous code

If HasNull(myDataRow) = False Then

    ' Do all of your processing here

End If

 

This is a very basic/generic example, so if you need more complexity, you'll have to build it up. If you want a list of fields that are null, you'd want to return a list of strings or something like that instead of Boolean.