#195649 - 2009-08-28 10:47 AM
Steelkix question
|
BoForce
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.
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:
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:
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
|
|
|
|
#195654 - 2009-08-28 02:33 PM
Re: Steelkix question
[Re: Shawn]
|
Shawn
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:
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:
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
|
|
|
|
#195656 - 2009-08-28 03:40 PM
Re: Steelkix question
[Re: Shawn]
|
Shawn
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 ...)
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
|
|
|
|
#195658 - 2009-08-28 04:55 PM
Re: Steelkix question
[Re: It_took_my_meds]
|
BoForce
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:
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:
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:
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:
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
   
Registered: 1999-08-13
Posts: 8611
|
Here's a silly but workable work-around:
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|