Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Is the array empty?

Excel 2002, WinXP
I display a UserForm with a Listbox (set to multi-select) and ask the user
to select the names he wishes. I then use the procedure that John
Walkenbach has in his book to build an array of the selected names. All
works well if the user selects at least one name.
There is a real possibility that the user will select no names, in which
case the array will contain no names. I need to trap that situation.
How can I trap the fact that no names were selected or that the array has no
members? Thanks for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Is the array empty?

Otto,

Perhaps:

If Not IsEmpty(yourvarr(1)) Then

which tests for an initial array value.

Regards.

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I display a UserForm with a Listbox (set to multi-select) and ask the user
to select the names he wishes. I then use the procedure that John
Walkenbach has in his book to build an array of the selected names. All
works well if the user selects at least one name.
There is a real possibility that the user will select no names, in

which
case the array will contain no names. I need to trap that situation.
How can I trap the fact that no names were selected or that the array has

no
members? Thanks for your help. Otto




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.703 / Virus Database: 459 - Release Date: 10/06/2004


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Is the array empty?

Sub test()
Dim arr() As String, bln As Boolean, i As Long

' ReDim arr(1)

On Error Resume Next
i = LBound(arr): bln = Not (Err.Number = 9)
On Error GoTo 0

MsgBox bln
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I display a UserForm with a Listbox (set to multi-select) and ask the user
to select the names he wishes. I then use the procedure that John
Walkenbach has in his book to build an array of the selected names. All
works well if the user selects at least one name.
There is a real possibility that the user will select no names, in

which
case the array will contain no names. I need to trap that situation.
How can I trap the fact that no names were selected or that the array has

no
members? Thanks for your help. Otto




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Is the array empty?

I'd just count:

Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
Dim SelectedCtr As Long
Dim myNames() As String
SelectedCtr = 0
With Me.ListBox1
For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
SelectedCtr = SelectedCtr + 1
ReDim Preserve myNames(1 To SelectedCtr)
myNames(SelectedCtr) = .List(iCtr)
End If
Next iCtr
End With

MsgBox SelectedCtr
End Sub

Private Sub UserForm_Initialize()

Dim iCtr As Long
For iCtr = 1 To 10
Me.ListBox1.AddItem ("asdf" & iCtr)
Next iCtr
Me.ListBox1.MultiSelect = fmMultiSelectMulti

End Sub



Otto Moehrbach wrote:

Excel 2002, WinXP
I display a UserForm with a Listbox (set to multi-select) and ask the user
to select the names he wishes. I then use the procedure that John
Walkenbach has in his book to build an array of the selected names. All
works well if the user selects at least one name.
There is a real possibility that the user will select no names, in which
case the array will contain no names. I need to trap that situation.
How can I trap the fact that no names were selected or that the array has no
members? Thanks for your help. Otto


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Is the array empty?

Stuart, Rob, Dave
Thanks for your help. That gave me what I needed. Dave, your
suggestion was right on because I was counting anyway in the building of the
array, so why didn't I think of that? Thanks again. Otto
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I display a UserForm with a Listbox (set to multi-select) and ask the user
to select the names he wishes. I then use the procedure that John
Walkenbach has in his book to build an array of the selected names. All
works well if the user selects at least one name.
There is a real possibility that the user will select no names, in

which
case the array will contain no names. I need to trap that situation.
How can I trap the fact that no names were selected or that the array has

no
members? Thanks for your help. Otto






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
in excel..:can't empty clip are" but already empty Alan Gauthier Excel Discussion (Misc queries) 0 February 10th 06 08:02 PM
Excel - Autom. Filter "Empty / Non Empty cells" should come first Rom Excel Discussion (Misc queries) 0 August 10th 05 04:32 PM
Is Array Empty | Boolean Answer verizon Excel Programming 2 May 4th 04 02:53 PM
Differentiate between "" and Empty in array elements. RB Smissaert Excel Programming 3 January 2nd 04 09:01 PM
Can blank cells created using empty Double-Quotes not be empty?? JohnI in Brisbane Excel Programming 6 September 7th 03 11:22 PM


All times are GMT +1. The time now is 09:43 AM.

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

About Us

"It's about Microsoft Excel"