Wonderful use of Microsoft. VisualBasic. dll (certainly used in development)

Source: Internet
Author: User
ArticleDirectory
    • Preface
    • Function 1: Simplified Conversion
    • Function 2: Time Difference Calculation
    • Conclusion
Preface

All those who have done VB development know that there are some good functions in VB. net, but Microsoft. visualBasic. the DLL provides us with the functions to use these functions (these functions can be used the same without VB)

Here are two main topics: one isSimplified ConversionAnd the other isCalculation time differenceI believe everyone has a way to implement these two functions, but what I want to talk about today is just one sentence.CodeThese two functions are implemented!

Function 1: Simplified Conversion

First, you must reference Microsoft. VisualBasic. dll.

 

UsingMicrosoft. VisualBasic;StringSTR ="Sorrow";//Simplified to traditional ChineseSTR = strings. strconv (STR, vbstrconv. traditionalchinese,1033);//Traditional to simplifiedSTR = strings. strconv (STR, vbstrconv. simplifiedchinese,1033);

String. strconv description:

The first parameter is the string to be converted;

The second parameter is the enumerated value of the font to be converted;

The third parameter is the final encoding format (localeid) after text conversion );

1028 traditional Chinese

1033 ASCII


Simplified Chinese 2052


Why do I use 1033 for both traditional and simplified to traditional Chinese?


First, we must first know that some simplified Chinese characters do not have any character in Traditional Chinese. In this case, the displayed word is "? .


Because the "country" of 2052 is already in simplified Chinese, when it is converted to traditional Chinese, its encoding is less than 1028, so it will be a question mark.


The best way is to use en-us as the encoding format. After en-US is used as the final encoding format and Asian characters are used, Unicode is used as the storage encoding format. The storage format of string is the same as that of. net. This solves the problem!


Therefore, when performing simplified conversion, set the third parameter to 1033.

Function 2: Time Difference Calculation

I believe that we all have two time differences for computing, which may be the number of days, hours, minutes, or seconds for calculating the difference. We can use a single code to implement this.

UsingMicrosoft. VisualBasic;//Dt = 50LongDt = dateandtime. datediff (dateinterval. Hour, datetime. Now, datetime. Now. addhours (50));
 
Dateandtime. datediff description:
The first parameter is the enumerated value in the form of the expected time difference. It can be days, hours, minutes, seconds, etc.

The second parameter is the subtraction time value;

The third parameter is the time value to be subtracted;
Conclusion

The above two functions seem very simple, but it is still quite troublesome to implement them without Microsoft. VisualBasic. dll. It is convenient and accurate to implement them using the above methods! If you think it is good, we recommend it!

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.