-1

I have a database with 2 alternive picture filenames pic1 and pic2. If the first picture file does not exist i want to print the second.

in the onFormat Event of the report I want to do somthing like:

if FileExists(pic1) Then article.Picture=pic1 Else article.Picture=Pic2 EndIf

But I do not succeed as the componentone vbscript is not so well documented

user1230268
  • 221
  • 2
  • 14
  • Are you using C1Report or FlexReport? Is this for a designer? There is nothing called C1 VBScript, only VBScript with fields rendered from C1Report/FlexReport. – Nilay Vishwakarma Feb 27 '17 at 06:09
  • I am using c1Reports Build 2/4.6.20112.54408 and have the code article.Picture= pic1 in the OnFormat Event (in script editor window) which works! pic1 is the fullpath to a pic that is coming from a database field. But now I want to check if the file exists and if not i want to use a pic named pic2 coming from anothe db field. – user1230268 Feb 27 '17 at 07:27
  • Refer the answer. – Nilay Vishwakarma Feb 27 '17 at 08:57

1 Answers1

0

UPDATE

C1Report VBScrit engine does not support CreateObject, and thus this is not supported from report designer.


There are no inbuilt IO commands in VBScript. Instead, you can use FileSystemObject to check this. Use this function to determine if a file exists:
Function FileExists(filePath)
      Dim fso, exists
      Set fso = CreateObject("Scripting.FileSystemObject")
      If (fso.FileExists(filePath)) Then
        exists = True
      Else
        exists = False
      End If
      FileExists = exists
    End Function

Use this function in your VBScript editor

Nilay Vishwakarma
  • 3,105
  • 1
  • 27
  • 48
  • I tried this already, but Functions seem to be not supported by c1reports.If put this code in onFormat:Function FileExists(filePath) Dim fso, exists Set fso = CreateObject("Scripting.FileSystemObject") If (fso.FileExists(filePath)) Then exists = True Else exists = False End If FileExists = exists End Function IF FileExists(bilddatei)=True THEN ArtBild.Picture=bilddatei ELSE ArtBild.picture=bildalternativ END IF – user1230268 Feb 27 '17 at 09:11
  • Why not add this function as a global script? `VBScript Editor> Script:Report.GlobalScripts` – Nilay Vishwakarma Feb 27 '17 at 09:19
  • I do not know where I can do that. – user1230268 Feb 27 '17 at 09:31
  • seems it does not exist in my old version. – user1230268 Feb 27 '17 at 10:02
  • The question is if CreateObject is supported by C1Report's VBScript engine. Let me investigate on this, I would update the post once done – Nilay Vishwakarma Feb 27 '17 at 10:08
  • the only workarround in Visual studio is to load the report data to a datatable and do the logic there and then pass the dt as report datasource. – user1230268 Mar 01 '17 at 10:03