AutoHotkey Community

It is currently May 27th, 2012, 12:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: March 21st, 2010, 12:18 pm 
Offline

Joined: February 1st, 2006, 4:37 pm
Posts: 365
I have some new wishes :-)

The code below contains a begin, but I do not really know how I can proceed.

(excuse some text in the code is in Swedish - I hope it does not pose a problem)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Point One:
Background
When I filled out the information in the "Edit field"
I want to press the button "Sök Produkt" it's OK.

But
When I press the button, the program jumps to the label "ButtonSökProdukt"
My first problem: the window closes

My wish
When the button is pressed, I would jump to a subroutine or function (not a label)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Point Two:
I write numerals and / or characters in "Edit field"
but if the "Enter" key is pressed, I want to do the same thing as the Button "Sök Produkt" would be done.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Point Three:
If I press the Button "Sök Produkt" or "Enter" key without any text in the "Edit field". I get a message and a new attempt.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Code:
#SingleInstance force
#NoEnv
SetBatchLines -1

Start:

Menu Tray, NoStandard
Menu Tray, Add, Exit, GuiClose
Menu Tray, Default, Exit

; Storleken på fönstret
; Gui, Show, x250 y250 w350 h1000, Produktkontroll - Hemsidan
Gui 1:Show, x131 y91 h570 w993, Produktkontroll - Hemsidan

Gui 1:Font, cBlue s18 bold, Verdana
Gui 1:Add, Text, Center x0 y20 w330 h40 , Produktidentifikation
Gui 1:Font, S12 CDefault, Verdana; ; Önskad font, storlek och färg.

Gui 1:Add, Radio,  x20  y60  w160 h30 glblSend gFocus Checked vRadio1, Best. Nr      ; Radiobutton
Gui 1:Add, Radio,  x20  y85  w160 h30 glblSend gFocus         vRadio2, EAN - kod          ; Radiobutton
Gui 1:Add, Edit,   x20  y125 w160 h25 gInput vInput
Gui 1:Add, Button, x200 y60  w80  h90, Sök Produkt

; Rita linjer
Gui 1:Add, Text, x0 y170 w330 h1 0x7     ;Horizontal Line > Black
Gui 1:Add, Text, x330 y0 w1 h170 0x7   ;Vertical Line > Black

Gui 1:Add, Text, x656 y20 w110 h30, Best.nr .:
Gui 1:Add, Text, x776 y20 w190 h30 vTxtChk1
Gui 1:Add, Text, x656 y60 w100 h30, EAN ......:
Gui 1:Add, Text, x776 y60 w190 h30 vTxtChk2

Gui Show
Gosub Focus
Return


lblSend:
   iNbr := SubStr(a_GuiControl, 0, 1)
   GuiControlGet myText,, edtInput
   GuiControl ,, txtchk%iNbr%, %myText%
Return

Focus:
    GuiControl Focus, Input   ; Sätt fokus på inmatande fältet
   Send ^a         ; Markera hela fältet
   Send {Delete}   ; Töm fältet
Return



Input:
   Gui Submit, NoHide
   If Radio1
      {
      GuiControl ,, TxtChk1, %Input%
      GuiControl ,, TxtChk2,
      }
   else
      {
      GuiControl ,, TxtChk2, %Input%
      GuiControl ,, TxtChk1,
      }
Return





ButtonSökProdukt:
   ; MsgBox knapp tryckt
   Gui Submit  ; Save each control's contents to its associated variable.
   
   ; MsgBox Radio1 = %Radio1% `n Radio2 = %Radio2%
   If Radio1
      RadioVal = BestNr
   else
      RadioVal = EAN
   
   If not Input
      {
      MsgBox Inget beställningsnr eller EAN - Problem
      }
      
   MsgBox RadioVal = %RadioVal% `nInput = %Input%

Goto End



