AutoHotkey Community

It is currently May 27th, 2012, 4:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Asc
PostPosted: June 1st, 2011, 2:07 pm 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
I have only a small experience with AHK and I can normally get the right statements working but this has stumped me. I know it should bite me but it will not.
I am after the ascii number
List ="ABCD"
msgbox, Asc, List
To give the ascii of "A"
I have left it in this form knowing I am wrong. I have tried putting % everywhere. all I get is the string name not contents.

ie how do I display the value of Asc, List or Asc(List)

While I still have hair
Terry

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 2:10 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
1st break it up, each character has its own ascii value.
Code:
List = ABCD
stringSplit, chr, list
loop % chr0
  ascList .=  chr%a_index% " " asc( chr%a_index% ) "`n"

msgbox % ascList

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 2:25 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I think you may have overthought this one, TLM :wink: :

Code:
List = ABCD
Loop, Parse, List
   ascList .=   A_LoopField " " Asc(A_LoopField) "`n"
MsgBox % ascList

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 2:39 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
sinkfaze wrote:
I think you may have overthought this one, TLM :wink:
lolz

btw our code is pretty much the same thing,
whooo you loose one extra line whooo.. :)..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Last edited by TLM on June 2nd, 2011, 5:16 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 3:00 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
TLM wrote:
btw our code is pretty much the same thing,
whooo you loose one extra line whooo.. :)..


I also avoid the possibility of trying to explain StringSplit and dynamic variables as a follow-up discussion. I prefer only the laziest of solutions. :wink:

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 11:36 pm 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
Wow Thanks to all. Can you believe I was up till 1am this morning and did not get it.
TLM Yes I do have trouble with the way I reference variables.
The help file shows either asc(string) or asc, string
so I tried asc(List) and asc, List. which should give the ascii number of the first letter So I was stumped. I would appreciate that explained according to the help file the correct way of displaying msgbox, asc(List)
I never tried
msgbox % ascList
I will hang on to what hair I have left :D
Terry

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 1:01 am 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
I cannot find the explanation for .= I have for :=

Also I do not understand why. Extract from help file

Quote:
Asc(String): Returns the ASCII code (a number between 1 and 255) for the first character in String. If String is empty, 0 is returned.


does not work for
List = ABCD
msgbox, Asc(list) or msgbox, Asc(%List%)

I must be thick I did try your codes and see how they work but not equated to the example above.
Terry

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 2:04 am 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
TeeTwo wrote:
I cannot find the explanation for .=
Just look at it as a way to "grow a variable". To see the step by step growth, run this
Code:
loop 10
  msgbox % growingvariable .= a_index " "

msgbox % growingvariable .= "`nNow some text.`n"

msgbox % growingvariable .= "And yet even more.`n"

msgbox % growingvariable .= "As you can see.`n"

msgbox % growingvariable .= "It just keeps growing.`n"

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Last edited by TLM on June 2nd, 2011, 5:09 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 4:56 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
To the origional question.
Code:
Var:="ABC"
MsgBox % Asc(Var) ;65 asc of A
MsgBox % Asc("abc") ;97 asc of a


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 6:22 am 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
Thanks most sincerely. I really do appreciate the help and guidance. It has helped me to understand a little more of this amazing language.

I will wish you all a very G'Day
Terry

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 12:01 pm 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
I am trying to total ascii numbers which you showed me how. But how do I add these together to get a total.
I am trying
Code:
; array from above
while(x< List+1){
A.=   asc( chr%x%); This gives the ascii number at each iteration
; I cannot get the code to work to add the numbers for each iteration here To finish with all the ascii numbers of the letters in the list totaled together
x++
}

I have difficulty getting the referencing to work. I am so used to Basic and this syntax is trying.
Code:

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 12:54 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
I agree the syntax is something to get used too :)

Maybe:


Code:
list=abcd


Loop, Parse, List

{
asc_sum += Asc(A_LoopField)
asc_debug .=Asc(A_LoopField) "|"

}

msgbox %asc_sum%  `n%asc_debug%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 1:05 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
thank you Thanh00 , very short, I used TLM's code, example add ascii code
Code:
List = ABCD
stringSplit, chr, list
x:=0
y:=0
loop % chr0
  {
  ascList .=  chr%a_index% " " asc( chr%a_index% ) "`n"
  x:=asc(chr%a_index%)
  y:=(x+y)
  }
msgbox %ascList%`nTotal=%y%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 3:05 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
In this case only X has to be declared
Code:
List:="ABCD", x:=!!x ; init to true
stringSplit, chr, list
while chr%a_index% ; Alternative loop method if theres no auto array
  ascList .= chr%a_index% " " (y:=asc(chr%a_index%)) subStr(x+=y,1,0) "`n"
msgbox %ascList%`nTotal=%x%

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 3:29 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
thank you TLM, I make always complicated missing programming knowledge
thank you all for the different solutions


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me, rbrtryn and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group