Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default len of item in an array

Is it possible to check the length of each item in a specific field in an
array? Is so, how?

I am building an array but I want to check the length of a specific field
for each item in the array. For example, each "record" in my array has 4
fields. I want to check the length of the first field in each "record". If
it is greater than 0, I will do one action and if it is zero I will do
another action.

I'm using this in an edit to be verify the user has not selected a record
where the first field is blank.

Thanks for the help.

--
JT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default len of item in an array

JT,

Sub JTArrayTest()
Dim i As Integer
Dim j As Integer
Dim myArr(1 To 2, 1 To 4) As String
Dim NotEmpty As String

For i = LBound(myArr, 1) To UBound(myArr, 1)
For j = LBound(myArr, 2) To UBound(myArr, 2)
myArr(i, j) = "String " & i & " " & j
Next j
Next i

myArr(1, 1) = ""

For i = LBound(myArr, 1) To UBound(myArr, 1)
For j = LBound(myArr, 2) To UBound(myArr, 2)
If Len(myArr(i, j)) = 0 Then
MsgBox "array element " & i & " " & j & " is length 0"
Else
NotEmpty = NotEmpty & vbLf & i & " " & j
End If
Next j
Next i

MsgBox "Not Empty we" & vbLf & NotEmpty

End Sub

HTH,
Bernie
MS Excel MVP


"JT" wrote in message
...
Is it possible to check the length of each item in a specific field in an
array? Is so, how?

I am building an array but I want to check the length of a specific field
for each item in the array. For example, each "record" in my array has 4
fields. I want to check the length of the first field in each "record". If
it is greater than 0, I will do one action and if it is zero I will do
another action.

I'm using this in an edit to be verify the user has not selected a record
where the first field is blank.

Thanks for the help.

--
JT



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default len of item in an array

See VBA help for UBound

UBound Function


Returns a Long containing the largest available subscript for the indicated
dimension of an array.

Syntax

UBound(arrayname[, dimension])

The UBound function syntax has these parts:

Part Description
arrayname Required. Name of the array variable; follows standard variable
naming conventions.
dimension Optional; Variant (Long). Whole number indicating which
dimension's upper bound is returned. Use 1 for the first dimension, 2 for the
second, and so on. If dimension is omitted, 1 is assumed.



Remarks

The UBound function is used with the LBound function to determine the size
of an array. Use the LBound function to find the lower limit of an array
dimension.

UBound returns the following values for an array with these dimensions:

Dim A(1 To 100, 0 To 3, -3 To 4)

Statement Return Value
UBound(A, 1) 100
UBound(A, 2) 3
UBound(A, 3) 4



"JT" wrote:

Is it possible to check the length of each item in a specific field in an
array? Is so, how?

I am building an array but I want to check the length of a specific field
for each item in the array. For example, each "record" in my array has 4
fields. I want to check the length of the first field in each "record". If
it is greater than 0, I will do one action and if it is zero I will do
another action.

I'm using this in an edit to be verify the user has not selected a record
where the first field is blank.

Thanks for the help.

--
JT

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default len of item in an array

Assuming your field delimiter is a comma and that your array is named Record

LenFirstField = Instr(Record(X), ",") - 1

where X is the loop counter (record number). If you need this to be more
general, here is how to

LenOfField_F = Len(Split(Record(X), ",")(F - 1))

where F is 1 for the first field, 2 for the second, etc. and X is as defined
above.

Rick


Is it possible to check the length of each item in a specific field in an
array? Is so, how?

I am building an array but I want to check the length of a specific field
for each item in the array. For example, each "record" in my array has 4
fields. I want to check the length of the first field in each "record".
If
it is greater than 0, I will do one action and if it is zero I will do
another action.

I'm using this in an edit to be verify the user has not selected a record
where the first field is blank.

Thanks for the help.

--
JT


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
Second item in list using array CeciliaPDX Excel Worksheet Functions 4 March 10th 09 06:14 PM
Getting a the position of a single item in an array pinkfloydfan Excel Programming 5 July 23rd 07 09:05 PM
Fastest way to find item in an array. WhytheQ Excel Programming 7 May 24th 06 11:12 PM
Lookup Multiple Occurrence Of Item In Array John Sharkey Excel Programming 0 October 29th 04 08:32 PM
does an item belong to an array? wcc Excel Programming 4 October 21st 04 08:46 AM


All times are GMT +1. The time now is 04:12 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"