Page 1 of 1 1
Topic Options
#195649 - 2009-08-28 10:47 AM Steelkix question
BoForce Offline
Fresh Scripter
**

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
Hello guys,

First post and it's not even about Kix, but SteelKix.
For some reason I'm unable to use a Select-Case-EndSelect statement.
When I'm trying to use this, I get the following error message.

ERROR!
Message: Argument types do not match


The code section where I'm calling the eventhandler for a Combobox TextChanged event.
 Code:
Global $ComboBoxScheduleTask = $forms.ComboBox()
$FormScheduleJob.Controls.Add($ComboBoxScheduleTask)
$ComboBoxScheduleTask.Size = $drawing.Size(100,21)
$ComboBoxScheduleTask.Text = "Daily"
$ComboBoxScheduleTask.Location = $drawing.Point(12,35)
$ComboBoxScheduleTask.TabIndex = 2
$ComboBoxScheduleTask.MaxDropDownItems = 3
$ComboBoxScheduleTask.TextChanged += $system.eventhandler(AddressOf 
cmb_ST_TextChanged)


EventHandler cmb_ST_TextChanged:
 Code:
Function cmb_ST_TextChanged($sender,$e)
Select
   Case $sender.Text = "Daily"
	$GroupBoxDaily.Visible = 1
	$GroupBoxWeekly.Visible = 0
	$GroupBoxMonthly.Visible = 0
   Case $sender.Text = "Weekly"
	$GroupBoxDaily.Visible = 0
	$GroupBoxWeekly.Visible = 1
	$GroupBoxMonthly.Visible = 0
   Case $sender.Text = "Monthly"
	$GroupBoxDaily.Visible = 0
	$GroupBoxWeekly.Visible = 0
	$GroupBoxMonthly.Visible = 1
EndSelect
EndFunction


When I change the Select-Case-EndSelect with a simple If-EndIf, there is no problem.

EventHandler with If-EndIf:

 Code:
Function cmb_ST_TextChangedOK($sender,$e)
If $sender.Text = "Daily"
   $GroupBoxDaily.Visible = 1
   $GroupBoxWeekly.Visible = 0
   $GroupBoxMonthly.Visible = 0
EndIf

If $sender.Text = "Weekly"
   $GroupBoxDaily.Visible = 0
   $GroupBoxWeekly.Visible = 1
   $GroupBoxMonthly.Visible = 0
EndIf

If $sender.Text = "Monthly"
   $GroupBoxDaily.Visible = 0
   $GroupBoxWeekly.Visible = 0
   $GroupBoxMonthly.Visible = 1
EndIf
EndFunction


Can anyone tell me what I'm doing wrong?

Thanks,

BoForce

Top
#195653 - 2009-08-28 02:20 PM Re: Steelkix question [Re: BoForce]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
When setting up events in Steelkix you have to ensure you use the right Event Handler class ... here's a little overview ...

1) First, go to somewhere like MSDN and look-up the docs for the event handler your setting-up, in this case:

TextChanged Event

2) Make note of the syntax, in this case:

 Quote:

Visual Basic (Declaration)

Public Event TextChanged As TextChangedEventHandler


3) Assign your event handler using this class (your basically creating an object of type TextChangedEventHandler) ...

 Code:

$ComboBoxScheduleTask.TextChanged += $System.TextChangedEventHandler(AddressOf 
cmb_ST_TextChanged)



Didn't have a chance to test this so pls advise ...

-Shawn

Top
#195654 - 2009-08-28 02:33 PM Re: Steelkix question [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
So you may be asking "Why did my SELECT break?". It probably will work but Steelkix had a problem entering the event function ...

The function "definition" for the TextChangedEventHandler looks like this:

 Code:
Private Sub textChangedEventHandler(ByVal sender As Object, ByVal args As TextChangedEventArgs)
    ' Omitted Code: Insert code that does something whenever
    ' the text changes...
End Sub


The function definition for the generic EventHandler class that you were using looks like this:

 Code:
Public Sub EventHandler ( _
    sender As Object, _
    e As EventArgs _
)


Notice that the second argument (e) is different (EventArgs versus TextChangedEventArgs) ?

When the event got triggered, .Net was trying to pass a TextChangedEventArgs to your function, but only an EventArgs was declared.

TextChangedEventArgs is actually a derived class from EventArgs, and adds additional information specific to that Event ...

-Shawn

Top
#195655 - 2009-08-28 03:34 PM Re: Steelkix question [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hold the phone. Actually in work now and trying this stuff - getting weird results ... standby ...
Top
#195656 - 2009-08-28 03:40 PM Re: Steelkix question [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ok, looks like the ComboBox can take an EventArgs OK ... tried setting-up a little test snippet, does this work ok for you (once running, just keep hitting the A key to see results ...)

 Code:
