RESOURCE ...
Alguém poderia me dar uma ajudinha sobre a seguinte questão: Tenho um sistema e, toda vez que preciso fazer a manutenção no banco de dados, tenho que ficar enviando um arquivo de script ao usuário para fazer as alterações na base. Agora estou passando estes scripts para dentro de um módulo e, ao invés de mandar para o cliente em separado, estou compilando junto.
Entretanto, gostaria de fazer diferente, mas não sei se dará certo.
Quero colocar este meu script no Resource, como .txt e criar uma função pra ler o Resource, carregar o conteúdo numa variável e disparar o comando para o SQL, atualizando minha base de dados. Assim eu posso programar minhas rotinas, criar a query no analisador, jogá-la no script.txt e simplesmente 'puxar' este arquivo em meu resource.
Estou viajando demais ou tem a possibilidade de fazer isto?
[]ÂÂÂ's
Milton
Entretanto, gostaria de fazer diferente, mas não sei se dará certo.
Quero colocar este meu script no Resource, como .txt e criar uma função pra ler o Resource, carregar o conteúdo numa variável e disparar o comando para o SQL, atualizando minha base de dados. Assim eu posso programar minhas rotinas, criar a query no analisador, jogá-la no script.txt e simplesmente 'puxar' este arquivo em meu resource.
Estou viajando demais ou tem a possibilidade de fazer isto?
[]ÂÂÂ's
Milton
Porque você não usa um bancodedados em 1 servidor web?
Olá
Se o seu problema é ler um arquivo .txt do resource, tenho um exemplo que le arquivos .TXT, carrega imagens . Gif e imagens . Jpg do arquivo .res
Se quiser o projeto do código me avise... e te envio o código está abaixo:
no projeto foram incluidos no arquivo .RES : um arquivo TXT, uma imagem .GIF e uma JPG
sds,
Maze
================================================================
'codigo dor formulario:
Option Explicit
' --------------------------------------------------------------------------
' Copyright (C) 1998 Microsoft Corporation '
' --------------------------------------------------------------------------
' You have a royalty-free right to use, modify, reproduce and distribute '
' the Sample Application Files (and/or any modified version) in any way '
' you find useful, provided that you agree that Microsoft has no warranty, '
' obligations or liability for any Sample Application Files. '
' --------------------------------------------------------------------------
' Written by Mike Dixon (mikedix@microsoft.com) '
' --------------------------------------------------------------------------
'The res file contains the following items:
'========================================='
'RESOURCE ID TYPE Actual Item '
'========================================='
' 101 Custom resfile.gif '
' 102 Custom resfile.jpg '
' 103 Custom test.txt '
Private Sub Form_Load()
'Center the form
Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
Picture1.AutoSize = True
'Load the JPG picture now
cmdJPG_Click
End Sub
Private Sub cmdGif_Click()
'Load Resource item 101 (a gif file) into the picturebox
Set Picture1.Picture = LoadPictureResource(101, "Custom")
'Show/Hide Controls
Text1.Visible = False
Picture1.Visible = True
End Sub
Private Sub cmdJPG_Click()
'Load Resource item 101 (a jpg file) into the picturebox
Set Picture1.Picture = LoadPictureResource(102, "Custom")
'Show/Hide Controls
Text1.Visible = False
Picture1.Visible = True
End Sub
Private Sub cmdText_Click()
'Load Resource item 103 (a text file) into the textbox
Dim sFileName As String
Dim iFileNum As Integer
Dim sText As String
If GetTempFile("", "~rs", 0, sFileName) Then
If Not SaveResItemToDisk(103, "Custom", sFileName) Then
'Get free file handle
iFileNum = FreeFile
'Open the file
Open sFileName For Input As iFileNum
'Input all the text of the file
sText = Input(LOF(iFileNum), iFileNum)
'Close the file
Close iFileNum
'Place the text from the file into the textbox
Text1.Text = sText
'Show/Hide Controls
Picture1.Visible = False
Text1.Visible = True
'Delete the temp file
Kill sFileName
Else
MsgBox "Unable to save resource item to disk!", vbCritical
'Show/Hide Controls
Picture1.Visible = False
Text1.Visible = False
End If
Else
MsgBox "Unable to get temp file name!", vbCritical
'Show/Hide Controls
Picture1.Visible = False
Text1.Visible = False
End If
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
-----------------------------------------------------------------------------------------------
' codigo do modulo bas
Option Explicit
Public Declare Function GetTempFilename Lib "kernel32" _
Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFilename As String _
) As Long
Public Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String _
) As Long
Public Function LoadPictureResource( _
ByVal ResourceID As Long, _
ByVal sResourceType As String, _
Optional TempFile _
) As Picture
'=====================================================
'Returns a picture object from a resource file.
'Used for loading images other than ICO and BMP into a
'Picture property. (Such as GIF and JPG images)
'=====================================================
'EXAMPLE CALL:
'Set Picture1.Picture = LoadPictureResource(101, "Custom", "C: emp emp.tmp")
Dim sFileName As String
'Check if the TempFile Name has been specified
If IsMissing(TempFile) Then
'Create a temp file name such as "~res1234.tmp"
GetTempFile "", "~rs", 0, sFileName
Else
'Use the specified temp file name
sFileName = TempFile
End If
'Save the resource item to disk
If SaveResItemToDisk(ResourceID, sResourceType, sFileName) = 0 Then
'Return the picture
Set LoadPictureResource = LoadPicture(sFileName)
'Delete the temp file
Kill sFileName
End If
End Function
Public Function SaveResItemToDisk( _
ByVal iResourceNum As Integer, _
ByVal sResourceType As String, _
ByVal sDestFileName As String _
) As Long
'=============================================
'Saves a resource item to disk
'Returns 0 on success, error number on failure
'=============================================
'Example Call:
' iRetVal = SaveResItemToDisk(101, "CUSTOM", "C:\myImage.gif")
Dim bytResourceData() As Byte
Dim iFileNumOut As Integer
On Error GoTo SaveResItemToDisk_err
'Retrieve the resource contents (data) into a byte array
bytResourceData = LoadResData(iResourceNum, sResourceType)
'Get Free File Handle
iFileNumOut = FreeFile
'Open the output file
Open sDestFileName For Binary Access Write As #iFileNumOut
'Write the resource to the file
Put #iFileNumOut, , bytResourceData
'Close the file
Close #iFileNumOut
'Return 0 for success
SaveResItemToDisk = 0
Exit Function
SaveResItemToDisk_err:
'Return error number
SaveResItemToDisk = Err.Number
End Function
Public Function GetTempFile( _
ByVal strDestPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Integer, _
lpTempFilename As String _
) As Boolean
'==========================================================================
' Get a temporary filename for a specified drive and filename prefix
' PARAMETERS:
' strDestPath - Location where temporary file will be created. If this
' is an empty string, then the location specified by the
' tmp or temp environment variable is used.
' lpPrefixString - First three characters of this string will be part of
' temporary file name returned.
' wUnique - Set to 0 to create unique filename. Can also set to integer,
' in which case temp file name is returned with that integer
' as part of the name.
' lpTempFilename - Temporary file name is returned as this variable.
' RETURN:
' True if function succeeds; false otherwise
'==========================================================================
If strDestPath = "" Then
' No destination was specified, use the temp directory.
strDestPath = String(255, vbNullChar)
If GetTempPath(255, strDestPath) = 0 Then
GetTempFile = False
Exit Function
End If
End If
lpTempFilename = String(255, vbNullChar)
GetTempFile = GetTempFilename(strDestPath, lpPrefixString, wUnique, lpTempFilename) > 0
lpTempFilename = StripTerminator(lpTempFilename)
End Function
Public Function StripTerminator(ByVal strString As String) As String
'==========================================================
' Returns a string without any zero terminator. Typically,
' this was a string returned by a Windows API call.
'
' IN: [strString] - String to remove terminator from
'
' Returns: The value of the string passed in minus any
' terminating zero.
'==========================================================
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Se o seu problema é ler um arquivo .txt do resource, tenho um exemplo que le arquivos .TXT, carrega imagens . Gif e imagens . Jpg do arquivo .res
Se quiser o projeto do código me avise... e te envio o código está abaixo:
no projeto foram incluidos no arquivo .RES : um arquivo TXT, uma imagem .GIF e uma JPG
sds,
Maze
================================================================
'codigo dor formulario:
Option Explicit
' --------------------------------------------------------------------------
' Copyright (C) 1998 Microsoft Corporation '
' --------------------------------------------------------------------------
' You have a royalty-free right to use, modify, reproduce and distribute '
' the Sample Application Files (and/or any modified version) in any way '
' you find useful, provided that you agree that Microsoft has no warranty, '
' obligations or liability for any Sample Application Files. '
' --------------------------------------------------------------------------
' Written by Mike Dixon (mikedix@microsoft.com) '
' --------------------------------------------------------------------------
'The res file contains the following items:
'========================================='
'RESOURCE ID TYPE Actual Item '
'========================================='
' 101 Custom resfile.gif '
' 102 Custom resfile.jpg '
' 103 Custom test.txt '
Private Sub Form_Load()
'Center the form
Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
Picture1.AutoSize = True
'Load the JPG picture now
cmdJPG_Click
End Sub
Private Sub cmdGif_Click()
'Load Resource item 101 (a gif file) into the picturebox
Set Picture1.Picture = LoadPictureResource(101, "Custom")
'Show/Hide Controls
Text1.Visible = False
Picture1.Visible = True
End Sub
Private Sub cmdJPG_Click()
'Load Resource item 101 (a jpg file) into the picturebox
Set Picture1.Picture = LoadPictureResource(102, "Custom")
'Show/Hide Controls
Text1.Visible = False
Picture1.Visible = True
End Sub
Private Sub cmdText_Click()
'Load Resource item 103 (a text file) into the textbox
Dim sFileName As String
Dim iFileNum As Integer
Dim sText As String
If GetTempFile("", "~rs", 0, sFileName) Then
If Not SaveResItemToDisk(103, "Custom", sFileName) Then
'Get free file handle
iFileNum = FreeFile
'Open the file
Open sFileName For Input As iFileNum
'Input all the text of the file
sText = Input(LOF(iFileNum), iFileNum)
'Close the file
Close iFileNum
'Place the text from the file into the textbox
Text1.Text = sText
'Show/Hide Controls
Picture1.Visible = False
Text1.Visible = True
'Delete the temp file
Kill sFileName
Else
MsgBox "Unable to save resource item to disk!", vbCritical
'Show/Hide Controls
Picture1.Visible = False
Text1.Visible = False
End If
Else
MsgBox "Unable to get temp file name!", vbCritical
'Show/Hide Controls
Picture1.Visible = False
Text1.Visible = False
End If
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
-----------------------------------------------------------------------------------------------
' codigo do modulo bas
Option Explicit
Public Declare Function GetTempFilename Lib "kernel32" _
Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFilename As String _
) As Long
Public Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String _
) As Long
Public Function LoadPictureResource( _
ByVal ResourceID As Long, _
ByVal sResourceType As String, _
Optional TempFile _
) As Picture
'=====================================================
'Returns a picture object from a resource file.
'Used for loading images other than ICO and BMP into a
'Picture property. (Such as GIF and JPG images)
'=====================================================
'EXAMPLE CALL:
'Set Picture1.Picture = LoadPictureResource(101, "Custom", "C: emp emp.tmp")
Dim sFileName As String
'Check if the TempFile Name has been specified
If IsMissing(TempFile) Then
'Create a temp file name such as "~res1234.tmp"
GetTempFile "", "~rs", 0, sFileName
Else
'Use the specified temp file name
sFileName = TempFile
End If
'Save the resource item to disk
If SaveResItemToDisk(ResourceID, sResourceType, sFileName) = 0 Then
'Return the picture
Set LoadPictureResource = LoadPicture(sFileName)
'Delete the temp file
Kill sFileName
End If
End Function
Public Function SaveResItemToDisk( _
ByVal iResourceNum As Integer, _
ByVal sResourceType As String, _
ByVal sDestFileName As String _
) As Long
'=============================================
'Saves a resource item to disk
'Returns 0 on success, error number on failure
'=============================================
'Example Call:
' iRetVal = SaveResItemToDisk(101, "CUSTOM", "C:\myImage.gif")
Dim bytResourceData() As Byte
Dim iFileNumOut As Integer
On Error GoTo SaveResItemToDisk_err
'Retrieve the resource contents (data) into a byte array
bytResourceData = LoadResData(iResourceNum, sResourceType)
'Get Free File Handle
iFileNumOut = FreeFile
'Open the output file
Open sDestFileName For Binary Access Write As #iFileNumOut
'Write the resource to the file
Put #iFileNumOut, , bytResourceData
'Close the file
Close #iFileNumOut
'Return 0 for success
SaveResItemToDisk = 0
Exit Function
SaveResItemToDisk_err:
'Return error number
SaveResItemToDisk = Err.Number
End Function
Public Function GetTempFile( _
ByVal strDestPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Integer, _
lpTempFilename As String _
) As Boolean
'==========================================================================
' Get a temporary filename for a specified drive and filename prefix
' PARAMETERS:
' strDestPath - Location where temporary file will be created. If this
' is an empty string, then the location specified by the
' tmp or temp environment variable is used.
' lpPrefixString - First three characters of this string will be part of
' temporary file name returned.
' wUnique - Set to 0 to create unique filename. Can also set to integer,
' in which case temp file name is returned with that integer
' as part of the name.
' lpTempFilename - Temporary file name is returned as this variable.
' RETURN:
' True if function succeeds; false otherwise
'==========================================================================
If strDestPath = "" Then
' No destination was specified, use the temp directory.
strDestPath = String(255, vbNullChar)
If GetTempPath(255, strDestPath) = 0 Then
GetTempFile = False
Exit Function
End If
End If
lpTempFilename = String(255, vbNullChar)
GetTempFile = GetTempFilename(strDestPath, lpPrefixString, wUnique, lpTempFilename) > 0
lpTempFilename = StripTerminator(lpTempFilename)
End Function
Public Function StripTerminator(ByVal strString As String) As String
'==========================================================
' Returns a string without any zero terminator. Typically,
' this was a string returned by a Windows API call.
'
' IN: [strString] - String to remove terminator from
'
' Returns: The value of the string passed in minus any
' terminating zero.
'==========================================================
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Valeu....
Tópico encerrado , respostas não são mais permitidas