Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
Mister B
Old
#3261  
Mister B's Avatar
Senior Member
Thanks Meter 253
Posts: 1,572
Join Date: Sep 2006
Location: Ratchada (Bangkok)
Quote:
Originally Posted by RoryB View Post
Try
Code:
If (RegRead( "HKLM", "System\State\Hardware", "Headset" ) EQ 1)
   Run ("\Program Files\Tools\ScreenOff.exe")
EndIf
if (wndActive ("Start"))
   PowerOff
Else
   Run ("\Windows\Display Switch.lnk")
EndIf
I find = is best for setting value and EQ is best for checking value.

Did you want to always check both reg and window? or is it an either/or question?
Code:
If (RegRead( "HKLM", "System\State\Hardware", "Headset" ) EQ 1)
   Run ("\Program Files\Tools\ScreenOff.exe")
ElseIf (wndActive ("Start"))
   PowerOff
Else
   Run ("\Windows\Display Switch.lnk")
EndIf
EQ makes all the difference, works perfect.
Thanks once again RoryB.
 
howdykeith
Old
(Last edited by howdykeith; 12th April 2010 at 04:52 PM.)
#3262  
Senior Member
Thanks Meter 1
Posts: 876
Join Date: Oct 2009
Location: East Greenwich, RI
Quote:
Originally Posted by CLHatch View Post
Which operator returns the results you expect depends on the results you expect... Are you dealing with a number, or a string? Compare these:
Code:
Message("03" = 3)
Message("03" eq 3)
The first line outputs 1 (TRUE), the second outputs 0 (FALSE). Which is correct? Both.

The first line is using a numeric comparison, so it coverts the "03" to the number 3, sees 3=3, and returns TRUE.

The second line is using a alphanumeric comparison, so it converts the 3 to "3", sees "03" eq "3", and returns FALSE.

EDIT:
This very much applies to the other comparison operators too... look at this:
Code:
Message(2 < 10)
Message(2 lt 10)
The first returns 1 (TRUE), as you would expect, since 2 is less than 10.
What you might not expect is that the second returns 0 (FALSE). This is because it gets converted to "2" lt "10", and it does the comparison character by character in the strings... "2" is greater than "1" in the character map, so the comparison is FALSE.
Yah these were the issues I had expected. U r right with the not comparing other numbers as true.
I hadn't meant to compare 1,2,3,4 values to True, I had really meant to evaluate 1,2,3,4 as True.

Code:
test=3
If (test)
	message ("Is True")
EndIf
So i would expect this to work:

Code:
If (RegRead( "HKLM", "System\State\Hardware", "Headset" ))
   Run ("\Program Files\Tools\ScreenOff.exe")
ElseIf (wndActive ("Start"))
   PowerOff
Else
   Run ("\Windows\Display Switch.lnk")
EndIf
And now that I am clear on True = 1, and I would expect this to be more exact (in this case):

Code:
If (RegRead( "HKLM", "System\State\Hardware", "Headset" ) = True)
   Run ("\Program Files\Tools\ScreenOff.exe")
ElseIf (wndActive ("Start"))
   PowerOff
Else
   Run ("\Windows\Display Switch.lnk")
EndIf
Sometimes it is beneficial of course to treat numbers as numbers/booleans and strings as strings (of course).
 
howdykeith
Old
#3263  
Senior Member
Thanks Meter 1
Posts: 876
Join Date: Oct 2009
Location: East Greenwich, RI
ok.

since we r clarifying things with eq / LT / GT.

i have wondered if lt works as a alphabetizer?

Is "Ant" lt "Anu" ?
Is "Ants" gt "Ant" ?
 
CLHatch
Old
(Last edited by CLHatch; 12th April 2010 at 04:59 PM.)
#3264  
Senior Member
Thanks Meter 5
Posts: 468
Join Date: May 2008
Location: Nashville, TN
Quote:
Originally Posted by howdykeith View Post
ok.

since we r clarifying things with eq / LT / GT.

i have wondered if lt works as a alphabetizer?

Is "Ant" lt "Anu" ?
Is "Ants" gt "Ant" ?
On the first, yes. On the second... I would think so, would have to check (would think the added "s" would make it "greater than"). Try it out:
Code:
Message("Ant" lt "Anu")
Message("Ants" gt "Ant")
EDIT:
Oh, one thing to remember about the alpha comparisons, case matters...
"ant" lt "Ant"
is TRUE.
 
