LV_GetText without a ListView/GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

LV_GetText without a ListView/GUI

26 Feb 2018, 04:05

Hi, everyone, This script works very well for me, Thanks for @just me's help, but i just got an idea and meet a challenge, can't accomplish it by myself:
How can i make the script works without a GUI, use a preset conditions and vAmount(for example 30000) to calculate then instant get the results MsgBox, %Q1% %Q2% %Q3% %Q4% %R% by default

Really appreciate for your great help

Code: Select all

#NoEnv
SetBatchLines, -1
; Constant multipliers -----------------------------------------------------------------------------------------------------------
P1 := 7.25
P2 := 6.53
P3 := 6.16
P4 := 5.43
; GUI ----------------------------------------------------------------------------------------------------------------------------
Gui, Margin, 10, 10
Gui, Add, Text, xm ym w200, Amount:
Gui, Add, Edit, xp y+2 wp Number vAmount, 30000
Gui, Add, Text, ym wp, Minimum Deviation:
Gui, Add, Edit, xp y+2 wp Number vMinD, 10
Gui, Add, Text, ym wp, Maximum Deviation:
Gui, Add, Edit, xp y+2 wp Number vMaxD, 50
Gui, Add, Text, xm wp Section, Maximum Iterations:
Gui, Add, Edit, xp y+2 w200 ReadOnly Number, 3
Gui, Add, UpDown, vUDI Range1-3, 3
Gui, Add, Text, ys, Maximum Results:
Gui, Add, Edit, xp y+2 w200 ReadOnly Number, 15
Gui, Add, UpDown, vUDR Range1-30, 15
Gui, Add, Text, ys, Maximum Delta (n * 48):
Gui, Add, Edit, xp y+2 w200 ReadOnly Number, 3
Gui, Add, UpDown, vUDD Range1-5, 3
Gui, Add, Text, xm, Results:
Gui, Add, ListView, xm y+2 w620 r15 gSelectResult, #|Q1|Q2|Q3|Q4|Result|Max Delta|%A_Space%
Loop, % LV_GetCount("Column") - 1
   LV_ModifyCol(A_Index, "Integer")
