Jump to content

compare numbers -need help-


Go to solution Solved by FireFox,

Recommended Posts

hi all

this is a part from program update code

it must check a file size from a download link and compare it to test.exe that contain the size of another file in bytes

Local $nSize = InetGetSize("http://www.autoitscript.com/autoit3/files/beta/update.dat")

If FileExists("test.txt") Then


Local $file = FileOpen("test.txt", 0)

While 1
    Local $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
WEnd

FileClose($file)
Endif




If $nSize == $line Then
  MsgBox(4096,"","Matched!")
Else
  MsgBox(4096,"", "The strings did not match!")
EndIf

i am new to autoit and this code always give "The strings did not match" even if they're the same "445"

any ideas ?

Link to comment
Share on other sites

$nSize <> Int($line)

Try:

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Yeh, but they got the idea. I use Int as InetGetSize returns Int32, personal preference really.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

$nSize <> Int($line)

Try:

 

@guinnes

Upside down !

 

@alexander95

Try :

;better to compare same vars type :
If $nSize <> Number($line) Then
Br, FireFox.

 

 

thank you for fast replay guys but the both codes if it is the same value or not it give "The strings did not match!"

anyway what do you mean by <> i want it to be equal not larger or smaller ?

any ideas ? 

Link to comment
Share on other sites

No, I understood my Try: was below but the Forum messed up the insertion of the AutoIt tags, so I just left it. Feeling a little lazy today.

<>  - is non case-sensitive

= - is non case-sensitive

== is - is case-sensitive

Why not use FileGetSize on the application instead of reading lines from a file?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

No, I understood my Try: was below but the Forum messed up the insertion of the AutoIt tags, so I just left it. Feeling a little lazy today.

:) I wouldn't have posted if I saw your "Int", I replied too quickly.
Link to comment
Share on other sites

No, the operator <> means different from, for more infos see here.

That's weird, can you check if the vars are really the same and post it here if needed?

ConsoleWrite("$line:" & $line & ", $nSize:" & $nSize & "." & @CrLf)

Br, FireFox.

 

this is what i got

$line:, $nSize:445.

 

No, I understood my Try: was below but the Forum messed up the insertion of the AutoIt tags, so I just left it. Feeling a little lazy today.

Why not use FileGetSize on the application instead of reading lines from a file?

 

the rest of the code will download and execute if different from the old size ()

Link to comment
Share on other sites

  • Solution

Try this:

#include <Constants.au3>

Local $iSize = InetGetSize("http://www.autoitscript.com/autoit3/files/beta/update.dat")

Local $iMySize = FileRead("test.txt")
If @error Then Exit 1 ;either the file does not exists or it's used by another app.

If $iSize = $iMySize Then
    MsgBox($MB_SYSTEMMODAL, Default, "Matched!")
Else
    MsgBox($MB_SYSTEMMODAL, Default, "The strings did not match!")
EndIf
Br, FireFox. Edited by FireFox
Link to comment
Share on other sites

Try this:

#include <Constants.au3>

Local $iSize = InetGetSize("http://www.autoitscript.com/autoit3/files/beta/update.dat")

Local $iMySize = FileRead("test.txt")
If @error Then Exit 1 ;either the file does not exists or it's used by another app.

If $iSize = $iMySize Then
    MsgBox($MB_SYSTEMMODAL, Default, "Matched!")
Else
    MsgBox($MB_SYSTEMMODAL, Default, "The strings did not match!")
EndIf
Br, FireFox.

 

 

 

 

thank you man you are the best it worked !

can u explain what is the difference between isize and nsize ?

Link to comment
Share on other sites

can u explain what is the difference between isize and nsize ?

None, it's a variable name and it has no effect on its content.

I use i for the integers, see the Hungarian notation.

Br, FireFox.

Link to comment
Share on other sites

$iSize is a string, but on comparison with a number AutoIt internally converts it to a number.

#include <Constants.au3>

If 10 = '10' Then MsgBox($MB_SYSTEMMODAL, '', 'It''s 10!')

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

thank u all guys for helping

the update prosses must do the following:

1- check file size of the link provided

