?
Solved

Import a text file into resource file

Posted on 2002-05-06
8
Medium Priority
?
413 Views
Last Modified: 2011-10-03
Hi,
i want to create an application which is language independent. I've created a resource file, with all phrases/caption texts ... of my forms in it.
But now i come to the next form, which is a reengineering of an existing one. I have already a text file where ~300 lines of textes are stored. Now i want to import this file to my existing resource file.
is there a way to do this, without switching between nodepad and resource file editor for doing this silly copy/paste??

hope, someone has a good answer...
olka
0
Comment
Question by:olka
[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
8 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 6993150
I think you mean something like this

Open "Filename" For Input As #1
  strInput=input(lof(1),1)
Close #1
End Sub


Open "Filename" For Output As #1
  Write #1, "data here" & strInput
Close #1
0
 

Author Comment

by:olka
ID: 6993159
when it is possible to write the contents of the input file to the resource file (in this case the Output) then it would be ok. But i don't think that this is possible, because the VisualStudio resource file seems to be no text file.
olka
0
 
LVL 14

Accepted Solution

by:
Matti earned 600 total points
ID: 6993295
Hi!

The res file which is directly supported by VB is an cmplier procuct from .RC and .H files

Seems that you have the VisualStudio then in VC++ you can save easy in this .res format.

If you look in your VB setupkit folder there is a RC and .H and RES files for that Setup1 VBproject.

See the SETUP1.RC file is the one targeted for translations and Setup1.res the output there are editors to support directly res file like the VB adini, but the own text editor project is much more simple to make if you do write these both files at same time.

In RC file it has the string
resCALCSPACE "An error occurred while calculating required disk space."

In .H file it has the ID num:
#define resCALCSPACE 400

And common in both is:
resCALCSPACE


If you can make both of these files like this The VC++ will load it and make the res file. Also the commandline RES compiler will do the same.

I think it's easier to copy +300 strings once.
But the "Open "Filename" For Input As #1" and
simple string calc  Name & Str(Num) will solve it

Don't have this editor made, but seen these codes, maybe someone else has a link?

May be this is very close one, Excel to Resource:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8556&lngWId=1

Matti
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthedark
ID: 6993464
I translate at runtime.


The neat thing about this method is that you can distribute your app untranslated and allow a user to translate.  You can alow your form to detect CTRL/ALT/T and pops up a list of labels and allows use to save the translated labels.

I keep the files in formname_languagecode.txt.

I basically use the following functions, bewarned xSinbad's solution may fail in a multi-user enviroment, you ned to open files "Shared".

Here is how to use translation class.

' in globals
Dim TransForm As New clsTranslate

' in app setup
TransForm.Language = "FR"
TransForm.ResourceFolder = App.Path + "\"
TransForm.TranslateMessage = TransForm.GetFromMaster(TransForm.TranslateMessage)
TransForm.TranslateTitle = TransForm.GetFromMaster(TransForm.TranslateTitle)

' in form load

TransForm.TranslateForm Me

Dim dateformat

' any where else
dateformat = TransForm.GetFromMaster("DD/MM/YY")


Here is the class:
Option Explicit

' Language Translation Class by Nick Young
' Sept 19th 2000
' please report bugs to: nyoung@vipintersoft.com
' use at will.

Public Language As String   '   e.g. FR,DE
Public TranslateMessage As String ' Message to prompt operator
Public TranslateTitle As String   ' title for translation module
Public ResourceFolder As String   ' place where translations are stored

Dim MasterData As String

Public Terminator As String
Public Sub TranslateForm(frm As Form)

Dim LangDataFile As String
Dim LD As String ' Language data
Dim SaveLD As String
Dim ok

LangDataFile = ResourceFolder + frm.Name + "_" + Language + ".txt"

LD = ReadFile(LangDataFile)
If LD = "ERROR" Then
    LD = ""
End If
SaveLD = LD
Dim ctrl As Control
For Each ctrl In frm.Controls
   If TypeOf ctrl Is VB.Label Then
      ctrl.Caption = Translate(LD, ctrl.Caption)
   ElseIf TypeOf ctrl Is VB.CommandButton Then
      ctrl.Caption = Translate(LD, ctrl.Caption)
   End If
Next

' has data changed
If LD <> SaveLD Then
   ok = WriteFileOK(LangDataFile, LD)
End If

End Sub
Public Function GetFromMaster(KeyName As String) As String

Dim LangDataFile As String
Dim LD As String ' Language data
Dim SaveLD As String
Dim ok
If Len(MasterData) = 0 Then
    LangDataFile = ResourceFolder + "MASTER" + "_" + Language + ".txt"
    MasterData = ReadFile(LangDataFile)
    If MasterData = "ERROR" Then
        MasterData = ""
    End If
End If
SaveLD = MasterData

GetFromMaster = Translate(LD, KeyName)

' has data changed
If MasterData <> SaveLD Then
   ok = WriteFileOK(LangDataFile, MasterData)
End If

End Function


Function Translate(LD As String, CaptionText As String) As String

Dim NewText As String

If Len(CaptionText) = 0 Then
    Exit Function
End If
NewText = ReturnParameter(LD, CaptionText)
If Len(NewText) = 0 Then
    NewText = InputBox(TranslateMessage, TranslateTitle, CaptionText)
    If Len(NewText) > 0 Then
        LD = LD + CaptionText + "=" + NewText + vbCrLf
    Else
        NewText = CaptionText
    End If
End If
Translate = NewText

End Function

Public Function ReadFile(FileName As String) As String

Dim wlfn As Long

wlfn = FreeFile
On Error Resume Next

If Len(Dir(FileName)) > 0 Then
    If Err.Number Then
        ReadFile = "Invalid resource file path: " + FileName
        Exit Function
    End If
   
    Open FileName For Input Shared As #wlfn
    ReadFile = Input(LOF(wlfn), wlfn)
    Close wlfn
Else
    ReadFile = "ERROR"
End If

End Function

Public Function WriteFileOK(FileName As String, DataString) As Boolean

Dim wlfn As Long

wlfn = FreeFile
On Error Resume Next
Err.Clear
WriteFileOK = False
Open FileName For Output As #wlfn
If Err.Number <> 0 Then
    Exit Function
End If
Print #wlfn, DataString;
Close wlfn
If Err.Number <> 0 Then
    Exit Function
End If
WriteFileOK = True

End Function

Function ReturnParameter(VariableList As String, VariableName As String, Optional DefaultValue As String = "", Optional FieldDelimiter As String = "") As String

' Returns the value of a variable from withing as list of stuff
' example:

' VList="Server=Fred;Title=Cute Routine"
' MyTitle=ReturnParameter(Vlist,"Title","Untitled")

Dim VarPos As Long
Dim sFieldDelimiter As String

If Len(FieldDelimiter) = 0 Then
    sFieldDelimiter = Terminator
Else
    sFieldDelimiter = FieldDelimiter
End If

VarPos = InStr(1, VariableList, VariableName, vbTextCompare)
If VarPos = 0 Then
    ReturnParameter = ""
Else
    ReturnParameter = Trim(LeftPart(RightPart(Mid(VariableList, _
        VarPos), "="), sFieldDelimiter))
End If
   
End Function

Public Function RightPart(WholeString, FindString) As String

Dim pos As Long

pos = InStr(1, WholeString, FindString, vbTextCompare)
If pos = 0 Then
    RightPart = ""
ElseIf pos = Len(WholeString) Then
    RightPart = ""
Else
    RightPart = Mid$(WholeString, pos + Len(FindString))
End If

End Function

Public Function LeftPart(WholeString, FindString) As String

Dim pos As Long

pos = InStr(1, WholeString, FindString, vbTextCompare)
If pos = 0 Then
    LeftPart = WholeString
ElseIf pos = 1 Then
    LeftPart = ""
Else
    LeftPart = Left$(WholeString, pos - 1)
End If

End Function


Private Sub Class_Initialize()
Terminator = ";"
TranslateMessage = "You need to translate the following: "
TranslateTitle = "Translation"
End Sub





0
 
LVL 17

Expert Comment

by:inthedark
ID: 6993504
Using the Translation class you don't need to give the operator an option to change if you don't want to.

Your app can run as is.

Also any where in your code you can translate e.g.

M$ = "Printer Error"
msgbox TransForm.GetFromMaster(M$)
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6993511
p.s. On my PC it only takes .010 seconds to translate an average form at runtime.
0
 

Author Comment

by:olka
ID: 6993610
the link to the Excel2Resource Project was very good.
inthedark, i'm sorry, but this tool looks much more easier then your code, even i can now administrate my NLS-Textes in Excel.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6993678
If you already have done the resource file route then it's too late for you but using the translate class means that you can delivery your app. in any language without any effor on your part.
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 need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month8 days, 21 hours left to enroll

765 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