Gui, Add, Button, xm wp gCalculate, Calculate
Gui, Add, StatusBar
Gui, Show, , Calculator
Return
; Exit ---------------------------------------------------------------------------------------------------------------------------
GuiClose:
ExitApp
; Calculate the results ----------------------------------------------------------------------------------------------------------
Calculate:
Gui, +OwnDialogs
Gui, Submit, NoHide
;
Num := Amount
Min := Num + MinD
Max := Num + MaxD
MaxLoopCount := UDI
MaxResults := UDR
MaxDelta := UDD * 48
;
Q := Floor(Num // (P1 + P2 + P3 + P4))
Q -= Mod(Q, 48)
If (Q < MaxDelta) {
   MsgBox, 16, %A_ThisLabel%, Cannot iterate %UDI% times!
   GuiControl, Focus, UDI
   Return
}
LV_Delete()
;
Results := []
Loop {
   Q1 := Q2 := Q3 := Q4 := Q
   S1 := Q1 * P1
   Loop {
      S2 := S1 + (Q2 * P2)
      If (S2 >= Min)
         Break
      Q3 := Q
      Loop {
         S3 := S2 + (Q3 * P3)
         If (S3 >= Min)
            Break
         Q4 := Q
         Loop {
            S4 := S3 + (Q4 * P4)
            If (S4 >= Min) {
               If (S4 <= Max) {
                  R := (Q1 * P1) + (Q2 * P2) + (Q3 * P3) + (Q4 * P4)
                  D := 0
                  If ((Q2 - Q) > D)
                     D := Q2 - Q
                  If ((Q3 - Q) > D)
                     D := Q3 - Q
                  If ((Q4 - Q) > D)
                     D := Q4 - Q
                  If (D <= MaxDelta)
                     Results.Push([Q1, Q2, Q3, Q4, Round(R, 2), D])
                  If !(Results.Length() < MaxResults)
                     Break, 4
               }
               Break
            }
            Q4 += 48
         }
         Q3 += 48
      }
      Q2 += 48
   }
   Q -= 48
} Until (A_Index >= MaxLoopCount)
;
For I, R In Results
   LV_Add("", A_Index, R*)
Loop, % LV_GetCount("Column")
   LV_ModifyCol(A_Index, "AutoHdr")
LV_ModifyCol(7, "Sort")
L := Results.Length()
SB_SetText("   Found " . L . " solution" . (L <> 1 ? "s." : "."))
Return
; Select a result from the ListView by double click
SelectResult:
Gui, +OwnDialogs
If (A_GuiEvent = "DoubleClick") && (SelectedRow := LV_GetNext()) {
   LV_GetText(Q1, SelectedRow, 2)
   LV_GetText(Q2, SelectedRow, 3)
   LV_GetText(Q3, SelectedRow, 4)
   LV_GetText(Q4, SelectedRow, 5)
   LV_GetText(R, SelectedRow, 6)
   ; do what you want to do with the variables here
   MsgBox, 0, Selected Result, %Q1% %Q2% %Q3% %Q4% %R% ; just for testing
}
Return
Last edited by ivill on 26 Feb 2018, 19:17, edited 1 time in total.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: LV_GetText without a ListView/GUI

26 Feb 2018, 14:55

Like this ?

Code: Select all

#NoEnv
SetBatchLines, -1
; Constant multipliers
P1 		:= 7.25
P2 		:= 6.53
P3 		:= 6.16
P4 		:= 5.43
Amount  := 30000
MinD    := 10 	; Minimum Deviation
MaxD    := 50 	; Maximum Deviation
UDR     := 15	; Maximum Results
UDD     := 3	; Maximum Delta ( 1 to 5  )
UDI     := 3	; Maximum Iterations (1 to 3 )
gosub Calculate
ExitApp


Calculate:
Num := Amount
Min := Num + MinD
Max := Num + MaxD
MaxLoopCount := UDI
MaxResults := UDR
MaxDelta := UDD * 48
;
Q := Floor(Num // (P1 + P2 + P3 + P4))
Q -= Mod(Q, 48)
If (Q < MaxDelta) {
   MsgBox, 16, %A_ThisLabel%, Cannot iterate %UDI% times!
   Return
}

;
Results := []
Loop {
   Q1 := Q2 := Q3 := Q4 := Q
   S1 := Q1 * P1
   Loop {
      S2 := S1 + (Q2 * P2)
      If (S2 >= Min)
         Break
      Q3 := Q
      Loop {
         S3 := S2 + (Q3 * P3)
         If (S3 >= Min)
            Break
         Q4 := Q
         Loop {
            S4 := S3 + (Q4 * P4)
            If (S4 >= Min) {
               If (S4 <= Max) {
                  R := (Q1 * P1) + (Q2 * P2) + (Q3 * P3) + (Q4 * P4)
                  D := 0
                  If ((Q2 - Q) > D)
                     D := Q2 - Q
                  If ((Q3 - Q) > D)
                     D := Q3 - Q
                  If ((Q4 - Q) > D)
                     D := Q4 - Q
                  If (D <= MaxDelta)
                     Results.Push([Q1, Q2, Q3, Q4, Round(R, 2), D])
                  If !(Results.Length() < MaxResults)
                     Break, 4
               }
               Break
            }
            Q4 += 48
         }
         Q3 += 48
      }
      Q2 += 48
   }
   Q -= 48
} Until (A_Index >= MaxLoopCount)
;
str := "Found : " Results.Maxindex() " results:`nQ1`tQ2`tQ3`tQ4`tResult`tMax Delta`n"
For I, R In Results
    str .= R[1] "`t" R[2] "`t" R[3] "`t" R[4] "`t" R[5]  "`t" R[6] "`n"
MsgBox %str%
return

esc::
    ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: LV_GetText without a ListView/GUI

26 Feb 2018, 19:07

Odlanir wrote:Like this ?

Code: Select all

#NoEnv
SetBatchLines, -1
; Constant multipliers
P1 		:= 7.25
P2 		:= 6.53
P3 		:= 6.16
P4 		:= 5.43
Amount  := 30000
MinD    := 10 	; Minimum Deviation
MaxD    := 50 	; Maximum Deviation
UDR     := 15	; Maximum Results
UDD     := 3	; Maximum Delta ( 1 to 5  )
UDI     := 3	; Maximum Iterations (1 to 3 )
gosub Calculate
ExitApp


Calculate:
Num := Amount
Min := Num + MinD
Max := Num + MaxD
MaxLoopCount := UDI
MaxResults := UDR
MaxDelta := UDD * 48
;
Q := Floor(Num // (P1 + P2 + P3 + P4))
Q -= Mod(Q, 48)
If (Q < MaxDelta) {
   MsgBox, 16, %A_ThisLabel%, Cannot iterate %UDI% times!
   Return
}

;
Results := []
Loop {
   Q1 := Q2 := Q3 := Q4 := Q
   S1 := Q1 * P1
   Loop {
      S2 := S1 + (Q2 * P2)
      If (S2 >= Min)
         Break
      Q3 := Q
      Loop {
         S3 := S2 + (Q3 * P3)
         If (S3 >= Min)
            Break
         Q4 := Q
         Loop {
            S4 := S3 + (Q4 * P4)
            If (S4 >= Min) {
               If (S4 <= Max) {
                  R := (Q1 * P1) + (Q2 * P2) + (Q3 * P3) + (Q4 * P4)
                  D := 0
                  If ((Q2 - Q) > D)
                     D := Q2 - Q
                  If ((Q3 - Q) > D)
                     D := Q3 - Q
                  If ((Q4 - Q) > D)
                     D := Q4 - Q
                  If (D <= MaxDelta)
                     Results.Push([Q1, Q2, Q3, Q4, Round(R, 2), D])
                  If !(Results.Length() < MaxResults)
                     Break, 4
               }
               Break
            }
            Q4 += 48
         }
         Q3 += 48
      }
      Q2 += 48
   }
   Q -= 48
} Until (A_Index >= MaxLoopCount)
;
str := "Found : " Results.Maxindex() " results:`nQ1`tQ2`tQ3`tQ4`tResult`tMax Delta`n"
For I, R In Results
    str .= R[1] "`t" R[2] "`t" R[3] "`t" R[4] "`t" R[5]  "`t" R[6] "`n"
MsgBox %str%
return

esc::
    ExitApp
Hi, @Odlanir, can i get only the values from the first row? please check attachment 1.png
1.png
1.png (4.52 KiB) Viewed 1771 times
the final output is as shown on the attachment 2.png
2.png
2.png (1.84 KiB) Viewed 1771 times
Thanks
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: LV_GetText without a ListView/GUI

27 Feb 2018, 02:39

Yes, replace with this:

Code: Select all

UDR     := 1	; Maximum Results
;...
;...
;...
str:=""
For I, R In Results
    str .= R[1] "`n" R[2] "`n" R[3] "`n" R[4] "`n" R[5]
MsgBox %str%
return
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: LV_GetText without a ListView/GUI

27 Feb 2018, 03:01

Odlanir wrote:Yes, replace with this:

Code: Select all

UDR     := 1	; Maximum Results
;...
;...
;...
str:=""
For I, R In Results
    str .= R[1] "`n" R[2] "`n" R[3] "`n" R[4] "`n" R[5]
MsgBox %str%
return
How to call the R[1]-R[5], in order to use them later (not just the example MsgBox %str% )

Code: Select all

str:=""
For I, R In Results
MsgBox, %R[1]% "`n" %R[2]% "`n" %R[3]% "`n" %R[4]% "`n" %R[5]% ;Error: illegal characters
return
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: LV_GetText without a ListView/GUI

27 Feb 2018, 03:14

First, your Msgbox is wrong, should be:

Code: Select all

MsgBox % R[1] "`n" R[2] "`n" R[3] "`n" R[4] "`n" R[5]
Second, after 107 posts you're asking how to populate a variable with another variable contents ? Strange.
Anyway:

Code: Select all

blablabla := R[1]
ccccccc   := R[2]
agfhasgsf := R[3]
another1  := R[4]
thelast   := R[5]
You know what those values mean, so call the variables to be able to recognize them later in the script
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: LV_GetText without a ListView/GUI

27 Feb 2018, 03:23

Odlanir wrote:First, your Msgbox is wrong, should be:

Code: Select all

MsgBox % R[1] "`n" R[2] "`n" R[3] "`n" R[4] "`n" R[5]
Second, after 107 posts you're asking how to populate a variable with another variable contents ? Strange.
Anyway:

Code: Select all

blablabla := R[1]
ccccccc   := R[2]
agfhasgsf := R[3]
another1  := R[4]
thelast   := R[5]
You know what those values mean, so call the variables to be able to recognize them later in the script
I'm sorry, you are brilliant, I just recognized how clumsy i am... I'm grateful for your instruction. gonna have try.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada, inseption86, mikeyww and 369 guests