Previously done a small VB project, customers need software at the same time to support both Chinese and English, for this write an automatic language switching module to use, do not dare to enjoy, to give you a reference.
Module Mdllanmgr.bas:
Attribute vb_name = "Modulelanmgr"
Option Explicit
Private Declare Function getprivateprofilestring& Lib "kernel32" Alias "Getprivateprofilestringa" (ByVal Lpapplicationname As String, ByVal Lpkeyname as String, ByVal Lpdefault as String, ByVal lpreturnedstring as String, ByVal Nsize as Long, ByVal lpFileName as String)
Private Languagefilename as String
' Select language
Public Sub selectlanguage (lanname as String)
On Error Resume Next
Select Case Lanname ' reads different language files according to the name of the language selected by the user
Case "中文版":
Languagefilename = Addsplash (App.Path) & "English.lan"
Case "Chinese (simplify)":
Languagefilename = Addsplash (App.Path) & "Chineses.lan"
Case "Chinese (Traditional)":
Languagefilename = Addsplash (App.Path) & "Chineset.lan"
Case Else:
Languagefilename = ""
End Select
End Sub
' Translate text
Public Function Translatestr (ssection As String, SKey as String, Sdefval as String) as String
Dim svalue as String * 128
Dim N as Long
On Error Resume Next
Translatestr = Sdefval
If not FileExists (languagefilename) Then
Exit Function
End If
N = GetPrivateProfileString (ssection, SKey, Sdefval, svalue, 127, Languagefilename)
If N > 0 Then
Translatestr = Left (svalue, N)
End If
End Function
' Automatically converts some of the basic controls on the form (also extensible, currently supports Commandbutton,label,optionbutton,checkbutton)
Public Sub Translateform (Frm as Form)
Dim I as Long
On Error Resume Next
Frm.caption = Translatestr (Frm.name, "Caption", frm.caption)
For I = 0 to Frm.controls.count-1
If (TypeOf frm.controls (i) is CommandButton) Or (TypeOf frm.controls (i) is Label) _
or (TypeOf frm.controls (i) is OptionButton) or (TypeOf frm.controls (i) is CheckBox) Then
Frm.controls (I). Caption = Translatestr (Frm.name, Frm.controls (I). Name, Frm.controls (I). Caption)
End If
Next I
End Sub