Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Start value listbox

On a form I have 2 (as far as I can see exactly the same) ListBoxes. I fill
both ListBoxes using .AddItem with dates from today up to December 31 of this
year. For both ListBoxes I set the .ListIndex to 0. When I display the values
of both the ListBoxes in a MsgBox, I only see one (the second) value. Anyone
any idea what can be the cause of this?

I tried to force the ListBox to have a value with .LisBox.Value = , but that
did not help.

Many thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Start value listbox

It helps to post the relavent code.

"Henk" wrote:

On a form I have 2 (as far as I can see exactly the same) ListBoxes. I fill
both ListBoxes using .AddItem with dates from today up to December 31 of this
year. For both ListBoxes I set the .ListIndex to 0. When I display the values
of both the ListBoxes in a MsgBox, I only see one (the second) value. Anyone
any idea what can be the cause of this?

I tried to force the ListBox to have a value with .LisBox.Value = , but that
did not help.

Many thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Start value listbox

This is the code :

With BlockDay

.BlockDayStartDate.Clear
.BlockDayEndDate.Clear
Today = Sheets("ResAlloqBase").Range("TodaysDate").Value
For x = 1 To 366
DayNumber = Weekday(Today)
Select Case DayNumber
Case Is = 1
TodaysDay = "Sunday"
Case Is = 2
TodaysDay = "Monday"
Case Is = 3
TodaysDay = "Tuesday"
Case Is = 4
TodaysDay = "Wednesday"
Case Is = 5
TodaysDay = "Thursday"
Case Is = 6
TodaysDay = "Friday"
Case Is = 7
TodaysDay = "Saturday"
End Select

.BlockDayStartDate.AddItem (Today & " " & TodaysDay)
.BlockDayEndDate.AddItem (Today & " " & TodaysDay)

Today = Today + 1

If Month(Today) = 12 And Day(Today) = 31 Then
x = 365
End If

Next x

.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
.BlockDayMondays.Value = True
.BlockDayTuesdays.Value = True
.BlockDayWednesdays.Value = True
.BlockDayThursdays.Value = True
.BlockDayFridays.Value = True
.BlockDaySaturdays.Value = True
.BlockDaySundays.Value = True

.BlockDayBlockDay.Value = True

MsgBox(.BlockDayStartDate & " " & .BlocDayEndDate)

.Show

End With

"JLGWhiz" wrote:

It helps to post the relavent code.

"Henk" wrote:

On a form I have 2 (as far as I can see exactly the same) ListBoxes. I fill
both ListBoxes using .AddItem with dates from today up to December 31 of this
year. For both ListBoxes I set the .ListIndex to 0. When I display the values
of both the ListBoxes in a MsgBox, I only see one (the second) value. Anyone
any idea what can be the cause of this?

I tried to force the ListBox to have a value with .LisBox.Value = , but that
did not help.

Many thanks in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Start value listbox

I put a couple of listboxes on a small userform and used this code:

Option Explicit
Private Sub UserForm_Initialize()
Dim dCtr As Long
Dim StartDate As Date

StartDate = Date

For dCtr = StartDate To DateSerial(Year(StartDate), 12, 31)
Me.ListBox1.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Me.ListBox2.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Next dCtr

End Sub



Henk wrote:

This is the code :

With BlockDay

.BlockDayStartDate.Clear
.BlockDayEndDate.Clear
Today = Sheets("ResAlloqBase").Range("TodaysDate").Value
For x = 1 To 366
DayNumber = Weekday(Today)
Select Case DayNumber
Case Is = 1
TodaysDay = "Sunday"
Case Is = 2
TodaysDay = "Monday"
Case Is = 3
TodaysDay = "Tuesday"
Case Is = 4
TodaysDay = "Wednesday"
Case Is = 5
TodaysDay = "Thursday"
Case Is = 6
TodaysDay = "Friday"
Case Is = 7
TodaysDay = "Saturday"
End Select

.BlockDayStartDate.AddItem (Today & " " & TodaysDay)
.BlockDayEndDate.AddItem (Today & " " & TodaysDay)

Today = Today + 1

If Month(Today) = 12 And Day(Today) = 31 Then
x = 365
End If

Next x

.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
.BlockDayMondays.Value = True
.BlockDayTuesdays.Value = True
.BlockDayWednesdays.Value = True
.BlockDayThursdays.Value = True
.BlockDayFridays.Value = True
.BlockDaySaturdays.Value = True
.BlockDaySundays.Value = True

