KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Detecting what button was clicked

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Wed May 07, 2008 6:31 pm    Post subject: Detecting what button was clicked Reply with quote

Ok here is the scenario....

I have a text box that is the focus when the form is first loaded. On this text box I have the .onleave set to validate the information contained in the text box (in this case user names are validated against AD).

Problem is if I click on the exit button (that I created) and the text box is empty I get my error (as expected since there is not a "" user in AD), and I am unable to exit the form.

Should I abandon the use of the .onleave, or is there a way to detect that exit button was clicked and not perform the validation?

I have code if anyone wants it.

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Wed May 07, 2008 9:37 pm    Post subject: Reply with quote

Ja, abandon .onleave ... it leads to no good.
Modify a variable .OnChange of the textbox and after .Visible of child form is no more doublecheck the value of the variable you modify every .OnChange of the textbox Wink

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed May 07, 2008 10:17 pm    Post subject: Reply with quote

When you say click the exit button, you mean click the X button ?
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Wed May 07, 2008 10:26 pm    Post subject: Reply with quote

No the system X is disabled. This is an actual button that I created.

I think I will abandon the .onleave and just validate at "run" of main code.

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed May 07, 2008 10:48 pm    Post subject: Reply with quote

Should be easy to tell if you clicked the exit button, you would be in the event handler for it when it occurs.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed May 07, 2008 10:49 pm    Post subject: Reply with quote

Wait a tick - I see where you going. The OnLeave occurs before the OnClick ... k, hmmmm
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Wed May 07, 2008 10:59 pm    Post subject: Reply with quote

You catch on fast... Smile Yea that is what I was doing. For now I have removed the .onleave and am validating during the "run" portion of the script.
_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed May 07, 2008 11:06 pm    Post subject: Reply with quote

seems you have a work-around though, nice. But its kinda bugging me that one can't do it. Must be a way, hmmm ...
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed May 07, 2008 11:27 pm    Post subject: Reply with quote

Here's one thought. Like cappy says though - might be fraught with danger...

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form

$TextBox = $Form.Controls.Add($System.TextBox)
$TextBox.Center
$TextBox.Leave = "TextBox_Leave()"

$Button = $FOrm.Controls.Add($System.BUtton)
$BUtton.Center
$Button.Text = "Exit"
$Button.Top = $TextBox.Bottom + 10
$Button.Click = "Button_Click()"
$Button.MouseEnter = "Button_MouseEnter()"
$Button.MouseLeave = "Button_MouseLeave()"
$Button.Tag = 0

$FOrm.Center
$FOrm.Show

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function TextBox_Leave()

 If $BUtton.Tag = 0

  If $TextBox.Text = ""

   $= $System.MessageBox.Show("Bad Data")

   $TextBox.Focus

  Endif

 Endif

EndFUnction

Function Button_Click

 $Form.Hide

EndFunction

Function Button_MouseEnter
 
 $Button.Tag = 1

EndFunction

Function Button_MouseLeave
 
 $Button.Tag = 0

EndFunction

Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Thu May 08, 2008 12:28 am    Post subject: Reply with quote

Shawn, very interesting workaround. I would have never thought of that.

This wouldn't necessarily work if using the keyboard only, but who does that anyway right? Wink
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Thu May 08, 2008 1:55 am    Post subject: Reply with quote

Got to thinking about this on the way home..

In my form build section I define the TextBox first and later I define the button.

How does KiX decide which event to process first the .leave or the .click, is it in build order? If so I could easily define the TextBox after the Button.

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Thu May 08, 2008 1:11 pm    Post subject: Reply with quote

I am prolly not understanding what you are wanting, but I don't think you need any of that, here is an example:

Code:

Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

$Form = $System.Form()
$Form.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form.Size = $System.Size(400,300) ;(Width,Height)
$Form.Text = "Test Form"

$TextBox = $System.TextBox()
$TextBox.Left = 80
$TextBox.Text = ""
$TextBox.Top = 100
$TextBox.Width = 230
$nul = $Form.Controls.Add($TextBox)

$ExitButton = $System.Button()
$ExitButton.Click = "ExitButton_Click()"
$ExitButton.Left = 230
$ExitButton.Text = "Exit"
$ExitButton.Top = 130
$nul = $Form.Controls.Add($ExitButton)

$Label = $System.Label()
$Label.Left = 80
$Label.Text = ""
$Label.Top = 60
$Label.Width = 230
$nul = $Form.Controls.Add($Label)

$Form.Show  ;Displays the Form

While $Form.Visible
   $Nul = Execute($Form.DoEvents())
Loop
Exit 0

Function ExitButton_Click()
  If Not($TextBox.Text = "")
    If CheckForUser($TextBox.Text) = 1
      $Label.Text = "Valid"
      ;do stuff
      ;Quit()
    Else
      $Label.Text = "Not Valid"
      $TextBox.Text = ""
      $TextBox.Focus
    EndIf
  EndIf
EndFunction

Function CheckForUser($samAccountName)
   
  $objRootDSE = GetObject("LDAP://rootDSE")
  $defaultNamingContext = $objRootDSE.Get("defaultNamingContext")
 
   $strUserName = $samAccountName
   $objConnection = CreateObject("ADODB.Connection")
   $objConnection.Open ("Provider=ADsDSOObject;")

   $objCommand = CreateObject("ADODB.Command")
   $objCommand.ActiveConnection = $objConnection

   $objCommand.CommandText = "<LDAP://" + $defaultNamingContext + ">;(&(objectCategory=User)(samAccountName=" + $strUserName + "));samAccountName;subtree"
   
   $objRecordSet = $objCommand.Execute

   If $objRecordset.RecordCount = 0
      $CheckForUser = 0 ; does not exist
   Else
      $CheckForUser = 1 ; exists
   EndIf

   $objConnection.Close

EndFunction

If the input is valid then do stuff then quit
If the input is not valid clear input field and wait for valid input

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group