Jump to content
Sign in to follow this  
butterfly

If $SQL[$z][1] = "a" Or "b" Or "c" Or "d" Or"e" Or "f" then

Recommended Posts

butterfly

It seems because I do not have proper education in this field i make big beginner mistakes

 

my 2d array has 40.000 items from 2 tables which needs to combined and all works flawless

 

but i want to filter out for lets say 25 pre defined names , which i prefer to type out

i am trying to do the follow but it does not work

If $SQL[$z][1] = "abb" Or "bbb" Or "cbb" Or "dbb" Or "ebb" Or "fbb"  then
        If $CSQL[$z][5] = "T" Then
                     $lineskip = True
(code)
MsgBox(0, "", $z & "True")
elseif
If $CSQL[$z][5] = "F" Then
$lineskip = False
(code)
MsgBox(0, "", $z & "False" )
endif

How to make this work? and what is best practice? a tiny bit of background would also help me a lot

I am very sorry for such a horrible starters question

Edited by butterfly

Share this post


Link to post
Share on other sites
water

Either something like this or use Switch for multiple values:

If $SQL[$z][1] = "abb" Or $SQL[$z][1] = "bbb" Or $SQL[$z][1] = "cbb" Or $SQL[$z][1] = "dbb" Or $SQL[$z][1] = "ebb" Or $SQL[$z][1] = "fbb" Then
    If $CSQL[$z][5] = "T" Then
        $lineskip = True
        ; (code)
        MsgBox(0, "", $z & "True")
    ElseIf $CSQL[$z][5] = "F" Then
        $lineskip = False
        ; (code)
        MsgBox(0, "", $z & "False")
    EndIf
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
JLogan3o13

Someone will undoubtedly be along to tell me my regex-fu sucks (which it does), but I would think you could do something like this if you are only trying to match a few patterns:

#include <Array.au3>

Local $SQL[6][2]
    $SQL[0][0] = "5"
    $SQL[0][1] = ""
    $SQL[1][0] = "Line 1"
    $SQL[1][1] = "aaa"
    $SQL[2][0] = "Line 2"
    $SQL[2][1] = "bbb"
    $SQL[3][0] = "Line 3"
    $SQL[3][1] = "fff"
    $SQL[4][0] = "Line 4"
    $SQL[4][1] = "ggg"
    $SQL[5][0] = "Line 5"
    $SQL[5][1] = "hhh"


For $i = 1 To $SQL[0][0]
    If StringRegExp($SQL[$i][1], "abb|bbb|cbb|dbb|ebb|fbb") Then
        MsgBox(0, $SQL[$i][0], "Matches pattern, do something here.")
    Else
        MsgBox(0, $SQL[$i][0], "Doesn't match pattern, do something else")
    EndIf
Next

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
bogQ

or something like this

$string = '|abb|bbb|cbb|dbb|ebb|fbb|'
If StringInStr($string, '|' & $SQL[$z][1] & '|') Then
    If $CSQL[$z][5] = "T" Then
        $lineskip = True
        ; (code)
        MsgBox(0, "", $z & "True")
    ElseIf $CSQL[$z][5] = "F" Then
        $lineskip = False
        ; (code)
        MsgBox(0, "", $z & "False")
    EndIf
EndIf

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites
water

A Switch example:

Switch $SQL[$z][1]
    Case "abb", "bbb", "cbb", "dbb", "ebb", "fbb"
        If $CSQL[$z][5] = "T" Then
            $lineskip = True
            ; (code)
            MsgBox(0, "", $z & "True")
        ElseIf $CSQL[$z][5] = "F" Then
            $lineskip = False
            ; (code)
            MsgBox(0, "", $z & "False")
        EndIf
    Case Else
        MsgBox(0, "", "Not Found")
EndSwitch

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
butterfly

Thank you very much, for the mulitple solutions, I was thinking of making an array while i was on the bike doing groceries, But i like the solution of water for now (I do not need more then 10 names)

thank you very much again

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
jchd

 

my 2d array has 40.000 items from 2 tables which needs to combined and all works flawless

but i want to filter out for lets say 25 pre defined names , which i prefer to type out

This attracts two sideways remarks which may not be valid but who knows?

First you can join tables in SQL queries even if tables come from two DBs, in which case you can attach the second one to the first (you may be using that already).

Second, rather than filtering out unwanted data from a large dataset you can specify where conditions to avoid getting them in the resultset. Again this may not be valuable in your specific use case.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
kylomas

butterfly,

An example of what jchd is alluding to.  Better to let the DB engine do the work for you...

#include <sqlite.au3>

;---------------------------------------------------------------------------------------
; initialize SQLite, open DB and declare some common variables
;---------------------------------------------------------------------------------------

_SQLite_Startup()

If @error Then
    ConsoleWrite('error loading sqlite.dll' & @LF)
    Exit
EndIf

Local $hDB = _SQLite_Open(':memory:')

If @error Then
    ConsoleWrite('Unable to open DB' & @LF)
    _exit()
EndIf

OnAutoItExitRegister("_exit")

Local $ret, $rows, $nbrows, $nbcols, $sqlstr

;---------------------------------------------------------------------------------------
; create two tables and load some data
;---------------------------------------------------------------------------------------

$ret = _SQLite_Exec($hDB, 'create table if not exists T1 (Col1, Col2, Col3, Col4); create table if not exists T2 (Col1,Col2);')
If $ret <> $SQLITE_OK Then
    MsgBox(0, 'ERROR', 'Create table error')
    _exit()
EndIf

$sqlstr = _
        'insert into T1 values("abb","","","");' & _
        'insert into T1 values("bbb","","","");' & _
        'insert into T1 values("cbb","","","");' & _
        'insert into T1 values("dbb","","","");' & _
        'insert into T1 values("ebb","","","");' & _
        'insert into T1 values("fbb","","","");' & _
        'insert into T2 values("abb","T");' & _
        'insert into T2 values("bbb","T");' & _
        'insert into T2 values("cbb","F");' & _
        'insert into T2 values("dbb","T");' & _
        'insert into T2 values("ebb","T");' & _
        'insert into T2 values("fbb","F");'

$ret = _SQLite_Exec($hDB, $sqlstr)

If $ret <> $SQLITE_OK Then
    MsgBox(0, 'ERROR', 'Insert table error')
    _exit()
EndIf

;  the "where...in" clause uses the DB engine to filter the data.

$sqlstr = ' select T1.Col1, T2.Col2 from T1, T2 ' & _
        '      where T1.Col1 = T2.Col1 and T1.Col1 in ("cbb","dbb");'

$ret = _SQLite_GetTable2d($hDB, $sqlstr, $rows, $nbrows, $nbcols)

If @error Then
    ConsoleWrite("!>  Error getting Data" & @LF)
    _exit()
EndIf

_ArrayDisplay($rows)

Func _exit()
    _SQLite_Close()
    _SQLite_Shutdown()
    Exit
EndFunc   ;==>_exit

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×