Print Page | Close Window

Outputting Split() Function

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=18387
Printed Date: 19 Apr 2024 at 10:50pm


Topic: Outputting Split() Function
Posted By: Siiig
Subject: Outputting Split() Function
Date Posted: 07 Jan 2013 at 10:53am
Sup People,

I'm working on sorting my records, and I've run into a group of records that have multiple pieces of information stored in them.

They are warehouse locations, and the field BinLocation is often expressed as "110,230". One location being 110 and the other being 230.

I'm trying to figure out how to split this information, and that has lead me to the "Split()" function. What I'm using is...

Split({BinLocation{,",")

The problem is, I don't know how to get the information out of that newly created array!

Anyone have a simpler solution to this, or could help me extract the info?



Replies:
Posted By: lockwelle
Date Posted: 08 Jan 2013 at 9:28am
local numbervar i;
for i := 0 to ubound(array) do(
  your code here
);
 
I'm pretty sure that is the syntax. Look at the For loop in CR help (that's how I learned)
 
or you could directly access the data
array[1];
 
I am not sure if CR starts the arrays at 0 or 1 (I'd lean toward 1, but I've been wrong before and would test it)
 
UBound or Upper (check CR help) will tell you the size of the array.
 
HTH
 


Posted By: Siiig
Date Posted: 09 Jan 2013 at 3:20am
Thanks for the response Lockwell!

Below is the code I've come up with...

Dim BinLoc1
Dim BinLoc2

Split({IM2_InventoryItemWhseDetl.BinLocation},",")

BinLoc1 = Array[1]

BinLoc2 = Array[2]

formula = BinLoc1


But I must be misunderstanding something about the Array[#] part of the function. Setting the Forumla = to Array[1] results in an error of "Formula cannot be an Array".

What I have listed above results in the message "The remaining text does not appear to be part of the formula." And it highlights everything after the first "Array"


Posted By: lockwelle
Date Posted: 09 Jan 2013 at 5:57am
hmm...I don't use the vb code too often, but what I would try:
Dim BinLoc1
Dim BinLoc2
Dim arr

arr = Split({IM2_InventoryItemWhseDetl.BinLocation},",")

BinLoc1 = CStr(arr[1])

'BinLoc2 = Array[2] comment out, since you are only returning the first value

formula = BinLoc1
 
if it was crystal syntax:
local stringvar array bins = Split({IM2_InventoryItemWhseDetl.BinLocation},",");
bins[1]
 
I think that you are missing the assignment to an array variable more than anything else.
 
HTH


Posted By: Sastry
Date Posted: 10 Jan 2013 at 12:28am
To add to HTH post..

you don't have to assign the value to a variable, you can use

Split({IM2_InventoryItemWhseDetl.BinLocation},",")[1]  // for first value and [2] will give you second value of your string.


-------------
Thanks,
Sastry


Posted By: lockwelle
Date Posted: 10 Jan 2013 at 6:17am
Sastry is correct, you can do that.
 
If you are only using 1 row of the split, that is probably fine...
if you want to use several rows, cutting down on the calls to Split should speed up the report processing, and if you the number of rows that are being output by split is variable, depending on what you are doing, putting the results in a variable that you can query again should speed things up.


Posted By: sbodell
Date Posted: 23 Apr 2014 at 1:10pm
suppose you have more, like about 100 items, but you don't know how many. How would you split that field? I saw something that appeared to work, but I can't get it to work

split(varName, "~")[recordnumber+1]


Posted By: lockwelle
Date Posted: 28 Apr 2014 at 4:46am
depends...if you only want 1 value out of x and you know what the value is you could iterate through the array like:

local stringvar arr := split({table.field}, "delimiter");
local numbervar x;
for x := 1 to ubound(arr) do (
if arr[x] = "some criteria" then
    do something
)

HTH



Print Page | Close Window