Guicontrol not active

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Guicontrol not active

01 Oct 2015, 16:12

Hi

certainly a simple thing, but I don't know why.

I have a simple script to train the "times table / 1x1 / 101 / Einmaleins".
- a start dialogue
- a loop which asks for multiplications, checks the result (plus Beep and Menutray and counting ...)
- returns to start dialogue and displays the results

Everything is fine, but the "ElapsedTime" is not displayed with Guicontrol. I can see it in the variables, I can display it with MsgBox - but it is not displayed in the in the GUI :eh:

Thanks for advice.

EDIT:
I found that it works with

Code: Select all

SetFormat, float, 0.0
But I still have to check why ....

Code: Select all

; 1x1.ahk
    #NoEnv
    #Singleinstance force
    Gosub, ShowStartDialog
Return

;; **********************************************************
ShowStartDialog:

    Gui, new, 
    Gui, Add, Text,  vZeit   ,   Zeit: ----
    Gui, Add, Text,  vRichtig,   Richtig: ----
    Gui, Add, Text,  vFalsch   ,   Falsch: ----
    Gui, Add, Button, Default    gcalcloop  vcalcloop,   Starten...
    Gui , Show, w200 h130
return

;; **********************************************************
calcloop:
    countrichtig := 0
    countfalsch := 0
    StartTime := A_TickCount

    Loop, 1
    {
        Random, fakt1, 0, 10     ; Faktor zwischen 0 und 10
        Random, fakt2, 0, 10     ; Faktor zwischen 0 und 10
        ergebnis := fakt1 * fakt2
        anzeige = %fakt1% x %fakt2%
        ; InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
        InputBox, eingabe, 1x1 Trainer, Berechne`n%anzeige%,,130,150
        IfEqual, eingabe, %ergebnis%
        {
            bewertung = Richtig
            SoundBeep , 5000
            countrichtig+=1
        }
        Else
        {
            bewertung = Falsch
            SoundBeep , 2000
            countfalsch+=1
        }
        TrayTip,Vergleich, Eingabe: %eingabe%`nErgebnis: %ergebnis%`nBewertung: %bewertung%
    }
    SetFormat, float, 0.2
    ElapsedTime := (A_TickCount - StartTime)/1000
    GuiControl,, Zeit,      Zeit: %ElapsedTime% sec
    GuiControl,, Richtig,   Richtig: %countrichtig%
    GuiControl,, Falsch,    Falsch: %countfalsch%
return
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
nli

Re: Guicontrol not active

01 Oct 2015, 20:56

Try it with: Gui, Add, Text, vZeit w190, Zeit: ----

Also, I think you may want to move these two lines into the ShowStarDialog sub?

Code: Select all

countrichtig := 0
countfalsch := 0
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Guicontrol not active

02 Oct 2015, 01:17

nli wrote:Try it with: Gui, Add, Text, vZeit w190, Zeit: ----...
Great, it works. :thumbup:
I never thought that the width of the control would be the problem. The GUI is wide enough, and until now I had no problem with missing text - the time-variable is completely skipped, not truncated :?

nli wrote:...Also, I think you may want to move these two lines into the ShowStarDialog sub?

Code: Select all

countrichtig := 0
countfalsch := 0
No. I need it at the start of every loop to reset the existing, just displayed values.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Guicontrol not active

02 Oct 2015, 01:31

Use border to see what happend to your text control if you dont set w

Gui, Add, Text, vZeit border, Zeit: ----

The width will be set to the input (Zeit: ----).
But if the new Input is larger than the first one, the text will not be displayed.
Zusatz auf deutsch / Additional in german
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
just me
Posts: 9456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Guicontrol not active

02 Oct 2015, 01:39

Peter2 wrote:the time-variable is completely skipped, not truncated :?
It's not skipped, it's wrapped into a second line, but the height of the control won't be adjusted. You might try the option -Wrap to see the difference.
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Guicontrol not active

02 Oct 2015, 01:45

w190, border, -wrap, % ".." - simple things which shows the detailed structure and flexible usage of AHK.
Thanks to all for the replies.
For me, maybe it's better to feed the pigeons in the park :oops:
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Guicontrol not active

02 Oct 2015, 01:55

Another hint:
Everytime I create a Gui, I test the controls (text, radio, checkbox, ...) with borders.
After everthing fits, just remove the borders. =)

Example: This is how I teached me to work with Gui's

Testing looks like:

Code: Select all

; h21    => Passe die Höhe an das nebenstehende Edit Control an
; 0x200  => Zentriere den Text, da das Text Control jetzt höher ist
; border => Prüfe ob Text Control mit dem Edit Control übereinstimmt (*danach wieder löschen)
Gui, Add, Text, xm ym w100 h21 0x200 border, % "Text Control 1"

; x+1    => Zum Überprüfen ob die Höhe der beiden Controls übereinstimmen (*danach anpassen z.B. x+5)
Gui, Add, Edit, x+1 yp w100, % "Edit Control 1"

; y+1    => Zum Überprüfen ob die nächste Zeile mit der oberen übereinstimmt (*danach anpassen z.b. y+4)
Gui, Add, Text, xm y+1 w100 h21 0x200 border, % "Text Control 2"

Gui, Add, Edit, x+1 yp w100, % "Edit Control 2"

Gui, Show, w300 h200, % "Title"
return
 
GuiClose:
GuiEscape:
ExitApp
Image

Finished looks like:

Code: Select all

Gui, Add, Text, xm ym w100 h21 0x200, % "Text Control 1"
Gui, Add, Edit, x+5 yp w100, % "Edit Control 1"
Gui, Add, Text, xm y+4 w100 h21 0x200, % "Text Control 2"
Gui, Add, Edit, x+5 yp w100, % "Edit Control 2"
Gui, Show, w300 h200, % "Title"
return

GuiClose:
GuiEscape:
ExitApp
Image
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen and 317 guests