Allow VB program to support the switching of multi-national languages

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.