 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
BoBo Guest
|
Posted: Fri Feb 25, 2005 1:40 pm Post subject: |
|
|
toralf, you're my hero
Alte Gewohnheiten bleiben einem irgendwie kleben, da kommt dann plötzlich das ---> := daher und schon ist man/frau Out !
btw: dein Operand sieht irgendwie aus wie ein Adolf Smiley  |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Feb 25, 2005 1:43 pm Post subject: |
|
|
| BoBo wrote: | | Quote: | Clipboard = 12.34.5678_12:34_1.2345_2.3456_3.4567_4.5678 ; sample input
FileAppend, %Clipboard%`n, MyFile.txt ; test section |
| Code: | Loop, Read, MyFile.txt
{
StringSplit, MyNumberArray, A_LoopReadLine, %A_Tab%
ArrayToIgnore = %MyNumberArray0%
ArrayToIgnore -= 4 ; get only the last four arrays/fields/numbers
Loop, %MyNumberArray0% ; read all arrays
{
StringTrimRight, CurrentArray, MyNumberArray%A_Index%, 0
If A_Index <= %ArrayToIgnore%
Continue
MsgBox, will do some math with MyNumberArray%A_Index% = %CurrentArray% ; here you can do your math task
} |
So, where's the problem ? |
| Code: |
Loop, Read, MyFile.txt
{
StringSplit, MyNumberArray, A_LoopReadLine, %A_Tab%%A_Space%
ArrayToIgnore = %MyNumberArray0%
ArrayToIgnore -= 4 ; get only the last four arrays/fields/numbers
Loop, %MyNumberArray0% ; read all arrays
{
StringTrimRight, CurrentArray, MyNumberArray%A_Index%, 0
If A_Index <= %ArrayToIgnore%
Continue
if CurrentArray is float
MsgBox, will do some math with MyNumberArray%A_Index% = %CurrentArray% ; here you can do your math task
}
}
|
Bobo, I added the extra bracket at the end guessing that is where it was needed. I also added the float line the a_space and float line and now it seems to work, grabbing only the floats. Is the float line ahk gramatically correct? Thanks again for your help and everyone else's too. The first line of this thread says it all.
As for a follow through, I notice that ahk uses the same variable names as it reads the next line down. For example:
1st line of variables found
Myvar1 Myvar2 Myvar3
2nd line
Myvar1 Myvar2 Myvar3
If you have more than one line of variables, that will be used, how could you "rename" the second ( or more ) line of variables to be something different, for example - My2var1 My2var2 My2var3?
Or, if ahk could continue naming the variables counting up would work too.
Myvar4 Myvar5 Myvar6, and on. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Fri Feb 25, 2005 1:56 pm Post subject: |
|
|
Mr. toralf's tweak will save you some line of code and makes you familiar with a more sophisticated form how to (de)reference variables. Check it out.
 |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Fri Feb 25, 2005 2:04 pm Post subject: |
|
|
| BoBo wrote: | | btw: dein Operand sieht irgendwie aus wie ein Adolf Smiley |
Bitte, was? Ich verstehe nicht. Was ist ein Operand. Oder meinst do emoticons (:=)? Wenn ja, dann kann ich ja nichts dafür, ist AHK syntax und nicht MEINE. :) _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Feb 25, 2005 2:08 pm Post subject: |
|
|
| BoBo wrote: | Mr. toralf's tweak will save you some line of code and makes you familiar with a more sophisticated form how to (de)reference variables. Check it out.
 |
Thanks toralf, and Bobo, but
| Code: |
Loop, Read, MyFile.txt
{
StringSplit, ArrayOfNumbers, A_LoopReadLine, %A_Tab%%A_Space%
NumbersOfInterest := ArrayOfNumbers0 - 4
Loop, %NumbersOfInterest% ; read all arrays
{
Number := ArrayOfNumbers%A_Index%
MsgBox, I will do some math with ArrayOfNumbers%A_Index% = %Number%
}
}
|
does not work the same. It seems to be trimming exactly the opposite. i added the a_space. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Fri Feb 25, 2005 2:15 pm Post subject: |
|
|
| Anonymous wrote: | | Is the float line ahk gramatically correct? |
Not realy, "CurrentArray" doesn't have any value, it is "CurrentArrayi" where "i" is 0,1,2,3, ... see manual for arrays (or StringSplit)
| Anonymous wrote: | If you have more than one line of variables, that will be used, how could you "rename" the second ( or more ) line of variables to be something different, for example - My2var1 My2var2 My2var3?
Or, if ahk could continue naming the variables counting up would work too.
Myvar4 Myvar5 Myvar6, and on. |
What exactly do you want to do?
Yes you can do that, e.g. exchange | Code: | StringSplit, MyNumberArray, A_LoopReadLine, %A_Tab%%A_Space%
with
StringSplit, MyNumberArray%i%, A_LoopReadLine, %A_Tab%%A_Space%
| and count i up with every loop.
But I would not recomment that. It will be hard to read and understand. I would suggest to store the values in an different array or matrice. And do the calculation in another loop. That's a better structure. 1)collect data 2)manipulate data 3)present data. Each in its own loop (works most of the time). _________________ Ciao
toralf  |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Fri Feb 25, 2005 2:51 pm Post subject: |
|
|
| Quote: | | Bitte, was? Ich verstehe nicht. Was ist ein Operand. |
| Quote: | Operand - Programmierung-Fachbegriffe
Numerischer Wert oder String, der durch einen Operator zu einem anderen Operanden (oder mehreren) in Beziehung gesetzt wird.
Bei 2 * 3 sind die Zahlen die Operanden und " * " der Operator.
[More...] |
Tja, ich lag da wohl knapp daneben  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Fri Feb 25, 2005 2:58 pm Post subject: |
|
|
Dachte ich mir. :) Keep up the faith in the learning curve. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Mar 01, 2005 9:50 am Post subject: |
|
|
| Code: |
Loop, Read, MyFile.txt
{
StringSplit, MyNumberArray, A_LoopReadLine, %A_Tab%%A_Space%
Loop, %MyNumberArray0% ; read all arrays
{
StringTrimRight, CurrentArray, MyNumberArray%A_Index%, 0
if CurrentArray is float
MsgBox, will do some math with MyNumberArray%A_Index% = %CurrentArray% ; here you can do your math task
}
}
|
ok, the ignores were removed and it does exactly what it should. Is there anything in here that is still unecessary or unneeded?
MyFile.txt
| Code: |
text text
12.34.5678 90:12 3.456 7.890 1.234 5.678
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Tue Mar 01, 2005 11:07 am Post subject: |
|
|
| Code: |
Loop, Read, MyFile.txt
{
StringSplit, ArrayOfNumbers, A_LoopReadLine, %A_Tab%%A_Space%
NumbersOfInterest := ArrayOfNumbers0
Loop, %NumbersOfInterest% ; read all arrays
{
Number := ArrayOfNumbers%A_Index%
if Number is float
MsgBox, I will do some math with ArrayOfNumbers%A_Index% = %Number%
}
}
|
here is toralf's better code with float and a_space added. i'm still not sure if this is correct, but it does the same as above.
So now, I've tried to do simple math and can't get the syntax right.
For example, this:
Sum1 := ArrayofNumbers3 + ArrayofNumbers4
and then display the result.
MsgBox %Sum1% ; does not work
MyFile.txt
| Code: |
text text
12.34.5678 90:12 3.456 7.890 1.234 5.678
| [/quote] |
|
| Back to top |
|
 |
BoBo Guest
|
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Tue Mar 01, 2005 2:19 pm Post subject: |
|
|
You can't just do it with the Array of numbers. You first have to sort the one without float out.
This should work
| Code: | Loop, Read, MyFile.txt
{
StringSplit, ArrayOfItems, A_LoopReadLine, %A_Tab%%A_Space%
ListOfNumbers =
Loop, ArrayOfItems0 ; read all items from array
{
Number := ArrayOfNumbers%A_Index%
if Number is float
ListOfNumbers = %ListOfNumber%|%Number%
}
StringTrimRight,ListOfNumbers ,ListOfNumbers ,1 ;remove first pipe
StringSplit, ArrayOfNumbers, ListOfNumbers , |
Sum1 := ArrayofNumbers1 + ArrayofNumbers2 + ArrayofNumbers3 + ArrayofNumbers4
MsgBox %Sum1% = %ArrayofNumbers1% + %ArrayofNumbers2% + %ArrayofNumbers3% + %ArrayofNumbers4%
} |
_________________ Ciao
toralf  |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Mar 03, 2005 7:18 am Post subject: |
|
|
| toralf wrote: |
This should work
|
toralf, bier und die programmierung können möglicherweise nicht guten code bilden. Haha!
Result:
| Code: |
= + + +
= + + +
= + + +
|
|
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Thu Mar 03, 2005 10:30 am Post subject: |
|
|
Yeah, I know, there are two % missing. Find out where by yourself. >) _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Mar 03, 2005 12:07 pm Post subject: |
|
|
I assume the loop should have %ArrayOfItems0%.
But ArrayOfItems does not seem to be used after the loop, so
I changed both to ArrayofNumbers but still does not work.
I'm not seeing your hint. I do appreaciate your help though.
| Code: | Loop, Read, MyFile.txt
{
StringSplit, ArrayofNumbers, A_LoopReadLine, %A_Tab%%A_Space%
ListOfNumbers =
Loop, %ArrayofNumbers0% ; read all items from array
{
Number := ArrayOfNumbers%A_Index%
if Number is float
ListOfNumbers = %ListOfNumber%|%Number%
}
StringTrimRight,ListOfNumbers ,ListOfNumbers ,1 ;remove first pipe
StringSplit, ArrayOfNumbers, ListOfNumbers , |
Sum1 := ArrayofNumbers1 + ArrayofNumbers2 + ArrayofNumbers3 + ArrayofNumbers4
MsgBox %Sum1% = %ArrayofNumbers1% + %ArrayofNumbers2% + %ArrayofNumbers3% + %ArrayofNumbers4%
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|