?
Solved

Create UTF8 text file

Posted on 2008-10-29
1
Medium Priority
?
1,098 Views
Last Modified: 2012-05-05
I want to create an UTF8 text file from data that I have in my application.

I simply need a function that will take string as a parameter, convert it to UTF8 and then create UTF8 text file containing the string.
0
Comment
Question by:JiriNovotny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 22838017
try this module:


Public Enum ForWriteEnum
   ForWriting = 2
   ForAppending = 8
End Enum
#If False Then  'PreserveEnumCase
   Public ForWriting, ForAppending
#End If

Public Enum TristateEnum
   TristateTrue = -1        'Opens the file as Unicode
   TristateFalse = 0        'Opens the file as ASCII
   TristateUseDefault = -2  'Use default system setting
End Enum
#If False Then  'PreserveEnumCase
   Public TristateTrue, TristateFalse, TristateUseDefault
#End If

Public Function getUnicodeValue(v As String) As String
    Dim sUniText As String, I As Long
    For I = 1 To Len(v) Step 2
    'Someone in EE said use For I = 1 To I < Len(v) Step 2 ?
    'http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/Q_23652503.html?cid=236#a22242933
        sUniTex = sUniTex & ChrW(Asc(Mid$(v, I + 1, 1)) * 256& + Asc(Mid$(v, I, 1)))
    Next
    getUnicodeValue = sUniTex
End Function

Public Sub writeUnicodeFile( _
   ByVal sFileName As String, _
   ByVal vVar As Variant, _
   Optional ByVal ForWrite As ForWriteEnum = ForWriting, _
   Optional ByVal TriState As TristateEnum = TristateTrue, _
   Optional ByVal bJoin As Boolean)

   Dim objFSO           As Object
   Dim objStream        As Object
   Dim sText            As String

   Set objFSO = CreateObject("Scripting.FileSystemObject")
   If (Not objFSO Is Nothing) Then
      Set objStream = objFSO.OpenTextFile( _
         sFileName, ForWrite, True, TriState)

      If (Not objStream Is Nothing) Then
         With objStream
            If bJoin Then
               sText = Join(vVar, vbCrLf)
            Else
               sText = vVar
            End If
            .Write sText
            .Close
         End With
         Set objStream = Nothing
      End If
      Set objFSO = Nothing
   End If
End Sub



then use like:

writeUnicodeFile "filepath...", "your utf-8 text"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question