Jump to content
Sign in to follow this  
CraigFu

OR Operator Not Working

Recommended Posts

CraigFu

I have an excel spreadsheet that could have many different columns with different names. Within the spreadsheet there are two columns with the header "LISTQTY" and another one with "ITEM-AT-QT". I want to cycle through the headers and delete the columns that don't have the headers that I specified.

The OR operator doesn't seem to be working. If I just leave the "LISTQTY" portion, the code works fine. Here is the code:

#include <Excel.au3>
#include <Array.au3>

$bomInfo = _ExcelReadSheetToArray($oExcel)


$LabelTemplate = _ExcelBookNew()
_ExcelWriteSheetFromArray($LabelTemplate, $bomInfo)

For $i = 1 to $bomInfo[0][1]
If $bomInfo[1][$i] <> "LISTQTY" OR $bomInfo[1][$i] <> "ITEM-AT-QT" Then
  _ExcelColumnDelete($LabelTemplate, $i)
EndIf
Next

Any ideas of why the OR wouldn't work in this case?

Share this post


Link to post
Share on other sites
jdelaney

You created a condition that can never happen, since the header will never have both specified names at the same time ( unless they are the same) change it to an AND


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
CraigFu

You're right, oops, faulty logic. Thanks!

Share this post


Link to post
Share on other sites
BrewManNH

Not to mention, if it's one OR the other, it's going to get deleted because the other condition is TRUE.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
CraigFu

Here's my new code snippet, this works:

$bomInfo = _ExcelReadSheetToArray($oExcel)

$LabelTemplate = _ExcelBookNew()
_ExcelWriteSheetFromArray($LabelTemplate, $bomInfo)

$templateInfo = _ExcelReadSheetToArray($LabelTemplate)

For $i = 1 to $templateInfo[0][1]
$templateInfo = _ExcelReadSheetToArray($LabelTemplate)
If $templateInfo[1][$i] <> "LISTQTY" AND $templateInfo[1][$i] <> "ITEM-AT-QT" AND $templateInfo[1][$i] <> "ITEMPARTNU" AND $templateInfo[1][$i] <> "FLIR/MFGNO" AND $templateInfo[1][$i] <> "ITEMTITLE" AND $templateInfo[1][$i] <> "MFRNAME" AND $templateInfo[1][$i] <> "LISTQTY" AND $templateInfo[1][$i] <> "LISTITEMNU" AND $templateInfo[1][$i] <> "TYPE" Then
_ExcelColumnDelete($LabelTemplate, $i)
EndIf
Next

Share this post


Link to post
Share on other sites
jdelaney

At this point, it's cleaner to create an array (you have lots of conditions), loop throught the array, and verify not present, and then delete...or even do an _arraysearch (forget the exact name, something like that.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
ChrisL

You can write that a bit easier...

$bomInfo = _ExcelReadSheetToArray($oExcel)

$LabelTemplate = _ExcelBookNew()
_ExcelWriteSheetFromArray($LabelTemplate, $bomInfo)

$templateInfo = _ExcelReadSheetToArray($LabelTemplate)

For $i = 1 to $templateInfo[0][1]
  $templateInfo = _ExcelReadSheetToArray($LabelTemplate)
  Switch $templateInfo[1]
    Case "LISTQTY","ITEM-AT-QT","ITEMPARTNU","FLIR/MFGNO","ITEMTITLE", "MFRNAME","LISTQTY", "LISTITEMNU", "TYPE"
      ;Do Nothing
    Case Else
      _ExcelColumnDelete($LabelTemplate, $i)
  EndSwitch
Next

Although I'm a little concerned at you reusing the variable $templateInfo while inside your FOR loop?

Share this post


Link to post
Share on other sites
CraigFu

Although I'm a little concerned at you reusing the variable $templateInfo while inside your FOR loop?

I had to re-read the excel sheet because the column number will change when columns are deleted. There's probably a better way, there's always a better way as you pointed out.

Share this post


Link to post
Share on other sites
BrewManNH

You should loop through your array backwards For $i =$templateInfo[0][1] to 1 Step -1, that way you're deleting from the higher numbered columns and working your way down to the lower columns and the column numbers won't change that way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
autoovi

#requireadmin
#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
$i = 0
While $i <= 10
$pt1 = PixelSearch(1859, 401, 1859, 401, 0xFF9900, 10)
     $pt12 = PixelSearch(1859, 436, 1859, 436, 0xFF9900, 10)
If _IsPressed("57", $hDLL) or _IsPressed("53", $hDLL) or _IsPressed("02", $hDLL) Then
Sleep(100)
     ControlSend("windowname", "", "", "{keyboard}")
     Sleep(100)
     ControlSend("", "", "", "{-}")
     Sleep(100)
elseIf _IsPressed("04", $hDLL) Then
     Sleep(100)
     ControlSend("", "", "", "{-}")
     Sleep(100)
     While _IsPressed("04", $hDLL)
     sleep(100)
     if isarray ($pt1) = true Then
     Sleep(100)
     ControlSend("", "", "", "{-}")
     Sleep(100)
Elseif isarray ($pt1) = False and isarray ($pt12) = false Then
Sleep(100)
ControlSend("", "", "", "{-}")
     Sleep(100)
_ifl()
sleep(1000)
EndIf
ExitLoop
WEnd
sleep(10)
     EndIf
Sleep(15)
WEnd
Sleep(15)
DllClose($hDLL)
Func _ifl()
Sleep(10)
     ControlSend("", "", "", "{enter}")
     sleep(45)
     ControlSend("", "", "", "{up}")
sleep(55)
ControlSend("", "", "", "{enter}")
sleep(200)
EndFunc
this or works for me

here is another

#requireadmin
$i = 0
While $i <= 10
$ytrr = PixelSearch(127, 753, 127, 753, 0xF8CA53, 5)
$ybll = PixelSearch(52, 752, 52, 752, 0xFBDE6F, 5)
$pt3 = PixelSearch(95, 73, 95, 73, 0x232F39, 5)
Select
case isarray ($ybll) = true or isarray ($ytrr) = true
  MouseClickDrag("left", 51, 751, 59, 624, 5)
   sleep(1000)
EndSelect
  wend
Edited by autoovi

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  

×