Compare text with AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Compare text with AHK

13 Nov 2015, 09:40

I get data some looks like

Code: Select all

Josefen Huge
In a program data looks like

Code: Select all

JOSEFEN, HUGE
I need to check if data er equal. In this case code must show that data are equal. How to do that?

Code: Select all

!y::
xl := ComObjActive("Excel.Application")
	number1:= xl.Range("B4").Text  ; Josefen Huge
	number2:= xl.Range("C4").Text  ; JOSEFEN, HUGE
If (number1 = number2)
	MsgBox TRUE
else
	MsgBox FALSE
return
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Compare text with AHK

13 Nov 2015, 09:57

can't you just remove the comma before the comparison, if that's all there is to it! or add comma before the first space
something like this:

Code: Select all

!y::
xl := ComObjActive("Excel.Application")
	number1:= xl.Range("B4").Text  ; Josefen Huge
	number2:= xl.Range("C4").Text  ; JOSEFEN, HUGE

StringReplace, number1, number1, `,,, all ; no comma
StringReplace, number2, number2, `,,, all ; no comma

If (number1 = number2)
	MsgBox TRUE
else
	MsgBox FALSE
return
 
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Compare text with AHK

13 Nov 2015, 10:24

data with comma findes in a program. I cant change data there. And data I get is without comma. There is many clients and it will be best if I can compare data with comma...
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Compare text with AHK

13 Nov 2015, 10:35

still the same:

Code: Select all

!y::
xl := ComObjActive("Excel.Application")
	number1:= xl.Range("B4").Text  ; Josefen Huge
	number2:= xl.Range("C4").Text  ; JOSEFEN, HUGE
 
StringReplace, dummynumber1, number1, `,,, all ; no comma, with number1 variable is still intact, the data is still intact also
StringReplace, dummynumber2, number2, `,,, all ; no comma, with number2 variable is still intact, the data is still intact also
 
If (dummynumber1 = dummynumber2) ; this is internally compared 
	MsgBox TRUE
else
	MsgBox FALSE
return
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Compare text with AHK

13 Nov 2015, 13:03

thank you MJs! it works :)
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: Compare text with AHK

13 Nov 2015, 14:22

aaand I'm stuck :D comparison goes fine until first name doesn't compare. I get a msgbox with YES or NO. Problem that if I choose NO, all others names goes onto red color until it came up another msgbox and if I click YES, all seconds names goes onto green color. I misted something on this If / else... Can you check it? :)

Code: Select all

!y::
xl := ComObjActive("Excel.Application")
loop
	{
		loopnr := A_Index
		if (xl.Range("B3").Offset(loopnr-1,0).Value = "")
				break
		xl := ComObjActive("Excel.Application")
		number1:= xl.Range("B3").Offset(loopnr-1,0).Text  ; Josefen Huge
		number2:= xl.Range("C3").Offset(loopnr-1,0).Text  ; JOSEFEN, HUGE
		StringCaseSense Locale
		StringReplace, number1, number1, `,,, all ; no comma, with number1 variable is still intact, the data is still intact also
		StringReplace, number2, number2, `,,, all ; no comma, with number2 variable is still intact, the data is still intact also 
		If (number1 = number2) ; this is internally compared 
			xl.Range("B3").Offset(loopnr-1,0).Font.ThemeColor := 7
		else
			MsgBox, 4,, Replace %number1% with %number2%?
				IfMsgBox Yes
					xl.Range("B3").Offset(loopnr-1,0).Font.ThemeColor := 7
				else IfMsgBox No
					xl.Range("B3").Offset(loopnr-1,0).Font.ThemeColor := 6
	}
return
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Compare text with AHK

13 Nov 2015, 15:30

from what I can see, it's the braces after the first else:

Code: Select all

!y::
xl := ComObjActive("Excel.Application")
loop
	{
		loopnr := A_Index
		if (xl.Range("B3").Offset(loopnr-1,0).Value = "")
				break
		xl := ComObjActive("Excel.Application")
		number1:= xl.Range("B3").Offset(loopnr-1,0).Text  ; Josefen Huge
		number2:= xl.Range("C3").Offset(loopnr-1,0).Text  ; JOSEFEN, HUGE
		StringCaseSense Locale
		StringReplace, number1, number1, `,,, all ; no comma, with number1 variable is still intact, the data is still intact also
		StringReplace, number2, number2, `,,, all ; no comma, with number2 variable is still intact, the data is still intact also 
		If (number1 = number2) ; this is internally compared 
			xl.Range("B3").Offset(loopnr-1,0).Font.ThemeColor := 7
		else{
			MsgBox, 4,, Replace %number1% with %number2%?
				IfMsgBox Yes
					xl.Range("B3").Offset(loopnr-1,0).Font.ThemeColor := 7
				else IfMsgBox No
					xl.Range("B3").Offset(loopnr-1,0).Font.ThemeColor := 6
			}
	}
return
 
before it was if (number1 = number2) change to 7, and if not show the msgbox, and that's it the next IfMsgBox weren't parst of the condition.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Cerulium, Sem552 and 172 guests