Jump to content
Sign in to follow this  
AvgGamerGuy

Need some help with my logic

Recommended Posts

AvgGamerGuy

The following section of code reads two nodes from an XML file. Each node should be an array of up to 14 items. Some of the items may be blank. One node contains monthly payment amounts and the other node contains the dates that the payments are due on. The section of code I'm having trouble with is a function designed to check the data and verify that there is an equal number of payments and dates (i.e. if there are 10 scheduled payment dates in the payment date node, there should be a corrosponding 10 payments in the payment node). The function should compare each unit of the array in the payment node with the payment date node and makes sure that if one is blank or empty that the other one is empty and should assign an error value if one node has something and the other one doesn't. But it's not setting my error flag. Code is below

CODE

Func _PaymentAndDateError($PaymentNode, $PaymentDueDateNode);--------

Local $NumOfPayments, $NumOfScheduledDates

Local $EqualError = 0

$NumOfPayments = _XMLGetValue($PaymentNode)

$NumOfScheduledDates = _XMLGetValue($PaymentDueDateNode)

If IsArray ($NumOfPayments) And IsArray ($NumOfScheduledDates) Then

For $T = 1 to 14

MsgBox(0, "Debug", "$NumOfPayments[" & $T & "] = " & $NumOfPayments[$T] & "$NumOfScheduledDates[" & $T & "] = " & $NumOfScheduledDates[$T]); debug msgbox

MsgBox(0, "EqualError", "$EqualError = " & $EqualError); debug msgbox

If (($NumOfPayments[$T] = "") And ($NumOfScheduledDates[$T] <> "")) Then ; this is where i'm having the trouble....it should check this and then assign $EqualError to 1 if one has something in it and the other one doesn't....but it's not.

$EqualError = 1

Return $EqualError

EndIf

Next

Return $EqualError

Else

SetError(1,3,0)

EndIf

EndFunc; _CheckNumofPaymentsAndDates----------------------------------

Any help would be appreciated!

Share this post


Link to post
Share on other sites
enaiman

You might try this piece of code:

Global $EqualError = 0

Func _PaymentAndDateError($PaymentNode, $PaymentDueDateNode);--------

    Local $NumOfPayments, $NumOfScheduledDates

    $NumOfPayments = _XMLGetValue($PaymentNode)

    $NumOfScheduledDates = _XMLGetValue($PaymentDueDateNode)

    If IsArray ($NumOfPayments) And IsArray ($NumOfScheduledDates) Then

        For $T = 1 to 14
            MsgBox(0, "Debug", "$NumOfPayments[" & $T & "] = " & $NumOfPayments[$T] & "$NumOfScheduledDates[" & $T & "] = " & $NumOfScheduledDates[$T]); debug msgbox
            MsgBox(0, "EqualError", "$EqualError = " & $EqualError); debug msgbox
            Select
                Case $NumOfPayments[$T] = "" And $NumOfScheduledDates[$T] <> ""
                    MsgBox(0, "Error Found", "Index: "&$T&" Empty payment field for "$NumOfScheduledDates[$T])
                    $EqualError = 1
                Case $NumOfPayments[$T] <> "" And $NumOfScheduledDates[$T] = ""
                    MsgBox(0, "Error Found", "Index: "&$T&" Empty date field for "$NumOfPayments[$T])
                    $EqualError = 1
                Case Else
                    MsgBox(0, "OK", "Record OK", 1)
                    $EqualError = 0
            EndSelect
        Next

    Else

        SetError(1,3,0)

    EndIf

EndFunc; _CheckNumofPaymentsAndDates----------------------------------

I've got rid of your Return statements, I've declared $EqualError as a global variable so you will have to change your code a little bit, I've replaced your "If" with a Select-Case and it might work this way.

I don't have your full code so I can't test this ... good luck.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
PsaltyDS

The following section of code reads two nodes from an XML file. Each node should be an array of up to 14 items. Some of the items may be blank. One node contains monthly payment amounts and the other node contains the dates that the payments are due on. The section of code I'm having trouble with is a function designed to check the data and verify that there is an equal number of payments and dates (i.e. if there are 10 scheduled payment dates in the payment date node, there should be a corrosponding 10 payments in the payment node). The function should compare each unit of the array in the payment node with the payment date node and makes sure that if one is blank or empty that the other one is empty and should assign an error value if one node has something and the other one doesn't. But it's not setting my error flag. Code is below

CODE
Func _PaymentAndDateError($PaymentNode, $PaymentDueDateNode);--------

Local $NumOfPayments, $NumOfScheduledDates

Local $EqualError = 0

$NumOfPayments = _XMLGetValue($PaymentNode)

$NumOfScheduledDates = _XMLGetValue($PaymentDueDateNode)

If IsArray ($NumOfPayments) And IsArray ($NumOfScheduledDates) Then

For $T = 1 to 14

MsgBox(0, "Debug", "$NumOfPayments[" & $T & "] = " & $NumOfPayments[$T] & "$NumOfScheduledDates[" & $T & "] = " & $NumOfScheduledDates[$T]); debug msgbox

MsgBox(0, "EqualError", "$EqualError = " & $EqualError); debug msgbox

If (($NumOfPayments[$T] = "") And ($NumOfScheduledDates[$T] <> "")) Then ; this is where i'm having the trouble....it should check this and then assign $EqualError to 1 if one has something in it and the other one doesn't....but it's not.

$EqualError = 1

Return $EqualError

EndIf

Next

Return $EqualError

Else

SetError(1,3,0)

EndIf

EndFunc; _CheckNumofPaymentsAndDates----------------------------------

Any help would be appreciated!
You should post a short .xml file with demo data in it, otherwise how do we know what your function is looking at?

If the node is "an array of up to 14 items" then why is the number 14 hard coded into the For/Next loop?

This code fails if there is any whitespace at all present, and only tests if both are null, NOT if only one is empty:

If (($NumOfPayments[$T] = "") And ($NumOfScheduledDates[$T] <> "")) Then

Try this instead:

$NumOfPayments = StringSplit("1,2,3,4,,6,7,8,9,0", ",")
$NumOfScheduledDates = StringSplit("1,2,3,,,6,7,,9,0", ",")

If IsArray($NumOfPayments) And IsArray($NumOfScheduledDates) Then
    If UBound($NumOfPayments) = UBound($NumOfScheduledDates) Then
        For $T = 1 To UBound($NumOfPayments) - 1
        ; Test if one is empty but not the other
            If (StringStripWS($NumOfPayments[$T], 8) = "") <> (StringStripWS($NumOfScheduledDates[$T], 8) = "") Then
                MsgBox(16, "Mismatch", "Element [" & $T & "] of the arrays are mismatched.") 
            EndIf
        Next
        
    ;...
        
    Else
        MsgBox(16, "Mismatch", "The arrays $NumOfPayments and $NumOfScheduledDates are not the same size.")
    EndIf
Else
    MsgBox(16, "Mismatch", "Either $NumOfPayments or $NumOfScheduledDates is not an array.")
EndIf

MsgBox(64, "Finished", "Done.")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×