Page 1 of 1

Compare text with AHK

Posted: 13 Nov 2015, 09:40
by euras
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

Re: Compare text with AHK

Posted: 13 Nov 2015, 09:57
by MJs
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
 

Re: Compare text with AHK

Posted: 13 Nov 2015, 10:24
by euras
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...

Re: Compare text with AHK

Posted: 13 Nov 2015, 10:35
by MJs
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

Re: Compare text with AHK

Posted: 13 Nov 2015, 13:03
by euras
thank you MJs! it works :)

Re: Compare text with AHK

Posted: 13 Nov 2015, 14:22
by euras
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

Re: Compare text with AHK

Posted: 13 Nov 2015, 15:30
by MJs
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.