• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Storing files as strings

Could someone tell me how I can store a whole file as a VB string?
0
genuinegenius
Asked:
genuinegenius
1 Solution
 
idcanadaCommented:

Read the contents and store it in a resource file.
Then you can call them as needed.
0
 
genuinegeniusAuthor Commented:
Explain
0
 
dbienerCommented:
Use filelen to get size of file.
Open file for binary read.
Get the entire length of the file into a string var.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
watyCommented:
Here is how I do in my applications, it works very well :

   record.AddNew
   record("Item") = nItem
   record("Filename") = sFilename
   record("Size") = FileLen(sFilename)
   record("Type") = nType
   record("LastModified") = Now
   Call SaveFileToDB(sFilename, record("OLEModule"))
   record.Update




.



Function SaveFileToDB(sSource As String, BynaryField As Field) As Integer
   ' *** Will save a file to a Binary field

   Dim nNumBlocks       As Integer
   Dim nFile            As Integer
   Dim nI               As Integer
   Dim nFileLen         As Long
   Dim nLeftOver        As Long
   Dim sFileData        As String
   Dim Retval           As Variant
   Dim nBlockSize       As Long

   On Error GoTo Error_SaveFileToDB

   nBlockSize = 32000    ' Set size of chunk.

   ' *** Open the sSource file.
   nFile = FreeFile
   Open sSource For Binary Access Read As nFile

   ' *** Get the length of the file.
   nFileLen = LOF(nFile)
   If nFileLen = 0 Then
      SaveFileToDB = 0
      Exit Function
   End If

   ' *** Calculate the number of blocks to read and nLeftOver bytes.
   nNumBlocks = nFileLen \ nBlockSize
   nLeftOver = nFileLen Mod nBlockSize

   ' *** Read the nLeftOver data, writing it to the table.
   sFileData = String$(nLeftOver, 32)
   Get nFile, , sFileData
   BynaryField.AppendChunk (sFileData)

   ' *** Read the remaining blocks of data, writing them to the table.
   sFileData = String$(nBlockSize, Chr$(32))
   For nI = 1 To nNumBlocks
      Get nFile, , sFileData
      BynaryField.AppendChunk (sFileData)
   Next
   Close #nFile
   SaveFileToDB = nFileLen

   SaveFileToDB = 0

   Exit Function

Error_SaveFileToDB:
   SaveFileToDB = -Err
   Exit Function
   
End Function

0
 
genuinegeniusAuthor Commented:
Cheers

more comments welcome
0
 
watyCommented:
Did you use my solution?
0
 
genuinegeniusAuthor Commented:
Not yet, but I'll try it
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now