重拾VB631:International Issues

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Programmer’s Guide/Part 2: What Can You Do With Visual Basic/International Issues/

1. Some Terms and Basics

(1) A locale is made up of a unique combination of a language and a country. Two examples of locales are: English/U.S. and French/Belgium.

(2) String resources refers to all the text that appears in the application's user interface. They include,but are not limited to,menus,dialog boxes,and informational,alert,and error messages. If an application will be used in a locale other than the one in which it was developed,these resources will have to be translated,or localized.

(3) It is a lot more efficient to design your application with localization in mind,following an approach that separates string resources from code,than to revise your finished application to make it international later in the development process.

(4) Any application that will be localized represents two conceptual blocks: a code block and a data block.

The data block contains all the user-interface string resources but no code. Conversely,the code block contains only the application code that is run for all locales.

In theory,you can develop a localized version of your Visual Basic application by changing only the data block. The code block for all locales should be the same.

2. 和界面相关的

(1) When you are writing Visual Basic code,you can use the LoadResString,LoadResPicture,and LoadResData functions in place of references to string literals,pictures,and data. 这样不仅方便本地化,也提高性能减少代码大小。

(2) Because text tends to grow when you localize an application,you should pay special attention when designing the following user interface (UI) components: Messages(小心太长文字要拐弯),Menus and dialog boxes(小心文字太长导致控件位置不当),Icons and bitmaps(确认它们是文化认同的,同时是不带文字的),Access and shortcut keys(注意各国的键盘可能不同).

3. code module要注意的

(1) You should identify the strings that need to be localized,allow for strings to grow,and avoid the pitfalls of string concatenation.

(2) The buffer size you declare in your Visual Basic code must account for this increase.

(3) 在不同的语言里两个字符串相加得到的结果可能不同

(4) it is also important to know that words or sentences that appear identical in English may need to be translated into different words or sentences when localized.

4. Writing International Code in Visual Basic

(1) The system locale is the locale of the user who runs your program — it is used as a reference for user input and output and uses Control Panel settings provided by the operating system. The code locale is always English/U.S. in Visual Basic,regardless of which international version you use.

(2) Date: In Visual Basic,never type dates as strings in your code. Entering dates in code in the format #month/day/year# ensures that the date will be interpreted correctly in any system locale.

(3) Currency: Avoid typing currencies as strings in your code.

(4) Numeric Values and Separators: Instead,use the CStr,CDbl,CSng,CInt,and CLng functions to provide international conversions from any other data type to the data type you need. These functions use the system locale to determine the decimal separator.

5. Locale-Aware Functions

(1) In Visual Basic,many functions use the user's system locale,which uses the Control Panel settings provided by the operating system to automatically determine the conventions at run time. These functions are called locale-aware functions.

(2) Print Method

(3) Format Function: Using named formats produces output that is based on the user's system locale. The named formats can even generate output in the user's native language,including the names of months and days of the week.

6. International Sort Order and String Comparison

(1) Correct international sorting can imply context-sensitive sorting. 另外还有可能一个字变俩字,俩字变1个。另外不同的语言可能使用不同的“code pages”.

(2) Visual Basic provides a number of tools,such as Like and StrComp,which are locale-aware.

(3) Option Compare Statement: If you specify Binary,comparisons are done according to a sort order derived from the internal binary representations of the characters. If you specify Text,comparisons are done according to the case-insensitive textual sort order determined by the user's system locale. The default text comparison method is Binary.

(4) Comparing Strings with the Like Operator: When character ranges are used with Like,the specified pattern indicates a range of the sort ordering. 在某些语言里这可能会导致有些字母被漏掉。

7. International File Input/Output

(1) Locale is also an important consideration when working with file input and output in Visual Basic. Both the Print # and Write # statements can be used to work with data files,but they have distinct purposes.

(2) The Input # statement cannot read locale-aware data in Visual Basic that has been written to a file with the Print # statement. To write locale-independent data that can be read by Visual Basic in any locale,use the Write # statement instead of the Print # statement.

8. Locale-Aware SQL Queries Based on Dates

(1) In Visual Basic,the database engine stores a date/time value as a DateSerial value,which is represented by an 8-byte floating-point number,with the date as the integral portion and the time as the fractional portion. This approach is completely locale-independent and will let you perform date/time comparisons using the international date/time formats.

(2) Structured Query Language (SQL) is an ANSI standard with which Visual Basic complies. Dates are saved in tables and databases using the English/U.S. format (month/day/year). This format was also adopted for the Microsoft Jet database engine. Queries that use these fields may return the wrong records or no records at all if a non-U.S. date format is used.

This constraint also applies to the Filter property,to the FindFirst,FindNext,FindPrevious,and FindLast methods of the Recordset object,and to the WHERE clause of an SQL statement.

(3) Avoid using date/time literals in your code. Instead,consider using the DateValue or the DateSerial functions to generate the date you want. The DateValue function uses the system's Short Date setting to interpret the string you supply; the DateSerial function uses a set of arguments that will run in any locale. If you are using date/time literals in your SQL query or with the Filter property,you have no choice but to use the English/U.S. format for date and time.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...