-
Jun 19th, 2017, 07:57 AM
#1
Thread Starter
Enjoy the moment
[RESOLVED] how do i add to an array comboxes strings?
hey,
i have like 10 comboboxes that i need to add the same values
now instead of adding for each combobox
i want to add it to all the combos at once
this is how i am using right now
Code:
DtDay(1).AddItem "06:00"
DtDay(1).AddItem "06:30"
DtDay(1).AddItem "07:00"
DtDay(1).AddItem "07:30"
DtDay(1).AddItem "08:00"
DtDay(1).AddItem "08:30"
DtDay(1).AddItem "09:00"
DtDay(1).AddItem "09:30"
DtDay(1).AddItem "10:00"
DtDay(1).AddItem "10:30"
DtDay(1).AddItem "11:00"
DtDay(1).AddItem "11:30"
DtDay(1).AddItem "12:00"
DtDay(1).AddItem "12:30"
DtDay(1).AddItem "13:00"
DtDay(1).AddItem "13:30"
DtDay(1).AddItem "14:00"
DtDay(1).AddItem "14:30"
DtDay(1).AddItem "15:00"
DtDay(1).AddItem "15:30"
DtDay(1).AddItem "16:00"
DtDay(1).AddItem "16:30"
DtDay(1).AddItem "17:00"
DtDay(1).AddItem "17:30"
DtDay(1).AddItem "18:00"
DtDay(1).AddItem "18:30"
DtDay(1).AddItem "19:00"
DtDay(1).AddItem "19:30"
DtDay(1).AddItem "20:00"
DtDay(1).AddItem "20:30"
DtDay(1).AddItem "21:00"
DtDay(1).AddItem "21:30"
DtDay(1).AddItem "22:00"
DtDay(1).AddItem "22:30"
DtDay(1).AddItem "23:00"
DtDay(1).AddItem "23:30"
DtDay(1).ListIndex = 0
Code:
DtDay(2).AddItem "06:00"
DtDay(2).AddItem "06:30"
DtDay(2).AddItem "07:00"
DtDay(2).AddItem "07:30"
DtDay(2).AddItem "08:00"
DtDay(2).AddItem "08:30"
DtDay(2).AddItem "09:00"
DtDay(2).AddItem "09:30"
DtDay(2).AddItem "10:00"
DtDay(2).AddItem "10:30"
DtDay(2).AddItem "11:00"
DtDay(2).AddItem "11:30"
DtDay(2).AddItem "12:00"
DtDay(2).AddItem "12:30"
DtDay(2).AddItem "13:00"
DtDay(2).AddItem "13:30"
DtDay(2).AddItem "14:00"
DtDay(2).AddItem "14:30"
DtDay(2).AddItem "15:00"
DtDay(2).AddItem "15:30"
DtDay(2).AddItem "16:00"
DtDay(2).AddItem "16:30"
DtDay(2).AddItem "17:00"
DtDay(2).AddItem "17:30"
DtDay(2).AddItem "18:00"
DtDay(2).AddItem "18:30"
DtDay(2).AddItem "19:00"
DtDay(2).AddItem "19:30"
DtDay(2).AddItem "20:00"
DtDay(2).AddItem "20:30"
DtDay(2).AddItem "21:00"
DtDay(2).AddItem "21:30"
DtDay(2).AddItem "22:00"
DtDay(2).AddItem "22:30"
DtDay(2).AddItem "23:00"
DtDay(2).AddItem "23:30"
DtDay(2).ListIndex = 0
BTW
i need it to enter by 15 minutes each
ex.
06:00
06:15
06:30
until 23:45
and so on....
tnx in advanced
salsa31
-
Jun 19th, 2017, 08:17 AM
#2
Re: how do i add to an array comboxes strings?
You can use some some basic loops for this.
Sample for the hours only
Code:
Dim lHour As Long
For lHour = 0 To 23
dtDay(0).AddItem = Format(lHour, "00") & ":00"
Next lHour
See if you can use this sample to create a slightly more advanced version to add half hours or quarter hours.
-
Jun 19th, 2017, 08:26 AM
#3
Re: how do i add to an array comboxes strings?
Code:
Private Sub Command1_Click()
AddTimeSlots Combo1, 60
End Sub
Private Sub Command2_Click()
AddTimeSlots Combo1, 30
End Sub
Private Sub Command3_Click()
AddTimeSlots Combo1, 15
End Sub
Private Sub AddTimeSlots(oCMB As ComboBox, ByVal lMinuteStep As Long)
Dim lHour As Long, lMin As Long
oCMB.Clear
For lHour = 0 To 23
For lMin = 0 To 59 Step lMinuteStep
oCMB.AddItem Format(lHour, "00") & ":" & Format(lMin, "00")
Next lMin
Next lHour
oCMB.ListIndex = 0
End Sub
-
Jun 19th, 2017, 08:28 AM
#4
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
Originally Posted by Arnoutdv
Code:
Private Sub Command1_Click()
AddTimeSlots Combo1, 60
End Sub
Private Sub Command2_Click()
AddTimeSlots Combo1, 30
End Sub
Private Sub Command3_Click()
AddTimeSlots Combo1, 15
End Sub
Private Sub AddTimeSlots(oCMB As ComboBox, ByVal lMinuteStep As Long)
Dim lHour As Long, lMin As Long
oCMB.Clear
For lHour = 0 To 23
For lMin = 0 To 59 Step lMinuteStep
oCMB.AddItem Format(lHour, "00") & ":" & Format(lMin, "00")
Next lMin
Next lHour
oCMB.ListIndex = 0
End Sub
tnk you my friend
the combo is array
DtDay(1).AddItem
DtDay(2).AddItem
-
Jun 19th, 2017, 08:38 AM
#5
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
Originally Posted by Arnoutdv
You can use some some basic loops for this.
Sample for the hours only
Code:
Dim lHour As Long
For lHour = 0 To 23
dtDay(0).AddItem = Format(lHour, "00") & ":00"
Next lHour
See if you can use this sample to create a slightly more advanced version to add half hours or quarter hours.
this shows each hour
9:00
10:00
i need the combo to display
9:00
9:15
9:30
9:45
and so on until 23:45
-
Jun 19th, 2017, 08:53 AM
#6
Re: how do i add to an array comboxes strings?
Or this brute force method with Strings:
Code:
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim t1 As String
Dim t2 As Integer
t1 = "05"
t2 = "00"
For j = 0 To 23
If CInt(t1) < 23 Then
t1 = CStr(CInt(t1) + 1)
dtDay(1).AddItem t1 & ":00"
For i = 1 To 3
t2 = CStr(CInt(t2) + 15)
dtDay(1).AddItem t1 & ":" & t2
Next i
t2 = "00"
End If
Next j
dtDay(1).ListIndex = 0
End Sub
-
Jun 19th, 2017, 08:59 AM
#7
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
Originally Posted by SamOscarBrown
Or this brute force method with Strings:
Code:
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim t1 As String
Dim t2 As Integer
t1 = "05"
t2 = "00"
For j = 0 To 23
If CInt(t1) < 23 Then
t1 = CStr(CInt(t1) + 1)
dtDay(1).AddItem t1 & ":00"
For i = 1 To 3
t2 = CStr(CInt(t2) + 15)
dtDay(1).AddItem t1 & ":" & t2
Next i
t2 = "00"
End If
Next j
dtDay(1).ListIndex = 0
End Sub
hey sami tnx amigo
that did the trick
-
Jun 19th, 2017, 09:04 AM
#8
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
hey sami
it dosnt show the full hour
it skipps it
09:15
09:30
09:45 >> here dosnt show after 10:00
10:15
-
Jun 19th, 2017, 09:12 AM
#9
Re: how do i add to an array comboxes strings?
Have you tried post #3?
Code:
AddTimeSlots dtDay(1), 60
AddTimeSlots dtDay(2), 30
AddTimeSlots dtDay(3), 15
-
Jun 19th, 2017, 09:21 AM
#10
Re: how do i add to an array comboxes strings?
Yes it does....did you copy-paste?
-
Jun 19th, 2017, 09:31 AM
#11
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
Originally Posted by Arnoutdv
Have you tried post #3?
Code:
AddTimeSlots dtDay(1), 60
AddTimeSlots dtDay(2), 30
AddTimeSlots dtDay(3), 15
i get type mismatch
-
Jun 19th, 2017, 10:30 AM
#12
Re: how do i add to an array comboxes strings?
Is dtDay() an array of ComboBoxes?
-
Jun 19th, 2017, 12:38 PM
#13
Re: how do i add to an array comboxes strings?
Salsa
Sorry, but I've gotta go with Sam on this one.
My combox is named Combo1.
Code:
Dim i As Integer
Dim j As Integer
Dim t1 As String
Dim t2 As Integer
t1 = "05"
t2 = "00"
With Combo1
For j = 9 To 13
If CInt(t1) < 23 Then
t1 = CStr(CInt(t1) + 1)
.AddItem t1 & ":00"
For i = 1 To 3
t2 = CStr(CInt(t2) + 15)
txt = txt & vbCrLf
.AddItem t1 & ":" & t2
Next i
t2 = "00"
End If
Next j
End With
Not as many as Sam's, but no "skipped" interval ..
.. and scrolling down produces
Spoo
-
Jun 19th, 2017, 01:03 PM
#14
Re: how do i add to an array comboxes strings?
Salsa
BTW, here is similar for ComboBox array
Code:
For a = 0 To 1
t1 = "05"
t2 = "00"
With Combo2(a)
For jj = 9 To 13
If CInt(t1) < 23 Then
t1 = CStr(CInt(t1) + 1)
.AddItem t1 & ":00"
For i = 1 To 3
t2 = CStr(CInt(t2) + 15)
txt = txt & vbCrLf
.AddItem t1 & ":" & t2
Next i
t2 = "00"
End If
Next jj
End With
Next a
Spoo
-
Jun 19th, 2017, 01:24 PM
#15
Re: how do i add to an array comboxes strings?
just because...
Code:
Dim x As Single
For x = 6 To 23.75 Step 0.25
Debug.Print Int(x) & ":" & Format((x - Int(x)) * 60, "00")
Next
-
Jun 19th, 2017, 03:00 PM
#16
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
Originally Posted by LaVolpe
just because...
Code:
Dim x As Single
For x = 6 To 23.75 Step 0.25
Debug.Print Int(x) & ":" & Format((x - Int(x)) * 60, "00")
Next
DtDay(1).AddItem???
hello sir long time good to see you tnk you
-
Jun 19th, 2017, 03:01 PM
#17
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
Originally Posted by Arnoutdv
Is dtDay() an array of ComboBoxes?
yes it is
-
Jun 19th, 2017, 05:23 PM
#18
Re: how do i add to an array comboxes strings?
Originally Posted by salsa31
DtDay(1).AddItem???
hello sir long time good to see you tnk you
Think you might have been able to answer that yourself:
Code:
Dim x As Single
For x = 6 To 23.75 Step 0.25
DtDAy(1).AddItem Int(x) & ":" & Format((x - Int(x)) * 60, "00")
Next
-
Jun 19th, 2017, 05:34 PM
#19
Re: how do i add to an array comboxes strings?
BOY, Lavolpe!, that was simple! (No, I am not calling you 'boy'!!!)
Sure would be nice to have a grasp of the language like you do....
-
Jun 19th, 2017, 08:32 PM
#20
Re: how do i add to an array comboxes strings?
Also if it is an array and you want to populate multiple combos with the same data then do not use
DtDAy(1)
Instead use a loop
Code:
Dim x As Single, Y as Integer
For Y=1 to 10
For x = 6 To 23.75 Step 0.25
DtDAy(Y).AddItem Int(x) & ":" & Format((x - Int(x)) * 60, "00")
Next
Next
That would populate 10 combo boxes with the same data assuming that 10 or more exist and have the indexes of 1 through 10
-
Jun 19th, 2017, 09:13 PM
#21
Re: how do i add to an array comboxes strings?
Be careful with those floating point loop indexes though. You can get some funny stuff if you're not careful. The fraction 0.25 is going to go to binary fairly cleanly. However, what if we wanted thirds?
Take a look at the following two examples:
Code:
Private Sub Command1_Click()
Dim n As Single
For n = 1! To 8!/3! Step 1!/3!
Debug.Print n
Next n
End Sub
... versus ...
Code:
Private Sub Command1_Click()
Dim n As Single
For n = 1! To 7!/3! Step 1!/3!
Debug.Print n
Next n
End Sub
Now, in the first one, 8/3 = 2.666... and everything runs as expected.
However, in the second one, 7/3 = 2.333... but we never get to that number. The loop stops executing when n = 2.
I'll let y'all ponder why that is. It's all about equality (and inequality) in binary.
Best Regards,
Elroy
EDIT1: Just for the purists, the loop stops reporting when n = 2. As is the case with all loops, n will be incremented by the step one more time once the code falls out of the loop.
Last edited by Elroy; Jun 19th, 2017 at 09:20 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 19th, 2017, 09:19 PM
#22
Re: how do i add to an array comboxes strings?
Elroy, granted. However, since the request for quarter hour increments, knew that wouldn't be a problem which is why the loop is an easy choice.
-
Jun 19th, 2017, 09:24 PM
#23
Re: how do i add to an array comboxes strings?
---
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 19th, 2017, 10:29 PM
#24
Re: how do i add to an array comboxes strings?
I'd do it with Date-Variables (adding them up with the Interval in question)...
Quite flexible compared to the other routines - and the Parameters can be passed-in as Strings,
which are a bit more readable then (basically the same format as the later expected output).
Code:
Option Explicit
Private Sub Form_Load()
FillTimeSlots List1, "23:45", "0:15", "0:05" 'to test "crossing the midnight point"
FillTimeSlots Combo1, "6:45", "23:45", "0:15"
End Sub
Private Sub FillTimeSlots(Lst, ByVal tStart As Date, ByVal tEnd As Date, ByVal tDelta As Date, Optional ByVal sFmt As String = "hh:mm")
Lst.Clear
If tEnd < tStart Then tEnd = DateAdd("d", 1, tEnd) 'just in case we "go over midnight"
Do: Lst.AddItem Format$(tStart, sFmt)
tStart = tStart + tDelta
Loop Until tStart > DateAdd("s", 1, tEnd)
End Sub
Olaf
-
Jun 20th, 2017, 12:11 AM
#25
Thread Starter
Enjoy the moment
Re: how do i add to an array comboxes strings?
thank you very much all of you
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
|