Skip to main content

how to validate if an .IMD

hello, how to validate if an .IMD file is found in the working project directory to send a message to the user who must first verify that this file exists and then proceed with the execution of the tests.

Brian Element Thu, 10/06/2022 - 14:25

There are different ways you can do this, these example tries to open the file and then checks for an error.  If the file doesn't exist then IDEA throws an error which we capture and know that the file doesn't exit.


Sub Main
	MsgBox checkIfIMDFileExists("This file doesn't exist.IMD")
End Sub

Function checkIfIMdFileExists(sFilename As String) As Boolean
	Dim db As database
	
	On Error Resume Next
	client.OpenDatabase(sFilename)
	If err.number <> 0 Then
		checkIfIMdFileExists = False
		err.number = 0
	Else
		checkIfIMdFileExists = True
	End If
End Function

ortizmario6025… Fri, 10/07/2022 - 09:02

Thank you, Brian Element.
thank you very much for your help, sincerely with what I have learned from you, there is no way to thank you, it has even encouraged me to learn a little VB to apply it in my scripts

ortizmario6025… Mon, 10/10/2022 - 09:24

Cheers,
I execute the program and I place a table that exists and another that does not exist and it always throws me false, what will be happening? Here is the code.
Sub Main
MsgBox checkIfIMDFileExists("This file doesn't exist.IMD")
End Sub
 
Function checkIfIMdFileExists(sFilename As String) As Boolean
Dim db As database
 
On Error Resume Next
client.OpenDatabase("MOVI.CONTABLES.IMD")
'client.OpenDatabase(sFilename)
If err.number <> 0 Then
checkIfIMdFileExists = False
err.number = 0
Else
checkIfIMdFileExists = True
End If
End Function