Break On

Reference("System.Windows.Forms") 
Reference("System.Drawing")

Imports $System = System
Imports $Forms = System.Windows.Forms
Imports $Drawing = System.Drawing

$Form = $Forms.Form()
$Form.Text = "Test"

$ComboBox1 = $Forms.ComboBox()
$ComboBox1.TextChanged += $System.EventHandler(AddressOf ComboBox1_TextChanged)

$Form.Controls.Add($ComboBox1)

$Forms.Application.EnableVisualStyles
$Forms.Application.Run($form);

Exit 0

Function ComboBox1_TextChanged($sender, $e)
 Select
  Case $sender.text = "a"
   ? "a detected"
  Case $sender.text = "aa"
   ? "aa detected"
  Case $sender.text = "aaa"
   ? "aaa detected"
 EndSelect
EndFunction

Top
#195657 - 2009-08-28 03:51 PM Re: Steelkix question [Re: Shawn]
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
It's great to see that people are starting to use SteelKiX. Is anyone else working on it apart from WvS? I was really hoping to contribute but I'm suffering from RSI at the moment so I can't. I would love to see this adopted more however - it's a great supplement to the KiXtart syntax.
Top
#195658 - 2009-08-28 04:55 PM Re: Steelkix question [Re: It_took_my_meds]
BoForce Offline
Fresh Scripter
**

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
Shawn,

Thanks for your replies.

Your snippet is working fine. I just found out that a Select-Case-EndSelect is working fine as long as I don't try to do something with another control.

This works just fine:
 Code:
Function cmb_ST_TextChanged($sender,$e)
Select
   Case $sender.Text = "Daily"
        ? 'Daily'
   Case $sender.Text = "Weekly"
        ? 'Weekly'
   Case $sender.Text = "Monthly"
        ? 'Monthly'
EndSelect
EndFunction


This will fail:

 Code:
Function cmb_ST_TextChanged($sender,$e)
Select
   Case $sender.Text = "Daily"
	$GroupBoxDaily.Visible = 1
	$GroupBoxWeekly.Visible = 0
	$GroupBoxMonthly.Visible = 0
   Case $sender.Text = "Weekly"
	$GroupBoxDaily.Visible = 0
	$GroupBoxWeekly.Visible = 1
	$GroupBoxMonthly.Visible = 0
   Case $sender.Text = "Monthly"
	$GroupBoxDaily.Visible = 0
	$GroupBoxWeekly.Visible = 0
	$GroupBoxMonthly.Visible = 1
EndSelect
EndFunction


After some testing, this is failing to:

 Code:
Function cmb_ST_TextChanged($sender,$e)
Select
   Case $sender.Text = "Daily"
	$Button1.Visible = 1
   Case $sender.Text = "Weekly"
	$Button2.Visible = 1
   Case $sender.Text = "Monthly"
	$Button1.Visible = 0
	$Button2.Visible = 0
EndSelect
EndFunction


The Select-Case-EndSelect statement does seem to be able to handle any action to controls.
When I put the $Button1.Visible = 0 after the EndSelect, $Button1 is gone after I've changed the value of the Combobox.
So within the eventhandler cmb_ST_TextChanged I can do various actions towards controls, as long
as they are not performed after a Case.

This works fine:

 Code:
Function cmb_ST_TextChanged($sender,$e)
Select
   Case $sender.Text = "Daily"
	? 'Daily'
   Case $sender.Text = "Weekly"
	? 'Weekly'
   Case $sender.Text = "Monthly"
	? 'Monthly'
EndSelect

$ButtonScheduleJobClose.Visible = 0
EndFunction

Top
#195671 - 2009-08-29 02:39 PM Re: Steelkix question [Re: BoForce]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Here's a silly but workable work-around:

 Code:
Function ComboBox1_TextChanged($sender, $e)
 Select
  Case $sender.text = "a" 
   If 1 
    $Sender.Text = "You pressed A"
   Endif
  Case $sender.text = "aa"
   ? "aa detected"
  Case $sender.text = "aaa"
   ? "aaa detected"
 EndSelect
EndFunction

Top
#195881 - 2009-09-11 04:50 PM Re: Steelkix question [Re: Shawn]
WvS Offline
Fresh Scripter
*****

Registered: 2009-05-30
Posts: 42
Loc: Netherlands
There is some weird stuff going on there, I will look in to it. I will try to release a new version this weekend, I have been very busy. Some rather interesting stuff will be in this version.
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.067 seconds in which 0.033 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org