Jump to content
Sign in to follow this  
Bearpocalypse

StringInStr quick help

Recommended Posts

Bearpocalypse

I'm trying to make life a little easier when scanning barcodes for some batteries for a recall. I have 10 entries I want to search. When using StringInStr, I can search for one and everything is fine and dandy. Can I assign one variable, say $BadItem to contain the 10 entries and have one StringInStr search? Let me know if I'm being stupid or if there is an easier way to do this. As always, thanks so for your help!

Example

$Serial = GUICtrlRead($B_Serial) ;Reads the input box

$BadItem = 1
$BadItem = 2
$BadItem = 3
$BadItem = 4
$BadItem = 5
$BadItem = 6
$BadItem = 7
$BadItem = 8
$BadItem = 9
$BadItem = 10

$SerialFind = StringInStr($Serial, $BadItem)

If $SerialFind Then
    MsgBox(0, '', 'Found a bad one.')
Else
    MsgBox(0, '', 'This one is good.')
EndIf

Share this post


Link to post
Share on other sites
mikell

Or you can use StringRegExp with flag 0

The internal syntax will depend on the kind of the baditems to need to detect

$Serial = "2a3b4c5e6d8i"

$BadItem = "1a"
$BadItem = "2b"
$BadItem = "3c"
$BadItem = "4d"
$BadItem = "5e"
$BadItem = "6f"

$SerialFind = StringRegExp($Serial, '(1a|2b|3c|4d|5e|6f)', 0)

If $SerialFind Then
    MsgBox(0, '', 'Found a bad one.')
Else
    MsgBox(0, '', 'This one is good.')
EndIf

Share this post


Link to post
Share on other sites
Bearpocalypse

Thanks for the assistance. I actually got it working with a long 'StringInStr($, $) OR' statement. It works and we only need it for a short time.

Share this post


Link to post
Share on other sites
AutID

If it is an InputBox() then you don't need GuiCtrlRead() to read it.

As said at post you, loop an array and check all values.

Local $B_Serial = InputBox("Hello", "Dump")
Local $BadItem[10] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
For $i = 0 To UBound($BadItem) -1
 If StringInStr($B_Serial, $BadItem[$i]) Then
  ConsoleWrite('Found a bad one.' & @LF)
 Else
  ConsoleWrite('This one is good.' & @LF)
 EndIf
Next

If it is an input(GUICtrlCreateInput()) then you will need GUICtrlRead() to read it's value.

Anyway here you got the example with the array and the loop. It is much better than the long stringinstr thing you got it working ;)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.