Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Outputting Split() Function Post Reply Post New Topic
Author Message
Siiig
Newbie
Newbie


Joined: 08 Nov 2012
Online Status: Offline
Posts: 4
Quote Siiig Replybullet Topic: Outputting Split() Function
    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?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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
 
IP IP Logged
Siiig
Newbie
Newbie


Joined: 08 Nov 2012
Online Status: Offline
Posts: 4
Quote Siiig Replybullet 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"
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet 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
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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.
IP IP Logged
sbodell
Newbie
Newbie


Joined: 13 Jul 2009
Online Status: Offline
Posts: 9
Quote sbodell Replybullet 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]
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.