Jump to content

Exit Select when first true expression found


Go to solution Solved by JohnOne,

Recommended Posts

I'm trying to adapt a program to handle a third Case, but the criteria is not being met. I think I know what is happening, that the For is continuing to be processed even after the expression is true, to a point where it is no longer true. For security reasons, I can't post complete code, but hopefully I can get a general idea across.

 

Data is read from XML and an INI. The idea is that the data must match. While the INI has a single static value to read, the XML does not and may have multiples. Where this is failing is where multiples are concerned.

 

  For $i = 1 to $itemcode[0] Step 1
      $quantity1 = $quantity[$i]
      $itemcode1 = $itemcode[$i]
      $itemcodedesc1 = $itemcodedesc[$i]
      Select
        Case $itemcode1 = $ossku
            $match = $itemcode1
        Case StringLeft($itemcode1, 7) = "Prefix1" AND StringRight($itemcodedesc1, 8) = "Text"
            $match = $itemcode1
        Case StringLeft($itemcode1, 7) = "Prefix1"
            $match = $itemcode1
        Case StringLeft($itemcode1, 7) = "Prefix2"
            $match = $itemcode1
      EndSelect
$ossku comes from the INI file, the 3 array items are from the XML. The usage of the solitary Prefix1 and Prefix2 cases are merely to be able to store what that value is, as the XML has no other way to determine what type of data it is. There are two possible outcomes that the system will allow.

1. Match on one type: the 1st expression is true, The 2nd is false, and either the 3rd or 4th is true. The software is allowed to proceed, there is a match.

3. Does not match: In this case, 1st is false, 2nd is false, 3rd or 4th is true. A MsgBox then appears to show which value is in the INI file and which is in the XML (stored by way of 3rd or 4th case.)

2. Match on second type: In this case, the 1st expression is true, the 2nd expression is true, the 3rd expression is true, the 4th is false. The software shows the MsgBox in Case 3 (which is why I posted this out of order) showing the INI value and the wrong data from the XML.

The reason for the wrong data is that in the Second Type condition, the XML has two fields with Prefix1. Two different values exist, one of them DOES actually match the INI, while the other does not.

It was my understanding that if multiple Case expressions are true, then the first one is executed. In the above code, I even added a second case, the part which compares the String Right, to get the second match, but it still fails. The physical XML has the correct value first, the incorrect second. What I am seeing here is that it is parsing the XML properly, but is not stopping once the first match is found.

What am I missing here?

Edited by Tripredacus
Link to comment
Share on other sites

Hey Trip, hope MSFN is lots of fun, I have greatly neglected my account there.

Can you explain the issue with these dummy values, and maybe not the issue but why are you stringright-ing 8 characters and only evaluating 4 "Text"

Dim $quantity[4] = ["00" , "11" , "22" , "33"]
Dim $itemcode[4] = ["ossku" , "Prefix1" ,  "Prefix1" , "Prefix2"]

Dim $itemcodedesc[4] = ["Text" , "Text" ,  "None" , "Text"]

$ossku = "ossku"

For $i = 0 to ubound($itemcode) - 1
      $quantity1 = $quantity[$i]
      $itemcode1 = $itemcode[$i]
      $itemcodedesc1 = $itemcodedesc[$i]
      Select
        Case $itemcode1 = $ossku
            $match = "ossku - Case number 1"
        Case StringLeft($itemcode1, 7) = "Prefix1" AND StringRight($itemcodedesc1, 4) = "Text"
            $match = "prefix1 & text - Case number 2"
        Case StringLeft($itemcode1, 7) = "Prefix1"
            $match = "prefix1 only - Case number 3"
        Case StringLeft($itemcode1, 7) = "Prefix2"
            $match = "prefix 2 - Case number 4"
      EndSelect
msgbox(0, '' , $match)
next
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

What am I missing here?

 

If the condition is meant, do you want to leave the loop? If so then use the keyword ExitLoop?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Can you explain the issue with these dummy values, and maybe not the issue but why are you stringright-ing 8 characters and only evaluating 4 "Text"

Yes! The dummy who dummy the values cannot count! :P

Now the working set does the following:

- can find a match where 1 data exists

- can find a match where multiple data exists

- can find mismatch and display to the user the actual and expected data.

For $i = 1 to $itemcode[0] Step 1
$quantity1 = $quantity[$i]
$itemcode1 = $itemcode[$i]
If $itemcode1 = $ossku Then
$match = $itemcode1
ExitLoop
Else
Select
Case StringLeft($itemcode1, 7) = "Prefix1"
$match = $itemcode1
Case StringLeft($itemcode1, 7) = "Prefix2"
$match = $itemcode1
EndSelect
EndIf

I knew this would be a case of just moving things around.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...