.BlockDayBlockDay.Value = True

MsgBox(.BlockDayStartDate & " " & .BlocDayEndDate)

.Show

End With

"JLGWhiz" wrote:

It helps to post the relavent code.

"Henk" wrote:

On a form I have 2 (as far as I can see exactly the same) ListBoxes. I fill
both ListBoxes using .AddItem with dates from today up to December 31 of this
year. For both ListBoxes I set the .ListIndex to 0. When I display the values
of both the ListBoxes in a MsgBox, I only see one (the second) value. Anyone
any idea what can be the cause of this?

I tried to force the ListBox to have a value with .LisBox.Value = , but that
did not help.

Many thanks in advance.



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Start value listbox

Dave,

Thanks for your prompt answer. I started this code using date formats as
well, but since VB did not let me set a start value for the listbox, I
started to look for workarounds. I understand your code, and implemented it
in my code as herunder, but I still see only one date in my MsgBox..........

Dim dCtr As Long
Dim StartDate As Date

StartDate = Date

With BlockDay

For dCtr = StartDate To DateSerial(Year(StartDate), 12, 31)
.BlockDayStartDate.AddItem Format(dCtr, "mm/dd/yyyy dddd")
.BlockDayEndDate.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Next dCtr


.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
.BlockDayMondays.Value = True
.BlockDayTuesdays.Value = True
.BlockDayWednesdays.Value = True
.BlockDayThursdays.Value = True
.BlockDayFridays.Value = True
.BlockDaySaturdays.Value = True
.BlockDaySundays.Value = True

.BlockDayBlockDay.Value = True

MsgBox(.BlockDayStartDate & " " & .BlockDayEndDate)

.Show

End With


"Dave Peterson" wrote:

I put a couple of listboxes on a small userform and used this code:

Option Explicit
Private Sub UserForm_Initialize()
Dim dCtr As Long
Dim StartDate As Date

StartDate = Date

For dCtr = StartDate To DateSerial(Year(StartDate), 12, 31)
Me.ListBox1.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Me.ListBox2.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Next dCtr

End Sub



Henk wrote:

This is the code :

With BlockDay

.BlockDayStartDate.Clear
.BlockDayEndDate.Clear
Today = Sheets("ResAlloqBase").Range("TodaysDate").Value
For x = 1 To 366
DayNumber = Weekday(Today)
Select Case DayNumber
Case Is = 1
TodaysDay = "Sunday"
Case Is = 2
TodaysDay = "Monday"
Case Is = 3
TodaysDay = "Tuesday"
Case Is = 4
TodaysDay = "Wednesday"
Case Is = 5
TodaysDay = "Thursday"
Case Is = 6
TodaysDay = "Friday"
Case Is = 7
TodaysDay = "Saturday"
End Select

.BlockDayStartDate.AddItem (Today & " " & TodaysDay)
.BlockDayEndDate.AddItem (Today & " " & TodaysDay)

Today = Today + 1

If Month(Today) = 12 And Day(Today) = 31 Then
x = 365
End If

Next x

.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
.BlockDayMondays.Value = True
.BlockDayTuesdays.Value = True
.BlockDayWednesdays.Value = True
.BlockDayThursdays.Value = True
.BlockDayFridays.Value = True
.BlockDaySaturdays.Value = True
.BlockDaySundays.Value = True

.BlockDayBlockDay.Value = True

MsgBox(.BlockDayStartDate & " " & .BlocDayEndDate)

.Show

End With

"JLGWhiz" wrote:

It helps to post the relavent code.

"Henk" wrote:

On a form I have 2 (as far as I can see exactly the same) ListBoxes. I fill
both ListBoxes using .AddItem with dates from today up to December 31 of this
year. For both ListBoxes I set the .ListIndex to 0. When I display the values
of both the ListBoxes in a MsgBox, I only see one (the second) value. Anyone
any idea what can be the cause of this?

I tried to force the ListBox to have a value with .LisBox.Value = , but that
did not help.

Many thanks in advance.



--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Start value listbox

I think it's a timing issue.

When the Userform was shown, both listboxes had the top item selected.

Option Explicit
Private Sub UserForm_Click()
With Me
MsgBox "Start: " & .BlockDayStartDate.Value _
& "--End: " & .BlockDayEndDate.Value
End With
End Sub
Private Sub UserForm_Initialize()
Dim dCtr As Long
Dim StartDate As Date

