Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Multiple selections within the same string Post Reply Post New Topic
<< Prev  Page  of 2
Author Message
Dreaming
Newbie
Newbie
Avatar

Joined: 26 Jan 2010
Location: Canada
Online Status: Offline
Posts: 17
Quote Dreaming Replybullet Posted: 03 Feb 2010 at 9:00am
Yes, the source data format is:
English | French<cr>
English | French<cr>
.
.
.
English | French<cr>
English | French<cr(?)>
There is a random number of English/French pairs, the last one possibly ending in a carriage return.


As for writing the code in Crystal, all of this data is stored in a memo field and the version of CR I have access to is 8.5, so I can't call this field directly.  It's why I've been spinning my wheels with SQL for the past few days, trying to extract it into a format I can manipulate on the report.  I had initially used CAST() in an SQL expression to grab it, but the data was being truncated and I was losing half of it. 

The data in the memo field will nearly always exceed 255 characters, so I've been trying to get SQL to pull it out in logical chunks, namely one English/French pairing at a time.  The tricky part has been the fact that the SQL expression editor throws syntax errors when I use the functions it supplies natively, but compiles fine when I use an alternative function.

For instance, LENGHT() is supplied by the editor and turns blue when typed in so I know it's being recognized, however, it causes a syntax error.  The same line of code using LEN() works perfectly, but the function doesn't light up in blue in the editor, so it appears to not be recognized.  For a novice coder trying to learn the basics of the language, it's enough to induce fits.

Anyway, is there a way that I don't know about to access the data in that memo field from within CR, or is SQL still really the only way?
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 03 Feb 2010 at 9:20am
I haven't used 8.5 in a while, so the old name might be length().  I am using XI and it recognizes len().
 
As far as getting the data to CR, I wish you luck.  Long strings are problematic.
IP IP Logged
Dreaming
Newbie
Newbie
Avatar

Joined: 26 Jan 2010
Location: Canada
Online Status: Offline
Posts: 17
Quote Dreaming Replybullet Posted: 03 Feb 2010 at 11:42am
Thanks, I can use some luck.  But I did find out exactly what database and version (SQL Server 2000) we're using so hopefully that will let me weed out the syntax errors.  Hopefully I'll be able to move on and try some of the suggestions that have been kindly offered for the CR part, once I can strip my data from that memo field.

Much appreciated.
IP IP Logged
Dreaming
Newbie
Newbie
Avatar

Joined: 26 Jan 2010
Location: Canada
Online Status: Offline
Posts: 17
Quote Dreaming Replybullet Posted: 05 Feb 2010 at 7:04am
OK, so I think I've hit on a way of getting my memo data out by splitting it into four smaller sections, no more than 255 characters.  Now I'm trying to write the formula to put it all together. 

Based on the suggestion above in the thread (thanks again), I think I have the logic correctly set out, but am encountering a few syntax errors that I can't figure out.  When I solve one, another rises to take it's place, so I might be doing something wrong elsewhere.

This current one is giving me an "a string is required here." error between an ELSE and an IF.  I really have no idea why anything should appear there, let alone a string.  No Formula samples I've seen have ever put anything between an ELSE IF statement.

Any ideas?

Here's the code.  The syntax error location is marked with a red *.  Oh, and any feedback on the general structure would be welcome.  It's my first stab at CR so I'm sure I could benefit from the insights of experience.


LOCAL NumberVar ParseCnt := 1;   // Counter for loop to pull extracted characters sequentially
LOCAL NumberVar ExtStrCnt := 1;  // Counter for loop to pull extracted strings sequentially
LOCAL NumberVar Toggle := 1;     // Toggles between language to write (1=English, 2=French)
LOCAL StringVar EString := "";   // New English string built from parsed characters
LOCAL StringVar SString := "";   // Current extracted source string
LOCAL StringVar PullChar := "";  // Current extracted character

WHILE ExtStrCnt < 5 DO // Begin loop to call string fragments                          
(
  IF ExtStrCnt = 1 THEN //Begin loop to select correct string fragment
    SString := {%Pull_1}
  ELSE IF ExtStrCnt = 2 THEN
    SString := {%Pull_2}
  ELSE IF ExtStrCnt = 3 THEN
    SString := {%Pull_3}
  ELSE
    SString := {%Pull_4}; // End loop to select correct string fragment

  WHILE ParseCnt <> (LENGTH(SString) + 1) DO // Begin loop to extract single characters
  (
    PullChar := Mid(SString,ParseCnt,1);
    IF PullChar <> "|" AND Toggle = 1 THEN // Begin character evaluation and English string building
      EString := EString & PullChar
    ELSE *IF PullChar = "|" AND Toggle = 1 THEN 
      ( 
      EString := EString & PullChar;
      Toggle := 2
      )
    ELSE
      Toggle := 1; // End character evaluation and English string building 
    ParseCnt := ParseCnt + 1;
  ); // End loop to extract single characters

  ExtStrCnt := ExtStrCnt + 1
); // End loop to call string fragments

ToText(EString)


IP IP Logged
<< Prev  Page  of 2
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