Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Two functions into one
Message
From
27/06/2006 10:40:06
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Two functions into one
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01131998
Message ID:
01131998
Views:
63
I have the following function to get the content of a file into a variable:
        ' FileToStr() VFP equivalent
        ' expC1 File name
        Public Function FileToStr(ByVal tcFileName As String) As String
            Dim loFile As IO.StreamReader
            Dim lcString As String
            Try
                loFile = New IO.StreamReader(tcFileName, True)
                lcString = loFile.ReadToEnd()
                loFile.Close()
            Catch loError As Exception
                oApp.ErrorSetup(loError)
                lcString = ""
            End Try
            Return lcString
        End Function
I have also this function to do the same but for binary files:
        ' Same as FileToStr() but for binary files
        ' This is used when you want to take a JPG, for example, and encode it as Base64 into a XSL
        ' expC1 File name
        Public Function FileToStrBinary(ByVal tcFileName As String) As String
            Dim loFile As IO.StreamReader
            Dim lcString As String
            Try
                loFile = New IO.StreamReader(tcFileName, System.Text.Encoding.Default)
                lcString = loFile.ReadToEnd()
                loFile.Close()
            Catch loError As Exception
                oApp.ErrorSetup(loError)
                lcString = ""
            End Try
            Return lcString
        End Function
The second function serves for reading a file such as Logo.jpg and getting its content into a variable. One need for that is to be able to encode that content into a Base64 and drop that into a XSL file. If I would use the FileToStr() function for that, I would end up in a 18k length instead of 35k length when Logo.jpg is of size 35k for example. Using FileToStrBinary() preserves the exact content as is.

The question is how can I use the same function to achieve both purposes? Because, if I use FileToStrBinary() to read a simple text file containing French characters, I am loosing them all. The key is the True parameter in FileToStr() which will preserve the French characters. But, one function is using True and the other one System.Text.Encoding.Default() which produces two different results which serves presently both of my needs. Would it there be a way to have everything into one function where binary files would be read ok as well as text files containing French characters?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform