Jump to content
Sign in to follow this  
MrBeatnik

[Solved] Comparison (date/time string) not working

Recommended Posts

MrBeatnik

Hi folks.

I wont post the whole code (I know, I know - that doesn't help my cause), but only because it reads from internal sharepoint libraries etc and is quite big now. I have a sloppy function that has some problems, as shown below.

Basically, I had read a file into a 2D array (looks like this:)

c.jpg,Active,1,19/03/2012,15:12
e.jpg,Active,2,16/03/2012,09:51
f.jpg,Active,3,16/03/2012,09:51
a.jpg,Active,4,16/03/2012,09:55

I also read some data from a webpage, into a 2D array which looks identical.

In fact, they are identical, except I have changed some of the times on the local file.

When I show in a message box:

$imageDetArray[$i][4] = 09:55

$imageDetArray[$iIndexi][4] = 09:51

I need to compare them and flag the difference, but when I compare them, using whatever method, it always comes back as matching. I can't figure out why - I guess I have something wrong somewhere, but I can't see the wood for the trees. I guess I would understand more if it always came back as NOT matching....

Any help?

$file = FileOpen($checkFile, 0)        ;Open downloaded File
If $file = -1 Then                                ;If File didn't open correctly
  ;Could not open file.
  Return 0
  ;Exit
EndIf
$fileData = FileRead($file)                ;Read file into var
FileClose($file)                                     ;Close file

$allLines = StringSplit($fileData,@CR)
;_ArrayDisplay($allLines)

dim $imageDetArray[Ubound($allLines)][5]            ;Create 3D Array with correct size
For $i=1 to $allLines[0]-1                                     ;From array 1 (0 is count) to max
  $curImageDet = StringSplit($allLines[$i],",",2)     ;Split the string by ","
  ;_ArrayDisplay($curImageDet)
  $imageDetArray[$i-1][0] = $curImageDet[0]     ;Populate the new 3D array with the correct info
  $imageDetArray[$i-1][1] = $curImageDet[1]
  $imageDetArray[$i-1][2] = $curImageDet[2]
  $imageDetArray[$i-1][3] = $curImageDet[3]     ;Date (dd/mm/yyyy)
  $imageDetArray[$i-1][4] = $curImageDet[4]     ;Time (hh:mm)
Next

;Now compare WEB data to LOCAL data.
;If not on list, download.
;If on list, but different dates, download.
Dim $dlImgArray = ""

For $i=0 to UBound($webImages)-1

$imageMatch=0
  $iIndexi = _ArraySearch($imageDetArray, $webImages[$i][0], 0, 0, 0, 1, 1, 0)
  
  If @error Then
     MsgBox(0, "Not Found", '"' & $webImages[$i][0] & '" was not found on column ' & 0 & '.')
  Else

     If $webImages[$i][3] == $imageDetArray[$iIndexi][3]Then
        msgbox(0,"Same:" & $webImages[$i][0],$webImages[$i][3] & " -- " & $imageDetArray[$iIndexi][3])
     EndIf

     if StringCompare($imageDetArray[$i][4],$imageDetArray[$iIndexi][4],0)=0 Then
        msgbox(0,"Same:" & $webImages[$i][0],$webImages[$i][4] & " -- " & $imageDetArray[$iIndexi][4])
     EndIf

  Endif

Next

EXIT

I have tried the followig line from above in many methods:

if StringCompare($imageDetArray[$i][4],$imageDetArray[$iIndexi][4],0)=0 Then

such as:

if $imageDetArray[$i][4] == $imageDetArray[$iIndexi][4] Then

if $imageDetArray[$i][4] = $imageDetArray[$iIndexi][4] Then

but it always shows the message box saying they are the same, even though the contents of the message box clearly show they are different! How can I compare 09:51 and 09:55 to show they are different?

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites
BrewManNH

I'm guessing because you're searching the array on the first (0) element of the array, and the time is in the fifth (4) element of the array.

BTW, you're not using 3D arrays, you're using 2D arrays, just for clarification.


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
water

Can you post a screenshot of one of the "Same" MsgBoxes?


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
MrBeatnik

I'm guessing because you're searching the array on the first (0) element of the array, and the time is in the fifth (4) element of the array.

Yes, I'm searching for the first (0) element, and if found, I'm checking the 4th (3) and 5th (4) element which hold the date and time respectively.

This works fine - it checks that we are dealing with the same filename (held in first (0) element).

BTW, you're not using 3D arrays, you're using 2D arrays, just for clarification.

Yes, good point! I'll edit the post.

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites
Melba23

MrBeatnik,

If I use these files:

1.txt

c.jpg,Active,1,19/03/2012,15:12
e.jpg,Active,2,16/03/2012,09:51
f.jpg,Active,3,16/03/2012,09:51
a.jpg,Active,4,16/03/2012,09:55

2.txt

c.jpg,Active,1,19/03/2012,15:11
e.jpg,Active,2,16/03/2012,09:52
f.jpg,Active,3,16/03/2012,09:50
a.jpg,Active,4,16/03/2012,09:56

Then this code works perfectly:

#include <File.au3>
#include <Array.au3>

Global $aArray_1, $aArray_2

$sFile_1 = "1.txt"
$sFile_2 = "2.txt"

_FileReadToArray($sFile_1, $aArray_1)
_FileReadToArray($sFile_2, $aArray_2)

;_ArrayDisplay($aArray_1)
;_ArrayDisplay($aArray_2)

Global $aArray_2D_1[$aArray_1[0] + 1][5], $aArray_2D_2[$aArray_2[0] + 1][5]

For $i = 1 To $aArray_1[0]
    $aSplit_1 = StringSplit($aArray_1[$i], ",", 2)
    $aSplit_2 = StringSplit($aArray_2[$i], ",", 2)
    For $j = 0 To 4
        $aArray_2D_1[$i][$j] = $aSplit_1[$j]
        $aArray_2D_2[$i][$j] = $aSplit_2[$j]
    Next
Next

;_ArrayDisplay($aArray_2D_1)
;_ArrayDisplay($aArray_2D_2)

For $i = 1 To UBound($aArray_2D_1) - 1
    If $aArray_2D_1[$i][4] < $aArray_2D_2[$i][4] Then
        ConsoleWrite($aArray_2D_1[$i][4] & " is less than " & $aArray_2D_2[$i][4] & @CRLF)
    Else
        ConsoleWrite($aArray_2D_1[$i][4] & " is greater than " & $aArray_2D_2[$i][4] & @CRLF)
    EndIf
Next

I hope that it might offer some help in getting your arrays correctly filled. :oops:

But without sight of the arrays that you are actually searching it is difficult to offer much more advice that to use _ArrayDisplay to make sure that you are actually comparing what you think you are comparing in those elements. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
MrBeatnik

Can you post a screenshot of one of the "Same" MsgBoxes?

Can I remember who to upload to my content area? No.

Anyway, here's the screeny.

Posted Image

which corresponds to:

if StringCompare($imageDetArray[$i][4],$imageDetArray[$iIndexi][4],0)=0 Then
    msgbox(0,"Same:" & $webImages[$i][0],$webImages[$i][4] & " -- " & $imageDetArray[$iIndexi][4])
   EndIf

Melba, I don't think I have an issue with filling the arrays (although I could probably be more efficient in doing so).

The data from the web page is not in the same format initially, but needs massaged and instead of putting that into a file, I stick it right into an array for comparison.

Using _arraydisplay at appropriate steps, I can see that the arrays are populated with the correct data (at least visually).

As you can see from the screenshot above, the arrays are outputting what they should - it's just that the comparison is incorrect...


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites
water

What version of AutoIt do you run?


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
MrBeatnik

Which one of you wants to slap me first?

I've already had a facepalm moment.

if StringCompare($imageDetArray[$i][4],$imageDetArray[$iIndexi][4],0)=0 Then
    msgbox(0,"Same:" & $webImages[$i][0],$webImages[$i][4] & " -- " & $imageDetArray[$iIndexi][4])
   EndIf

I'm comparing an element with the SAME element, but then displaying an element from two different arrays in the messagebox.

$imageDetArray[$i][4]
$imageDetArray[$iIndexi][4]

are the same.

I should have been comparing:

$webImages[$i][4]
$imageDetArray[$iIndexi][4]

which contain the differences.

Sometimes you just need to verbalise (or textualise in this case?) the problem to see the error.

I knew there was something I did wrong of course.

Thanks for guiding me towards the light.


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites
water

Could you please replace

if StringCompare($imageDetArray[$i][4],$imageDetArray[$iIndexi][4],0)=0 Then
    msgbox(0,"Same:" & $webImages[$i][0],$webImages[$i][4] & " -- " & $imageDetArray[$iIndexi][4])
EndIf
with
if StringCompare($imageDetArray[$i][4],$imageDetArray[$iIndexi][4],0)=0 Then
    msgbox(0,"Same: " & $webImages[$i][0],">" & $webImages[$i][4] & "< -- >" & $imageDetArray[$iIndexi][4] & "<")
EndIf
so we can see how long the strings are?


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
water
:oops:

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

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  

×