Link to home
Start Free TrialLog in
Avatar of rhill52
rhill52

asked on

Problem VB scripting in Fast Reports ...

Hi All,

I realise I may not be in the right zone here, suggestions about that would be good.


I have what should be 3 simple OnBeforePrint data adjustments to make for a "Fast Report".

2 of them are simple String.Concat("sometext: ",DataFieldName) and they work perfectly

The 3rd should be just as simple, however ... below is what I have coded ...

REM -----------------------------------------------------------------------------------------
Private Sub Text18_BeforePrint(ByVal sender As object, ByVal e As EventArgs)
 DIM This As String
 DIM Current As String

 Current=String.Concat('*** ',Text18.Text)
 This="***Failed to populate***"

 IF Left(Current,5)="*** F" THEN
 This="Condition: ( ) Pass (X) Fail"
 END IF

 IF Left(Current,5)="*** P" THEN
 This="Condition: (X) Pass ( ) Fail"
 END IF

Text18.Text=String.Concat(String.Concat(Current," "),This)
 End Sub
REM -----------------------------------------------------

Both of the "IF" conditions fail!!!

this is what I get ...

*** Fail ***Failed to populate***
or
*** Pass ***Failed to populate***

I find this positively wierd, the Text object knows what the DataField contains and I can concat, no problem, as soon as I try to interrogate content, odd things happen!

Any thoughts would be much appreciated,
Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rhill52
rhill52

ASKER

Hi Chris, it is never blank, it is a DataBase field and it always contains:

"Pass " ,or, "Fail "
IN point of fact my premise was wrong anyway ... sorry about that.

Chris
Capital P and lower case f is this an issue?

Chris
I'm not aware of fast reports but for example does it support ucase

Assuming it does then try  the snippet

If not then how about:

 IF Left(Current,5)="*** F" or Left(Current,5)="*** f" THEN
...
 IF Left(Current,5)="*** P" or Left(Current,5)="*** p" THEN
...

Chris
IF UCASE(Left(Current,5))="*** F" THEN
 This="Condition: ( ) Pass (X) Fail"
 END IF

 IF UCASE(Left(Current,5))="*** P" THEN
 This="Condition: (X) Pass ( ) Fail"
 END IF

Open in new window

Avatar of rhill52

ASKER

I wish it was that simple :)

Originally, I had an "IF" "THEN" "ELSE" construct and it -always- populated the "ELSE" condition, the reason I broke it down as displayed above, was to definitively "prove" both of the "IF" conditions were failing.

I am also only bunging the "*** " in front as an excercise to show that I can alter alter the real data.

It is really wierd ...

It is almost as if the real database data is not being exposed until AFTER the BeforePrint event, this of course, would be silly ...
Avatar of rhill52

ASKER

*** Fail ***Failed to populate***
or
*** Pass ***Failed to populate***

one of the lines above, is what pops out of my proc/event and that is exactly what gets printed in the report, I have added the "*** " (as the first 4 chars) to the actual datafield, which, is always:

"Pass ", or, "Fail "

this is driving me nuts :(
Not clear if you have tested for the case?

If so then will a msgbox help understanding ...


Msgbox ">>>" & current & "<<<"

IF UCASE(Left(Current,5))="*** F" THEN
 This="Condition: ( ) Pass (X) Fail"
 END IF

 IF UCASE(Left(Current,5))="*** P" THEN
 This="Condition: (X) Pass ( ) Fail"
 END IF

Open in new window

Avatar of rhill52

ASKER

the actual datafield, is always:

"Pass ", or, "Fail "

I can see this when I browse the database content, "case" is not the issue.
Understood and if you want me to stop simply say so, I included a check on the setting in current and since the interface you are using is the VB one I was wondering if using a messagebox to display the actual value of current would help understanding ... did you try it?

Chris
Avatar of rhill52

ASKER

Fast Report scripting does not support MsgBox, but, I have included case coding for the sake of completeness.

This has not altered the behavior at all.
Okay, i am trying to help from a generic background rather than fast report specifically but when I did a search on Delphi for Fast report it showed msgbox as a valid object but I accept your experience that it is not.  Within that skills qualifier I simply cannot see what the problem is but my next guess is the assignment of current.

You are using single quotes at that line ... does it change if you use double quotes?

Current=String.Concat('*** ',Text18.Text)
to
Current=String.Concat("*** ",Text18.Text)

Chris
Avatar of rhill52

ASKER

Hi Chris, this is what I have now ...
--------------------------------------------------------------

 Private Sub Text18_BeforePrint(ByVal sender As object, ByVal e As EventArgs)
      DIM This As String
      DIM That As String
      DIM Current As String
     
      Current=String.Concat("*** ",Text18.Text)
      REM --------------------------------------------------------------
       
      This="***Failed to populate***"
     
      IF Left(Current,5)="*** F" or Left(Current,5)="*** f" THEN
        This="Condition: ( ) Pass (X) Fail"
      END IF
     
      IF Left(Current,5)="*** P" or Left(Current,5)="*** p" THEN
        This="Condition: (X) Pass ( ) Fail"
      END IF  
     
      REM String.Concat("'",Current)
      REM String.Concat(This,"'")
     
      Text18.Text=String.Concat(Chr(ASC(Text18.Text)),This)
    End Sub

------------------------------------------------------------------------------------

the script needs double quotes, it does not pass the syntax check without them.

Text18 is a FastReports text object which has a string datafield from an SQL database bound to it.

this field contains "Pass " or "Fail " it is bound to the text object with "[Table2.Pass_Fail]"

I have added another Text object, also bound to this field to the report and can see the uncoded one displays "Pass " or "Fail ", as appropriate for the record.

      Text18.Text=String.Concat(Chr(ASC(Text18.Text)),This)

the line above now displays "[*** Failed to populate ***"

This seems to suggest the process has not resolved the the content of [Table2.Pass_Fail] at the time that the BeforePrint event fires, which, makes no sense to me.
I may be missing the point but if you were printing a range of records then before print would not have access to individual records and that implies assuming the mechanism supports multiple records that it probably does not have access to the text box data for a y indidul record.

However your opening comment puts the 'lie' to this since the same command you say works there ... Can you say what is used in those other subs since the one liner assignment doesn't necessarily get used there so I am wondering for now if the ref to the other subs as working might be fooling us!

Chris
Avatar of rhill52

ASKER

yea there is a BeforePrint event that can be tied to every item for the report, each record of the DataBase fires these events for each DataField that I specifiy one for.

All that aside, I have skinned this particular cat another way:

from the SQL generation end of things, this:

SELECT *,
case
      when upper(Left(Pass_Fail,1))='P' then 'Condition: (X) Pass ( ) Fail'
      else 'Condition: ( ) Pass (X) Fail'
end as pf_State

sorts the problem out perfectly, I would still like to know how to achieve this properly in FastReports as the scripting engine within it would seem easily upto such a task, but, the pressure is off now and I can attempt to discover this over time.

Cheers, and thank you for your time.
Avatar of rhill52

ASKER

again, for completeness, here is one of the events that do work.

Private Sub Text10_BeforePrint(ByVal sender As object, ByVal e As EventArgs)
      REM Primary
      Dim This As String
      Dim Current As String
      Current=Text10.Text
      This=String.Concat("Primary Securing: ",Current)
      Text10.Text=This
    End Sub

Avatar of rhill52

ASKER

ok, I have sorted it out now

event AfterData, not, event BeforePrint was the way to go.

I was blind-sided by the fact that some BeforeEvents do work.

Thanks for your input Chris.