|
-
May 16th, 2008, 04:12 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Problem using dynamic integer array
I am using a 3rd-party class to create Scheduled Tasks. One of the methods of this class expected an Integer array to represent the days of the month.
For example
[VBCODE]
Dim trig As New MonthlyTrigger(Me.StartTime.Value.Hour, Me.StartTime.Value.Minute, {1,2,3,4}, MonthsOfTheYear.January)
[/CODE]
I have a form with 31 checkboxes to represent the days of the month and the user can select any or all of them. So I would like to create a sub called, say, GetMonthDays, that would check which checkboxes are checked and then build an integer array from it. However, I'm stuck.
I can use the text value of the checkbox and simply Cint/DirectCast it but how to add it to the integer array? Is there a better way to do this?
Code:
Private Function GetDaysOfTheMonth() As Integer()
Dim dom As Integer() = Nothing
For Each C As Control In gb_MonthsDays.Controls
If TypeOf C Is CheckBox Then
Dim cb As CheckBox = DirectCast(C, CheckBox)
If cb.Checked Then ??????????
End If
Next
Return dom
End Function
ManagePC - the all-in-one PC management and inventory tool
-
May 16th, 2008, 05:16 AM
#2
Re: [2005] Problem using dynamic integer array
Code:
Dim dom() As Integer = {} 'changed
If cb.Checked Then
Array.Resize(dom, dom.Length + 1)
dom(dom.Length - 1) = Integer.Parse(cb.Text)
End If
'check dom length, if 0 none checked
Last edited by dbasnett; May 16th, 2008 at 05:20 AM.
-
May 16th, 2008, 05:16 AM
#3
Re: [2005] Problem using dynamic integer array
Use a list(of integer) to get the checked days, then export that list to an integer array. You can name you checkboxes "checkbox0, checkbox1".... or assign an integer value to the Tag property of each chackbox. When you loop thru the checkboxes, you read back this integer value and add it to your list. When done, call list.ToArray to export the array. This example using the Tag property of the checkboxes. If you serialized the name, you can read the name and use string.substring to get the number.
Code:
Private Function GetDaysOfTheMonth() As Integer()
Dim dom As New List(Of Integer)
For Each C As Control In gb_MonthsDays.Controls
If TypeOf C Is CheckBox Then
Dim cb As CheckBox = DirectCast(C, CheckBox)
If cb.Checked Then
dom.Add(CInt(cb.Tag))
End If
Next
Return dom.ToArray
End Function
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
May 16th, 2008, 05:29 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Problem using dynamic integer array
Ah, the ToArray method, that's what I need. I'll use the Text property instead of the Tag property as it's 1, 2, 3 etc for each checkbox
ManagePC - the all-in-one PC management and inventory tool
-
May 16th, 2008, 05:35 AM
#5
Re: [RESOLVED] [2005] Problem using dynamic integer array
edit - go with list. i was thinking of something else.
Last edited by dbasnett; May 16th, 2008 at 05:42 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|