GuiEscape:
   {
   MsgBox 48, Programavslut,
      (
      Du kommer att avsluta programmet med ESC-knappen.
      Börja om genom att starta programmet igen `n
      Tack för denna gång!
      )
   }

GuiClose:
ExitApp

End:
ExitApp


I do not understand everything in the script, but it works so far.
There are certainly things that could write better / nicer :-)

//Jan


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 2:31 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Quote:
Point 1: My first problem: the window closes
use Gui, Submit, NoHide

Quote:
My wish When the button is pressed, I would jump to a subroutine or function (not a label)


You can put any label name in (as you have used before using gSubName). A label is the same as a subroutine. You can't call functions directly (as far as I am aware) like that, but you can call a function from a sub:
Code:
#NoEnv
Gui, Add, Button, gMySub, Say Hello
Gui, Show
Return

MySub:
   MyFunction("hello")
Return

MyFunction(text)
{
   MsgBox, %text%
}


Quote:
Point Two: if the "Enter" key is pressed, I want to do the same thing as the Button "Sök Produkt" would be done
You can add the word "Default" in the add button command, so it is the default button selected, like this:
Code:
Gui Add, Button, x200 y60  w80  h90 gMySub Default, Sök Produkt


Quote:
Point Three: If I press the Button "Sök Produkt" or "Enter" key without any text in the "Edit field". I get a message and a new attempt.
You already have this in your script, no?

Here is your code:

Code:
#SingleInstance force
#NoEnv
SetBatchLines -1

Start:

Menu Tray, NoStandard
Menu Tray, Add, Exit, GuiClose
Menu Tray, Default, Exit

; Storleken på fönstret

Gui, 1:Default
; you can use this instead of putting the gui number all the time
Gui Font, cBlue s18 bold, Verdana
Gui Add, Text, Center x0 y20 w330 h40 , Produktidentifikation
Gui Font, S12 CDefault, Verdana; ; Önskad font, storlek och färg.

Gui Add, Radio,  x20  y60  w160 h30 glblSend Checked vRadio1, Best. Nr      ; Radiobutton
Gui Add, Radio,  x20  y85  w160 h30 glblSend vRadio2, EAN - kod          ; Radiobutton
Gui Add, Edit,   x20  y125 w160 h25 gInput vInput
Gui Add, Button, x200 y60  w80  h90 gMySub Default, Sök Produkt

; Rita linjer
Gui Add, Text, x0 y170 w330 h1 0x7     ;Horizontal Line > Black
Gui Add, Text, x330 y0 w1 h170 0x7   ;Vertical Line > Black

Gui Add, Text, x656 y20 w110 h30, Best.nr .:
Gui Add, Text, x776 y20 w190 h30 vTxtChk1
Gui Add, Text, x656 y60 w100 h30, EAN ......:
Gui Add, Text, x776 y60 w190 h30 vTxtChk2

Gui Show, x131 y91 h570 w993, Produktkontroll - Hemsidan ; show the GUI [u]after[/u] adding controls, not before
GuiControl, Focus, Input ; no need to put this in a sub

Return

lblSend:
   iNbr := SubStr(a_GuiControl, 0, 1)
   GuiControlGet myText,, edtInput
   GuiControl ,, txtchk%iNbr%, %myText%
   GuiControl, Focus, Input
Return

Input:
   Gui Submit, NoHide
   If Radio1
      {
      GuiControl ,, TxtChk1, %Input%
      GuiControl ,, TxtChk2,
      }
   else
      {
      GuiControl ,, TxtChk2, %Input%
      GuiControl ,, TxtChk1,
      }
Return

MySub:
   ; MsgBox knapp tryckt
   Gui Submit, NoHide  ; Save each control's contents to its associated variable.
   
   ; MsgBox Radio1 = %Radio1% `n Radio2 = %Radio2%
   If Radio1
      RadioVal = BestNr
   else
      RadioVal = EAN
   
   If not Input
   {
      MsgBox Inget beställningsnr eller EAN - Problem
      Return
   }
     
   MsgBox RadioVal = %RadioVal% `nInput = %Input%

   Goto, End

GuiEscape:
   MsgBox 48, Programavslut,
      (
      Du kommer att avsluta programmet med ESC-knappen.
      Börja om genom att starta programmet igen `n
      Tack för denna gång!
      )

End:
GuiClose:
   ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 7:36 pm 
Offline

Joined: February 1st, 2006, 4:37 pm
Posts: 365
Yes! It works :-)
(The Structure on the program looks much better now - thank you! :-))

It "appears" new requests when things start to work :-)
- - - - - - - - - - - - - - - - -

I write numerals and / or characters in "Edit field"
The "Radio Button 1" is selected.

Now!
I press the "Radio Button 2" (its OK!)

But.
The information (to the right - row 48-54)
is not moved to the right row, (before next characters is pressed)

Is it easy to do? (How?)

//Jan


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav and 23 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