@Fernando, bom dia!
Agora consegui abrir!
Me ajudou bastante! Não tinha ciência de que era possível criar Function dessa maneira. Entretanto ela só funciona dentro do contexto local.
Tentei criar um xObject como você sugeriu, mas estou com dificuldade de fazer funcionar.
Eu fiz assim:
Criei 6 propriedades no xObject:
- strArquivo - String
- strSecao - String
- strChave - String
- strValor - String
- Ler - Boolean
- Escrever - Boolean
Depois defini o script a seguir no evento OnPropertyChange da Propriedade Ler:
Sub Funcoes_OnLerChanged()
strValor = ReadIni(strArquivo, strSecao, strChave)
End Sub
Public Function ReadIni( myFilePath, mySection, myKey )
’ This function returns a value read from an INI file
’
’ Arguments:
’ myFilePath [string] the (path and) file name of the INI file
’ mySection [string] the section in the INI file to be searched
’ myKey [string] the key whose value is to be returned
’
’ Returns:
’ the [string] value for the specified key in the specified section
’
’ CAVEAT: Will return a space if key exists but value is blank
’
’ Written by Keith Lacelle
’ Modified by Denis St-Pierre and Rob van der Woude
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim intEqualPos
Dim objFSO, objIniFile
Dim strFilePath, strKey, strLeftString, strLine, strSection
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
ReadIni = ""
strFilePath = Trim( myFilePath )
strSection = Trim( mySection )
strKey = Trim( myKey )
If objFSO.FileExists( strFilePath ) Then
Set objIniFile = objFSO.OpenTextFile( strFilePath, ForReading, False )
Do While objIniFile.AtEndOfStream = False
strLine = Trim( objIniFile.ReadLine )
' Check if section is found in the current line
If LCase( strLine ) = "[" & LCase( strSection ) & "]" Then
strLine = Trim( objIniFile.ReadLine )
' Parse lines until the next section is reached
Do While Left( strLine, 1 ) <> "["
' Find position of equal sign in the line
intEqualPos = InStr( 1, strLine, "=", 1 )
If intEqualPos > 0 Then
strLeftString = Trim( Left( strLine, intEqualPos - 1 ) )
' Check if item is found in the current line
If LCase( strLeftString ) = LCase( strKey ) Then
ReadIni = Trim( Mid( strLine, intEqualPos + 1 ) )
' In case the item exists but value is blank
If ReadIni = "" Then
ReadIni = " "
End If
' Abort loop when item is found
Exit Do
End If
End If
' Abort if the end of the INI file is reached
If objIniFile.AtEndOfStream Then Exit Do
' Continue with next line
strLine = Trim( objIniFile.ReadLine )
Loop
Exit Do
End If
Loop
objIniFile.Close
Else
MsgBox strFilePath & " doesn't exists. Exiting..."
Wscript.Quit 1
End If
End Function
Sub Vazio()
End Sub
A seguir criei uma instância do xObject com o nome Funcoes e onde eu preciso executá-la estou usando o código a seguir:
Dim Funcoes
Set Funcoes = Application.GetObject("DadosPCC.Funcoes1")
Funcoes.strArquivo = "\\MAIN_SERVER\TESTE_AUTOMACAO\RECEITAS\Backup.ini"
Funcoes.strSecao = ComandoAnalogico.FonteAnalogica.Tag
Funcoes.strChave = "HH"
Funcoes.Ler = True
Funcoes.Ler = False
Msgbox Funcoes.strValor
Consigo acompanhar a alteração das propriedades que são atribuídas diretamente corretamente, porém a propriedade strValor continua em branco.
Não consigo entender o que estou fazendo de errado. Você pode me dizer o que eu preciso fazer diferente?
Desde já agradeço a atenção.