Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Working with Arrays, pasing from function to function

First let me explain the big picture. I'm trying to make a function to look
at list of zipcodes. They are listed in this format "Augusta GA" "298,
308-310". City name in one cell and the zips in another. I want the function
to look at these entries and tell me if a certain zipcode is in the list.
For example if I enter a zip of 309 it should return Augusta GA.
Now, I'm at the point where I have made a function to fill the range into an
array. The functions leaves me with an array of (308, 309, 310).
I have two questions. First of all is the best way to approach this?
Second if so, what do I need to know about passing arrays from one function
to another.

Thanks
Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Working with Arrays, pasing from function to function

Mike,

Here is an example of what I think you are doing

Function ZipWhere(Zip)
Dim aryZips, aryAreas
Dim iPos As Long

ZipCodes aryZips, aryAreas
On Error Resume Next
iPos = Application.Match(Zip, aryZips, 0)
On Error GoTo 0
If iPos = 0 Then
ZipWhere = CVErr(xlErrNA)
Else
ZipWhere = aryAreas(iPos)
End If

End Function

Function ZipCodes(ByRef pZipCodes, ByRef pZipAreas)

'this is a simulation to load the array
pZipCodes = [{308,401,517}]
pZipAreas = [{"Atlanta GA","Austin TX","Birmingham AL"}]
'your code would be different here, but it
'would load the same arrays
End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"mikebres" wrote in message
...
First let me explain the big picture. I'm trying to make a function to

look
at list of zipcodes. They are listed in this format "Augusta GA" "298,
308-310". City name in one cell and the zips in another. I want the

function
to look at these entries and tell me if a certain zipcode is in the list.
For example if I enter a zip of 309 it should return Augusta GA.
Now, I'm at the point where I have made a function to fill the range into

an
array. The functions leaves me with an array of (308, 309, 310).
I have two questions. First of all is the best way to approach this?
Second if so, what do I need to know about passing arrays from one

function
to another.

Thanks
Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Working with Arrays, pasing from function to function

I see some interesting ideas in your code. But the starting point is a
little different. Instead of a list of arrays, its a list of string values
from a spreadsheet. Here is a small section of the list I am working with.
This is a list on an Excel spreadsheet:
AADC AUGUSTA GA 308 298, 308-309
AADC MACON GA 310 310, 312, 316-319, 398
AADC JACKSONVILLE FL 320 299, 304, 313-315, 320-323, 326, 344
AADC PENSACOLA FL 325 324, 325

Here is the function so far:
Function ZipRange(TString As String) As Boolean
Dim Hyph As Integer, cWord As Integer, i As Integer, arrSize As Integer
Dim tWord As String, cHyph As Integer, j As Integer
Dim tArray() As String, fArray() As String

'Check to see if there is range of numbers
Hyph = InStr(TString, "-")
If Hyph 0 Then
'Seperate the two ends of the range and fill in the middle
cHyph = CountCSWords(TString, "-")
If cHyph = 2 Then
tStart = (GetCSWord(TString, 1, "-"))
tEnd = (GetCSWord(TString, 2, "-"))
Else
MsgBox "Problem with hyphenated zips"
End If

arrSize = Val(tEnd) - Val(tStart) + 1
ReDim tArray(arrSize)
tArray(1) = (tStart)
For j = (Val(tStart) - Val(tStart) + 2) To (Val(tEnd) - Val(tStart))
+ 1
tArray(j) = Format(Val(tArray(j - 1)) + 1, "000")
Next j
'Each zip is now loaded in the array
End If

Stop
End Function

The idea was to break down the zip ranges into each seperate zip, then pass
that back to a parent function to create a complete list of individual zips.
For example I would pass this on to the parent functiion "310, 312, 316-319,
398". So I would start with: AADC MACON GA 310 310, 312, 316-319, 398
End with: AADC MACON GA 310 310, 312, 316, 317, 318, 319, 398

Thanks
Mike

"Bob Phillips" wrote:

Mike,

Here is an example of what I think you are doing

Function ZipWhere(Zip)
Dim aryZips, aryAreas
Dim iPos As Long

ZipCodes aryZips, aryAreas
On Error Resume Next
iPos = Application.Match(Zip, aryZips, 0)
On Error GoTo 0
If iPos = 0 Then
ZipWhere = CVErr(xlErrNA)
Else
ZipWhere = aryAreas(iPos)
End If

End Function

Function ZipCodes(ByRef pZipCodes, ByRef pZipAreas)

'this is a simulation to load the array
pZipCodes = [{308,401,517}]
pZipAreas = [{"Atlanta GA","Austin TX","Birmingham AL"}]
'your code would be different here, but it
'would load the same arrays
End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"mikebres" wrote in message
...
First let me explain the big picture. I'm trying to make a function to

look
at list of zipcodes. They are listed in this format "Augusta GA" "298,
308-310". City name in one cell and the zips in another. I want the

function
to look at these entries and tell me if a certain zipcode is in the list.
For example if I enter a zip of 309 it should return Augusta GA.
Now, I'm at the point where I have made a function to fill the range into

an
array. The functions leaves me with an array of (308, 309, 310).
I have two questions. First of all is the best way to approach this?
Second if so, what do I need to know about passing arrays from one

function
to another.

Thanks
Mike




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
ISBLANK function not working when cell is blank dut to function re mcmilja Excel Discussion (Misc queries) 9 May 7th 23 03:43 AM
Using function with Arrays matelot Excel Programming 3 March 19th 06 10:02 PM
Using arrays or range in IF function - HELP PLS MickJJ Excel Worksheet Functions 1 February 10th 06 05:43 PM
Arrays and Join Function Stefano Condotta Excel Programming 2 January 8th 06 11:20 PM
Help with a UDF Function using Arrays... Dennis G.[_2_] Excel Programming 2 December 27th 05 09:39 PM


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