2-if test.exe does not exist then download and excute

   if test.exe exists then compare the size (from the link) compare to the number in try.txt if matched then do nothing

                                                                                                                                            if not matched then download and execute

Local $iSize = InetGetSize("https://dl.dropboxusercontent.com/u/102520949/My%20Files/GPU%20Z%200-3.exe")

Local $iMySize = FileRead("test.txt")
If @error Then 
   
   Local $hDownload = InetGet("https://dl.dropboxusercontent.com/u/102520949/My%20Files/GPU%20Z%200-3.exe", @TempDir & "\try.exe", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload) ; Close the handle to release resources.
ShellExecute(@tempdir & "\try.exe")
EndIf
   
   
If $iSize = $iMySize Then
    MsgBox(4096,"","Matched!")
Else
    MsgBox(4096,"", "The strings did not match!")
    Local $hDownload = InetGet("https://dl.dropboxusercontent.com/u/102520949/My%20Files/GPU%20Z%200-3.exe", @TempDir & "\try.exe", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload) ; Close the handle to release resources.
ShellExecute(@tempdir & "\try.exe")

EndIf

but it is behaving in different way

if it found test.txt it is working fine and comparing fine

if it didn't found try.txt it download and ecute 2 times

i want it only once

any ideas ?

Edited by alexander95

Link to comment
Share on other sites

Local $iSize = InetGetSize("https://dl.dropboxusercontent.com/u/102520949/My%20Files/GPU%20Z%200-3.exe")

Local $iMySize = Number(FileRead("test.txt"))
If @error _ ;if the file does not exists
        Or $iSize <> $iMySize Then ;OR if it exists and the size does not match
    Local $hDownload = InetGet("https://dl.dropboxusercontent.com/u/102520949/My%20Files/GPU%20Z%200-3.exe", @TempDir & "\try.exe", 1, 1)
    Do
        Sleep(250)
    Until InetGetInfo($hDownload, 2) ; Check if the download is complete.

    Local $nBytes = InetGetInfo($hDownload, 0)
    InetClose($hDownload) ; Close the handle to release resources.
    ShellExecute(@TempDir & "\try.exe")
EndIf
Edit: Added indents... (don't know what's happening with the forum).

Edited by FireFox
Link to comment
Share on other sites

  • 1 year later...

thank u all guys for helping

the update prosses must do the following:

If $iSize = $iMySize Then

MsgBox(4096,"","Matched!")

Else

MsgBox(4096,"", "The strings did not match!")

Whew, and it only took days to find out how to get strings to compare,, Yes read the darn help file many times.. and tons of posts on google and else were. just could not get a handle on

Local $iCmp = StringCompare($sStr1, $sStr2) MsgBox($MB_SYSTEMMODAL, "", _         "Comparing '" & $sStr1 & "' To '" & $sStr2 & "'" & @CRLF & _         "StringCompare Result (mode $STR_NOCASESENSE): " & $iCmp)

It makes no sense (((("StringCompare Result (mode $STR_NOCASESENSE):)))) compare the case of letters when you have tools built in to change the case of letters?

I know just trying to confuse me, and you did, congrats..

Thank you

Thank you

FireFox

Thank you

guinness   gosh if my husband knew how much time we spent together,, I would be dead..

I read a lot of your and Melba23's posts to learn.

And a touch to 

Melba23  .. for the lessons you gave me that got me started.

 

Oh yea.. I almost forgot and I did promise.. Note to the " why are you posting to OLD posts people " because I promised that I would if I found any GEMS that had that make or break code for a program that we all from time to time wish we could find.

Here is a quote I got back from Microsoft about Windows XP that was first released on 25 October 2001. I had sent a letter to them, politely asking why they could never get it right, XP was full of bugs and they have been at this for over 10 years now!

 

Dear. Mrs ********. As you know coding is very time intensive. Microsoft who is the leader, has a commitment to our board of directors. Principally Mr. Gates to move forward at a accelerated pace to keep the competition at bay. We use as much old tested code as we can and sometimes it needs tweaking to work with new commands. Old code is usually the basis all software is built upon................................ and so on.

I was lucky as living in Oregon I could attend many events at Microsoft. And they could take your breath away......

Thanks guys..

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...