AutoHotkey Community

It is currently May 27th, 2012, 10:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: "double numberize" list
PostPosted: April 25th, 2009, 1:20 am 
Hi everybody Is there any way to modify this code?
Code:
Clipboard =
WinActivate, a
Send ^c
ClipWait, 1
If Clipboard =
   Return
data := Clipboard
Loop Parse, data, `n, `r
{
   If (A_LoopField != "")
   {
;      result .= "aaa" A_Index . " = " . A_LoopField . "`r`n"
      result .= "PPP" A_Index . " = " . A_LoopField . "`r`n"
   }
}
Clipboard := result
ClipWait, 1
WinActivate, a
  Sendinput, ^v
ExitApp
Return


This one transform this:
Quote:
a
b
c
d
e
f


to This
Quote:
PPP1 = a
PPP2 = b
PPP3 = c
PPP4 = d
PPP5 = e
PPP6 = f


How to obtain this, please?
Quote:
PPP1 = a
UUU1 = b
PPP2 = c
UUU2= d
PPP3 = e
UUU3 = f


Thanks in advance. Regards, :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2009, 1:28 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
Code:
data =
(
a
b
c
d
e
f
g
)

; Method 1
Loop Parse, data, `n, `r
{
   If A_LoopField
   {
      prefix := Mod( A_Index, 2 ) ? "PPP" : "UUU"
      result1 .= prefix . A_Index . " = " . A_LoopField . "`r`n"
   }
}

; Method 2
Loop, parse, data, `n, `r
{
   If A_LoopField
   {
      toggle := !toggle
      prefix := toggle ? "PPP" : "UUU"
      result2 .= prefix . A_Index . " = " . A_LoopField . "`r`n"
   }
}

msgbox % "Method 1:`n" result1 "`nMethod 2:`n" result2

exitapp



If you're actually checking for existence (the "If A_Loopfield" statement), then Method 2 might be better, as it only alternates the prefix if you go into the if-statement block


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2009, 12:23 am 
sorry for asking something so basic but for me is too much...
with your code (tank you very much :D ),
Code:
data =
(
a
b
c
d
e
f
g
)

; Method 1
Loop Parse, data, `n, `r
{
   If A_LoopField
   {
      prefix := Mod( A_Index, 2 ) ? "PPP" : "UUU"
      result1 .= prefix . A_Index . " = " . A_LoopField . "`r`n"
   }
}

; Method 2
Loop, parse, data, `n, `r
{
   If A_LoopField
   {
      toggle := !toggle
      prefix := toggle ? "PPP" : "UUU"
      result2 .= prefix . A_Index . " = " . A_LoopField . "`r`n"
   }
}

;msgbox % "Method 1:`n" result1 "`nMethod 2:`n" result2
;exitapp

Code:
send, % "Method 1:`n" result1 "`nMethod 2:`n" result2

result is:
Quote:
Method 1:
PPP1 = a
UUU2 = b
PPP3 = c
UUU4 = d
PPP5 = e
UUU6 = f
PPP7 = g

Method 2:
PPP1 = a
UUU2 = b
PPP3 = c
UUU4 = d
PPP5 = e
UUU6 = f
PPP7 = g

I need:
Quote:
PPP1 = a
UUU1 = b
PPP2 = c
UUU2= d
PPP3 = e
UUU3 = f

How to please? :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2009, 12:58 am 
Offline

Joined: November 27th, 2008, 9:44 am
Posts: 62
Code:
data =
(
a
b
c
d
e
f
g
)

pcounter=0
ucounter=0
Loop, parse, data, `n, `r
{
   If A_LoopField
   {
      toggle := !toggle
      if toggle
      {
         prefix := "PPP"
         counter := ++pcounter
      }
      else
      {
         prefix := "UUU"
         counter := ++ucounter
      }
      result .= prefix . counter . " = " . A_LoopField . "`r`n"
   }
}

msgbox % result

exitapp


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thank you
PostPosted: April 27th, 2009, 8:22 am 
Thank you very much !!! :D :D :D


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, specter333, tomoe_uehara, XstatyK and 61 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