RoryB
Old
(Last edited by RoryB; 12th April 2010 at 05:31 PM.)
#3265  
RoryB's Avatar
Recognized Developer
Thanks Meter 621
Posts: 2,599
Join Date: Sep 2008
Location: Lexington

 
DONATE TO ME
Code:
Message("Ant" lt "Anu") returns 1
Message("Ants" gt "Ant") returns 1
Message("ant" lt "Ant") returns 0
Message("ant" gt "Ant") returns 1
Samsung Galaxy S III
Read About Me to see what I am working on & following like CHTS, Reminder and AppTask widgets, and CHT basic function tweaks. Also, Fixed CHT restarting when you have no tasks.
Mortscript | iniEditor | regEditor| MortScripts to toggle settings
Samsung Infuse 4G drowned. If you have one check out Scott's CM10 or CM10PA Firmware
ATT Fuze (HTC RAPH110) with Energy ROM: Energy.RAPHAEL.29022.Sense2.5.Cookie.2.0.Jul.06
HTC Wizard|See about me for my ROM collection and other work
 
CLHatch
Old
#3266  
Senior Member
Thanks Meter 5
Posts: 468
Join Date: May 2008
Location: Nashville, TN
Quote:
Originally Posted by RoryB View Post
Code:
Message("Ant" lt "Anu") returns 1
Message("Ants" gt "Ant") returns 1
Message("ant" lt "Ant") returns 0

Interesting... the last one returns 0? Hmm.
 
howdykeith
Old
(Last edited by howdykeith; 12th April 2010 at 05:45 PM.)
#3267  
Senior Member
Thanks Meter 1
Posts: 876
Join Date: Oct 2009
Location: East Greenwich, RI
Code:
Message("A" lt "B")
#True

Message("Aa" lt "A")
#False

Message("A" lt "a")
#True

Message("a" lt "A")
#False

Message("aa" lt "A")
#False
It probly is simpler to first check on lowercase to lowercase. We can first see if this works for case where uper/lower doesnt apply, like file and directory names.
 
CLHatch
Old
#3268  
Senior Member
Thanks Meter 5
Posts: 468
Join Date: May 2008
Location: Nashville, TN
Quote:
Originally Posted by howdykeith View Post
Code:
Message("A" lt "B")
#True

Message("Aa" lt "A")
#False

Message("A" lt "a")
#True

Message("a" lt "A")
#False

Message("aa" lt "A")
#False
It probly is simpler to first check on lowercase to lowercase. We can first see if this works for case where uper/lower doesnt apply, like file and directory names.
Ah, that makes sense then, I just had the order wrong. Upper case is before lower case in the character map.
 
SouthernAtHeart
Old
#3269  
Member
Thanks Meter 0
Posts: 90
Join Date: Jan 2010
Default Replacement for BREAK

Okay, if I don't want to use the beta version, I don't have the BREAK command. So how could I change this to work...

ForEach key, value in iniKeys ( UserFolder\"sort.txt","array" )
If ( Key eq LastImage )
Y = True
Endif
If (Y)
ArrayImg[I] = (Key)
I = I + 1
If ( I = ImageCount + 1)
BREAK
EndIf
EndIf
EndForEach




..........Thanks!
Sprint Touch Pro2, MalROM 6.5.3
Unlocked, Verizon Radio, AT&T Network, USA
 
RoryB
Old
#3270  
RoryB's Avatar
Recognized Developer
Thanks Meter 621
Posts: 2,599
Join Date: Sep 2008
Location: Lexington

 
DONATE TO ME
Quote:
Originally Posted by SouthernAtHeart View Post
Okay, if I don't want to use the beta version, I don't have the BREAK command. So how could I change this to work...

ForEach key, value in iniKeys ( UserFolder\"sort.txt","array" )
If ( Key eq LastImage )
Y = True
Endif
If (Y)
ArrayImg[I] = (Key)
I = I + 1
If ( I = ImageCount + 1)
BREAK
EndIf
EndIf
EndForEach
.........Thanks!
To be sure I understand. . .

You want to do foreach, but instead of doing all values in the sort.txt you want to stop once you reach a specific count or value?
This kind of has a feel of an ini file format where you would put data in categories and then you could do a foreach for that category only.
Samsung Galaxy S III
Read About Me to see what I am working on & following like CHTS, Reminder and AppTask widgets, and CHT basic function tweaks. Also, Fixed CHT restarting when you have no tasks.
Mortscript | iniEditor | regEditor| MortScripts to toggle settings
Samsung Infuse 4G drowned. If you have one check out Scott's CM10 or CM10PA Firmware
ATT Fuze (HTC RAPH110) with Energy ROM: Energy.RAPHAEL.29022.Sense2.5.Cookie.2.0.Jul.06
HTC Wizard|See about me for my ROM collection and other work

 
Post Reply+
Tags
mortscript, mortscript examples
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...