how to validate if an .IMD

5 posts / 0 new
Last post
ortizmario6025@...
Offline
Joined: 09/03/2021 - 11:54
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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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@...
Offline
Joined: 09/03/2021 - 11:54

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

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Glad you find the site helpful.  It is always nice when someone comes back and says that my suggestion helped them out.  I apprecaite that.

ortizmario6025@...
Offline
Joined: 09/03/2021 - 11:54

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