AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

grabbing floats for math
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
BoBo
Guest





PostPosted: Fri Feb 25, 2005 1:40 pm    Post subject: Reply with quote

toralf, you're my hero Wink

Alte Gewohnheiten bleiben einem irgendwie kleben, da kommt dann plötzlich das ---> := daher und schon ist man/frau Out ! Laughing

btw: dein Operand sieht irgendwie aus wie ein Adolf Smiley Shocked
Back to top
Guest






PostPosted: Fri Feb 25, 2005 1:43 pm    Post subject: Reply with quote

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





PostPosted: Fri Feb 25, 2005 1:56 pm    Post subject: Reply with quote

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.

Cool
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Feb 25, 2005 2:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Guest






PostPosted: Fri Feb 25, 2005 2:08 pm    Post subject: Reply with quote

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.

Cool


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

PostPosted: Fri Feb 25, 2005 2:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
BoBo
Guest





PostPosted: Fri Feb 25, 2005 2:51 pm    Post subject: Reply with quote

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 Embarassed
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Feb 25, 2005 2:58 pm    Post subject: Reply with quote

Dachte ich mir. :) Keep up the faith in the learning curve.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Guest






PostPosted: Tue Mar 01, 2005 9:50 am    Post subject: Reply with quote

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






PostPosted: Tue Mar 01, 2005 11:07 am    Post subject: Reply with quote

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





PostPosted: Tue Mar 01, 2005 11:57 am    Post subject: Reply with quote

Code:
Sum1 := (ArrayofNumbers3 + ArrayofNumbers4)
MsgBox %Sum1% ; should work


Check this thread ---> [What's the proper use of () and "" in If statement]
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Tue Mar 01, 2005 2:19 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Guest






PostPosted: Thu Mar 03, 2005 7:18 am    Post subject: Reply with quote

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

PostPosted: Thu Mar 03, 2005 10:30 am    Post subject: Reply with quote

Yeah, I know, there are two % missing. Find out where by yourself. >)
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Guest






PostPosted: Thu Mar 03, 2005 12:07 pm    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group