|
-
May 26th, 2004, 10:36 AM
#1
Thread Starter
Junior Member
LISTBOX and multiple and variables ??
I have a form in XLS (2002) that has a listbox. In form_intialize () event 10 dates fill the list box (today +1 through 10).
User will select 4 dates, i am trying to store all 4 values selected in variables.
I know that it recognizes only the last selected but was hoping for a work around.
I have the selected being shown in Msgbox and then stored in myVariable, but when loops, overwrites last variable stored.
this is what i have:
Dim x As Integer
For x = 0 To lstDates.ListCount - 1
If lstDates.Selected(x) = True Then
MsgBox lstDates.List(x)
myVariable = lstDates.List(x)
End If
Next x
-
May 26th, 2004, 10:54 AM
#2
Here is an example I put together for you to demonstrate the logic.
VB Code:
Option Explicit
'Set the MultiSelect property of the listbox to "2 - Extended" manually.
Private myVariable As String
Private Sub Form_Initialize()
Dim i As Integer
lstDates.AddItem Date
For i = 1 To 10
lstDates.AddItem DateAdd("d", i, Date)
Next
End Sub
Private Sub cmdLoadVar_Click()
Dim x As Integer
For x = 0 To lstDates.ListCount - 1
If lstDates.Selected(x) = True Then
MsgBox lstDates.List(x)
myVariable = myVariable & lstDates.List(x) & "|"
End If
Next x
End Sub
Private Sub cmdReadVar_Click()
Dim arArray() As String
Dim i As Integer
Erase arArray
ReDim arArray(lstDates.ListCount - 1) As String
arArray = Split(myVariable, "|")
For i = 0 To UBound(arArray) - 1
MsgBox arArray(i)
Next
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 26th, 2004, 02:16 PM
#3
Thread Starter
Junior Member
Thanks for your reply.
I put in a msgbox after the line "myVariable = myVariable & lstDates.list(x) to see both dates selected returned.
(I deactivated the other msgbox in the line above).
I get 2 msgboxes, 1 with the first date i select, and 2ns with both dates selected. What is the code doing ?
not sure what the code in cmdreadVar () is soppose to do, does not do anything when clicked.
thanks again for your help
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
|