Jump to content

Compare problem


Recommended Posts

i dont know what's wrong with this script

look:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <INet.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("program 1.0", 182, 46, 192, 124)
$Button1 = GUICtrlCreateButton("Update", 8, 8, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 88, 8, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $ThisVersionFile = @TempDir & "\alrdyVersion.txt"
Global $NewVersionFile = @TempDir & "\newversion.txt"
Global $GetSource, $CheckUpdate
FileWrite($ThisVersionFile, "103")
Func del()
FileDelete(@TempDir & "\alrdyVersion.txt")
FileDelete(@TempDir & "\newversion.txt")
EndFunc   ;==>del
Func Close()
FileClose($ThisVersionFile)
FileClose($NewVersionFile)
EndFunc   ;==>Close
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   del()
   Exit
  Case $Button2
   del()
   Exit
  Case $Button1
   $GetSource = _INetGetSource("https://sites.google.com/site/chk4updatetestau")
   FileWrite($NewVersionFile, $GetSource)
   FileOpen($ThisVersionFile, 0)
   FileOpen($NewVersionFile, 0)
   $AlrdyVersion = FileRead($ThisVersionFile)
   $NewVersion = FileRead($NewVersionFile)
   $NewTxt = _StringBetween($NewVersion, "Update", ":")
   $ThisTxt = _StringBetween($AlrdyVersion, "Update", ":")
   $compare = StringCompare($NewTxt, $ThisTxt)
   If $compare <> 0 Then
    MsgBox(0, "New update available", "There is new version for this program.")
    Close()
   ElseIf $compare = 0 Then
    MsgBox(0, "update doesn't available", "There isn't new version for this program.")
    Close()
   EndIf
 
EndSwitch
WEnd

i want to compare with the new version and already version, but it alaways says: new update is available if already version

less than new version or greater than it or equal .

any ideas please?

thanks. :graduated:

[font="arial, helvetica, sans-serif;"]Advice for you[/font][font="arial, helvetica, sans-serif;"]: [/font][u]Search[/u] before posting.

 

[font="arial, helvetica, sans-serif;"] *********** Problem solved? if yes [/font][color=rgb(0,0,0);font-family:arial, helvetica, sans-serif;] *********[/color]

[font="arial, helvetica, sans-serif;"]******* press "Mark Solved" button. *******[/font]

Link to comment
Share on other sites

The main problems with this script are that _StringBetween returns an array and you're comparing them like they're strings. Also, that website's source code has the word "Update" in it in 36 times, so your stringbetween array is going to have a lot of hits in it with that comparison.

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

Link to comment
Share on other sites

umm, okay how can i return it to array, i dont know more about arrays and the "Update" word came just 1time in my page, String between "Update" And ":".... so the problem just returns an array?

may u explain how to returns an array please? :graduated:

thanks. ;)

[font="arial, helvetica, sans-serif;"]Advice for you[/font][font="arial, helvetica, sans-serif;"]: [/font][u]Search[/u] before posting.

 

[font="arial, helvetica, sans-serif;"] *********** Problem solved? if yes [/font][color=rgb(0,0,0);font-family:arial, helvetica, sans-serif;] *********[/color]

[font="arial, helvetica, sans-serif;"]******* press "Mark Solved" button. *******[/font]

Link to comment
Share on other sites

You need to look at what is inside the variable $GetSource after you run this line:

$GetSource = _INetGetSource("https://sites.google.com/site/chk4updatetestau")

Because the text file you write from that variable, @TempDir & "\newversion.txt", contains the whole source code from that page. In that text file you'll see that the word Update is in there (by my count) 36 times. Sometimes it's in there as Updates, sometimes it's in there as "chk4updatetestau", _StringBetween is going to see every occurance of the word, whether it's by itself or part of another word, as a hit.

As to how to work with Arrays, I would suggest this Wiki Article on arrays as a start.

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

Link to comment
Share on other sites

Thanks bro for help :graduated:

so to resolve this problem i should change "Update" word to any another word??

and returns an array... i'll try and tell u ;)

thanks again.

[font="arial, helvetica, sans-serif;"]Advice for you[/font][font="arial, helvetica, sans-serif;"]: [/font][u]Search[/u] before posting.

 

[font="arial, helvetica, sans-serif;"] *********** Problem solved? if yes [/font][color=rgb(0,0,0);font-family:arial, helvetica, sans-serif;] *********[/color]

[font="arial, helvetica, sans-serif;"]******* press "Mark Solved" button. *******[/font]

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