StartDate = Date

With Me
For dCtr = StartDate To DateSerial(Year(StartDate), 12, 31)
.BlockDayStartDate.AddItem Format(dCtr, "mm/dd/yyyy dddd")
.BlockDayEndDate.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Next dCtr

.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
End With
End Sub

Henk wrote:

Dave,

Thanks for your prompt answer. I started this code using date formats as
well, but since VB did not let me set a start value for the listbox, I
started to look for workarounds. I understand your code, and implemented it
in my code as herunder, but I still see only one date in my MsgBox..........

Dim dCtr As Long
Dim StartDate As Date

StartDate = Date

With BlockDay

For dCtr = StartDate To DateSerial(Year(StartDate), 12, 31)
.BlockDayStartDate.AddItem Format(dCtr, "mm/dd/yyyy dddd")
.BlockDayEndDate.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Next dCtr


.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
.BlockDayMondays.Value = True
.BlockDayTuesdays.Value = True
.BlockDayWednesdays.Value = True
.BlockDayThursdays.Value = True
.BlockDayFridays.Value = True
.BlockDaySaturdays.Value = True
.BlockDaySundays.Value = True

.BlockDayBlockDay.Value = True

MsgBox(.BlockDayStartDate & " " & .BlockDayEndDate)

.Show

End With


"Dave Peterson" wrote:

I put a couple of listboxes on a small userform and used this code:

Option Explicit
Private Sub UserForm_Initialize()
Dim dCtr As Long
Dim StartDate As Date

StartDate = Date

For dCtr = StartDate To DateSerial(Year(StartDate), 12, 31)
Me.ListBox1.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Me.ListBox2.AddItem Format(dCtr, "mm/dd/yyyy dddd")
Next dCtr

End Sub



Henk wrote:

This is the code :

With BlockDay

.BlockDayStartDate.Clear
.BlockDayEndDate.Clear
Today = Sheets("ResAlloqBase").Range("TodaysDate").Value
For x = 1 To 366
DayNumber = Weekday(Today)
Select Case DayNumber
Case Is = 1
TodaysDay = "Sunday"
Case Is = 2
TodaysDay = "Monday"
Case Is = 3
TodaysDay = "Tuesday"
Case Is = 4
TodaysDay = "Wednesday"
Case Is = 5
TodaysDay = "Thursday"
Case Is = 6
TodaysDay = "Friday"
Case Is = 7
TodaysDay = "Saturday"
End Select

.BlockDayStartDate.AddItem (Today & " " & TodaysDay)
.BlockDayEndDate.AddItem (Today & " " & TodaysDay)

Today = Today + 1

If Month(Today) = 12 And Day(Today) = 31 Then
x = 365
End If

Next x

.BlockDayStartDate.ListIndex = 0
.BlockDayEndDate.ListIndex = 0
.BlockDayMondays.Value = True
.BlockDayTuesdays.Value = True
.BlockDayWednesdays.Value = True
.BlockDayThursdays.Value = True
.BlockDayFridays.Value = True
.BlockDaySaturdays.Value = True
.BlockDaySundays.Value = True

.BlockDayBlockDay.Value = True

MsgBox(.BlockDayStartDate & " " & .BlocDayEndDate)

.Show

End With

"JLGWhiz" wrote:

It helps to post the relavent code.

"Henk" wrote:

On a form I have 2 (as far as I can see exactly the same) ListBoxes. I fill
both ListBoxes using .AddItem with dates from today up to December 31 of this
year. For both ListBoxes I set the .ListIndex to 0. When I display the values
of both the ListBoxes in a MsgBox, I only see one (the second) value. Anyone
any idea what can be the cause of this?

I tried to force the ListBox to have a value with .LisBox.Value = , but that
did not help.

Many thanks in advance.



--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
start learning Excel/VBA, where to start from? Any online video lectures? cfman Excel Programming 8 September 29th 06 10:40 AM
OT :Start your own online business today !start making dollars [email protected] Excel Discussion (Misc queries) 0 May 6th 06 09:29 PM
VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox) modjoe23 Excel Programming 3 August 18th 05 02:35 PM
Start spreadsheet with WinXP start Gordon Gradwell Excel Worksheet Functions 1 July 13th 05 11:35 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 06:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"