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 

Form Validation (if,else,Return???)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
umek



Joined: 02 Oct 2004
Posts: 74

PostPosted: Sat May 06, 2006 3:12 pm    Post subject: Form Validation (if,else,Return???) Reply with quote

I'm getting stuck on scripting a simple form validation. grrrr ...
I have a group of fields to validate. First I used a message box to inform the user about an empty/required field and
after confirming the message the focus jumps into the field which was pointed out. But I'm tired of confirming the messages and
I tried upon PhiLho's advice to highlight the text beside the field but I get stuck.
Please take a look at the sample script (it's just an example) which might be more expressive than the attempt to describe it English.

I will try to descripe it:
The button "MsgBox" is the first script I used and Button "Colors" is my current problem: If there is an empty field (after pressing "Colors")
the text beside the control gets colored red, but all field with an entered value are appearing in the field "Result". I don't want to use "Return"
because the text beside every empty field should get a new color.

Code:
#Persistent
fsoTitle=Dispatch
; Generated using SmartGUI Creator 3.5.1
Gui, 2: -Theme +Border
    Gui, 2:Add, Text, x7 y18 w135 h19, List Queues whose:
    Gui, 2:Add, Text, x7 y40 w135 h19 vLable1, Queue Name:
    Gui, 2:Add, Text, x7 y62 w135 h19 vLable2, Status:
    Gui, 2:Add, Text, x7 y84 w135 h19 vLable3, Owner:
    Gui, 2:Add, Text, x7 y106 w135 h19 vLable4, Area:
    Gui, 2:Add, Text, x7 y128 w135 h19, Result:
    Gui, 2:Add, Edit, x142 y38 w120 h19 vCtrlEdit1,
    Gui, 2:Add, Edit, x142 y60 w120 h19 vCtrlEdit2,
    Gui, 2:Add, Edit, x142 y82 w120 h19 vCtrlEdit3,
    Gui, 2:Add, Edit, x142 y104 w120 h19 vCtrlEdit4,
    Gui, 2:Add, Edit, x7 y150 w258 h76 vCtrlEdit05 -VScroll,
    Gui, 2:Add, Button, x7 y235 w80 h20, MsgBox
    Gui, 2:Add, Button, x95 y235 w80 h20, Colors
    Gui, 2:Add, Button, x183 y235 w80 h20, Exit
  Gui, 2:Show, x369 y269 h260 w272, %fsoTitle%
Return

2ButtonMsgBox:
  Gui, 2:Submit, NoHide
    if CtrlEdit1 =
      {
        MsgBox, 48, %fsoTitle%, Please enter the Queue Name.`t`t
        GuiControl, 2:Focus, CtrlEdit1
        Return
      }
    else
      {
        fsoValue = Value 1: %CtrlEdit1%
      }
    if CtrlEdit2 =
      {
        MsgBox, 48, %fsoTitle%, Please enter the Status.`t`t
        GuiControl, 2:Focus, CtrlEdit2
        Return
      }
    else
      {
        fsoValue = %fsoValue%`nValue 2: %CtrlEdit2%
      }
    if CtrlEdit3 =
      {
        MsgBox, 48, %fsoTitle%, Please enter the Owner.`t`t
        GuiControl, 2:Focus, CtrlEdit3
        Return
      }
    else
      {
        fsoValue = %fsoValue%`nValue 3: %CtrlEdit3%
      }
    if CtrlEdit4 =
      {
        MsgBox, 48, %fsoTitle%, Please enter the Area.`t`t
        GuiControl, 2:Focus, CtrlEdit4
        Return
      }
    else
      {
        fsoValue = %fsoValue%`nValue 4: %CtrlEdit4%
      }
    GuiControl, 2:, CtrlEdit05, %fsoValue%
Return

2ButtonColors:
  Gui, 2:Submit, NoHide
  Gui, 2:Font, cBlack
    if CtrlEdit1 =
      {
        Gui , Font , cRed
        GuiControl, 2:Font, Lable1
      }
    else
      {
        fsoValue = Value 1: %CtrlEdit1%
      }
    if CtrlEdit2 =
      {
        Gui , Font , cRed
        GuiControl, 2:Font, Lable2
      }
    else
      {
        fsoValue = %fsoValue%`nValue 2: %CtrlEdit2%
      }
    if CtrlEdit3 =
      {
        Gui , Font , cRed
        GuiControl, 2:Font, Lable3
      }
    else
      {
        fsoValue = %fsoValue%`nValue 3: %CtrlEdit3%
      }
    if CtrlEdit4 =
      {
        Gui , Font , cRed
        GuiControl, 2:Font, Lable4
      }
    else
      {
        fsoValue = %fsoValue%`nValue 4: %CtrlEdit4%
      }
    GuiControl, 2:, CtrlEdit05, %fsoValue%
Return

!r:: Reload

2ButtonExit:
ExitApp


Please help ....
_________________
Works on my machine!
Back to top
View user's profile Send private message
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Sat May 06, 2006 10:29 pm    Post subject: Reply with quote

Not sure I understand the question, but maybe this is a start for what you want?

Code:
2ButtonColors:
  EmptyFieldCheck = 0
  Gui, 2:Submit, NoHide
  Gui, 2:Font, cBlack
    if CtrlEdit1 =
      {
        EmptyFieldCheck = 1
        Gui , Font , cRed
        GuiControl, 2:Font, Lable1
      }
    else
      {
        fsoValue = Value 1: %CtrlEdit1%
      }
    if CtrlEdit2 =
      {
        EmptyFieldCheck = 1
        Gui , Font , cRed
        GuiControl, 2:Font, Lable2
      }
    else
      {
        fsoValue = %fsoValue%`nValue 2: %CtrlEdit2%
      }
    if CtrlEdit3 =
      {
        EmptyFieldCheck = 1
        Gui , Font , cRed
        GuiControl, 2:Font, Lable3
      }
    else
      {
        fsoValue = %fsoValue%`nValue 3: %CtrlEdit3%
      }
    if CtrlEdit4 =
      {
        EmptyFieldCheck = 1
        Gui , Font , cRed
        GuiControl, 2:Font, Lable4
      }
    else
      {
        fsoValue = %fsoValue%`nValue 4: %CtrlEdit4%
      }
         
         if EmptyFieldCheck != 1
           {
             GuiControl, 2:, CtrlEdit05, %fsoValue%
           }
Return

_________________
____________________
Back to top
View user's profile Send private message
umek



Joined: 02 Oct 2004
Posts: 74

PostPosted: Sun May 07, 2006 12:04 am    Post subject: Reply with quote

My English must be horrible!
But that's exactly what I want! Thanks! May I ask what != is doing there?


umek
_________________
Works on my machine!
Back to top
View user's profile Send private message
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Sun May 07, 2006 12:39 am    Post subject: Reply with quote

!= simply means "Not Equal", same as If EmptyFieldCheck <> 1 or IfNotEqual, EmptyFieldCheck, 1.

And nothing is really wrong with your English... I'm still a bit slow on reading through code posted by others Smile
_________________
____________________
Back to top
View user's profile Send private message
umek



Joined: 02 Oct 2004
Posts: 74

PostPosted: Mon May 08, 2006 6:08 pm    Post subject: Reply with quote

Better slow in reading, than like me, in understanding. Searching for != didn't return any results and I had no words to search for.
Thanks a lot for the explanation, ... it will help in the future.
_________________
Works on my machine!
Back to top
View user's profile Send private message
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Mon May 08, 2006 7:43 pm    Post subject: Reply with quote

Those commands are all hidden away in the Variables and Expressions section, but the search function on the web page makes it a bit hard to search for them sometimes Confused

You're Welcome, and best of luck with the rest of the script Smile
_________________
____________________
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Mon May 08, 2006 11:22 pm    Post subject: Reply with quote

A tip for using CHM help files like AutoHotkey's: If you click anywhere in the right half of the window, you can then press Control-F to do a "find in page". The same thing works in Internet Explorer.
Back to top
View user's profile Send private message Send e-mail
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Tue May 09, 2006 1:45 am    Post subject: Reply with quote

Chris wrote:
A tip for using CHM help files like AutoHotkey's: If you click anywhere in the right half of the window, you can then press Control-F to do a "find in page". The same thing works in Internet Explorer.


True.

But first you have to find the page with the item you want

Laughing
_________________
____________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
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