vb6.0和vb.net有什么区别? VB6.0与VB.NET有什么区别?
Visual Studio\u4e2d\u7684VB\u548cVB6.0\u6709\u4ec0\u4e48\u5927\u7684\u533a\u522b\uff1f\u4e00\u3001\u521b\u5efa\u7a97\u4f53\u65b9\u5f0f\u4e0d\u540c
1\u3001Visual Studio\u4e2d\u7684VB\uff1a\u5411\u7a97\u4f53\u4e2d\u62d6\u5165\u7684\u7ec4\u4ef6\uff0c\u90fd\u662f\u57fa\u4e8e\u7ee7\u627f\uff0c\u4ece.Net\u6846\u67b6\u63d0\u4f9b\u7684SDK\u4e2d\u76f8\u5e94\u7684\u7c7b\u7ee7\u627f\uff0c\u7ecf\u8fc7\u5b9e\u4f8b\u5316\u540e\uff0c\u901a\u8fc7\u6dfb\u52a0\u529f\u80fd\u624d\u628a\u7ec4\u4ef6\u52a0\u5165\u5230\u8bbe\u8ba1\u7a97\u4f53\u4e2d\u3002
2\u3001VB6.0\uff1a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u521b\u5efa\u7684\u7ec4\u4ef6\u5168\u90e8\u662fCOM\u7ec4\u4ef6\uff0c\u5373\u53ef\u5728COM\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u7684ActiveX\u63a7\u4ef6\u3001ActiveX \u7c7b\u578b\u7684DLL \u548cActiveX\u7c7b\u578b\u7684EXE\u3002
\u4e8c\u3001\u8bbf\u95ee\u6570\u636e\u5e93\u65b9\u5f0f\u4e0d\u540c
1\u3001Visual Studio\u4e2d\u7684VB\uff1a\u662f\u4f7f\u7528ADO.NET\u6765\u8bbf\u95ee\u6570\u636e\u5e93\uff0cADO.NET\u662f.NET\u6846\u67b6\u7684\u4e00\u90e8\u5206\uff0c\u5176\u5bf9\u5e94\u7684\u7c7b\u5e93\u662f.Net FrameWork SDK\u7684\u771f\u5b50\u96c6\u3002
2\u3001VB6.0\uff1a\u901a\u8fc7ADO\uff08Active X Data Object\uff0c\u5373\uff1aActive X\u6570\u636e\u5bf9\u8c61\uff09\u6765\u5b9e\u73b0\u5bf9\u6570\u636e\u5e93\u8bbf\u95ee\u7684\u3002\u540c\u65f6\u4e3a\u4e86\u4fdd\u8bc1\u5bf9\u65e9\u671f\u7248\u672c\u7684\u517c\u5bb9\uff0c\u4e5f\u63d0\u4f9bRDO\uff08\u8fdc\u7a0b\u6570\u636e\u5bf9\u8c61\uff09\u548cDAO\uff08\u6570\u636e\u8bbf\u95ee\u5bf9\u8c61\uff09\u4e8c\u79cd\u6570\u636e\u8bbf\u95ee\u6280\u672f\u3002
\u4e09\u3001\u521b\u5efaWEB\u5e94\u7528\u65b9\u5f0f\u4e0d\u540c
1\u3001Visual Studio\u4e2d\u7684VB\uff1a\u662f\u4f7f\u7528ASP.NET\u6280\u672f\u6765\u7f16\u5199Web\u9875\u9762\u3002\u5728ASP.NET\u4e2d\u4f7f\u7528\u7684\u4e5f\u4e0d\u518d\u662f\u811a\u672c\u8bed\u8a00\uff0c\u800c\u662f\u771f\u6b63\u610f\u4e49\u7f16\u7a0b\u8bed\u8a00\uff0c\u5176\u4e2d\u5c31\u53ef\u4ee5\u662fVB.NET
2\u3001VB6.0\uff1a\u662f\u4f7f\u7528Active Server Page\uff08\u7b80\u79f0ASP\uff09\u6765\u521b\u5efa\u5728 Web\u5e94\u7528\u7a0b\u5e8f\u3002\u5728ASP\u4e2d\uff0c\u7f16\u5199Web\u9875\u9762\u5e76\u975e\u7eaf\u6b63\u7684VB\u8bed\u8a00\uff0c\u800c\u662fVB\u811a\u672c\u8bed\u8a00--VBScript\u3002
\u53c2\u8003\u8d44\u6599\u6765\u6e90\uff1a\u767e\u5ea6\u767e\u79d1-Visual Basic
\u53c2\u8003\u8d44\u6599\u6765\u6e90\uff1a\u767e\u5ea6\u767e\u79d1-VB.NET
VB.NET\u548cVB6.0\u6709\u4ec0\u4e48\u533a\u522b
Visual Basic .NET\u662fMicrosoft Visual Studio .NET\u5957\u4ef6\u4e2d\u4e3b\u8981\u7ec4\u6210\u90e8\u5206\u4e4b\u4e00\u3002.NET\u7248\u672c\u7684Visual Basic\u589e\u52a0\u4e86\u66f4\u591a\u7279\u6027\uff0c\u800c\u4e14\u6f14\u5316\u4e3a\u5b8c\u5168\u9762\u5411\u5bf9\u8c61\uff08\u5c31\u50cfC++\uff09\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u672c\u6587\u5c06\u4ecb\u7ecdVB.NET\u7684\u65b0\u7279\u6027\uff0c\u5e76\u6bd4\u8f83VB6.0/VB.NET\u4e4b\u95f4\u7684\u533a\u522b\uff0c\u9610\u8ff0\u5982\u4f55\u5229\u7528VB.NET\u7f16\u5199\u7b80\u5355\u7684\u5e94\u7528\u7a0b\u5e8f\u3002
1.1 \u4ec0\u4e48\u662f VB.NET? Microsoft\u63a8\u51fa\u5168\u65b0\u7684\u7f16\u7a0b\u548c\u64cd\u4f5c\u7cfb\u7edfFramework\u2014\u2014.NET\uff0c\u652f\u6301\u591a\u79cd\u8bed\u8a00\u5229\u7528\u516c\u5171.NET\u5e93\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u5e94\u7528\u7a0b\u5e8f\u5728.NET Framework\u4e0a\u8fd0\u884c\u3002\u4f7f\u7528Visual Basic\u5728.NET Framework\u4e0a\u7f16\u7a0b\uff0c\u8fd9\u5c31\u662fVB.NET\u3002
\u9996\u5148\uff0c\u8ba9\u6211\u6f14\u793a\u5728VB.NET\u4e2d\u5199\u6700\u7b80\u5355\u7684\u63a7\u5236\u53f0\u7a0b\u5e8f\uff1aHello World\u3002
1.2 Hello, World!\u201cHello World!\u201d\u662f\u521d\u5b66\u8005\u5b66\u4e60Windows\u7f16\u7a0b\u7684\u4ee3\u8868\u6027\u7a0b\u5e8f\u3002\u6211\u4eec\u7684\u7b2c\u4e00\u4e2a\u7a0b\u5e8f\u5c31\u53eb\u505a\u201cHello VB.NET World!\u201d\u3002\u8be5\u7a0b\u5e8f\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u4e00\u53e5\u8bdd\uff1a\u201cHello VB.NET World!\u201d\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a
\u4ee3\u7801 1.1: Hello VB.NET World\u4f8b\u5b50Imports System
Module Module1
Sub Main()
System.Console.WriteLine("Hello VB.NET World!")
End Sub
End Module
1.3 VB.NET \u7f16\u8f91\u5668\u548c\u7f16\u8bd1\u5668\u4f60\u53ef\u4ee5\u5728\u8bb0\u4e8b\u672c\u6216VS.NET IDE\u7b49\u4efb\u610f\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u64b0\u5199\u4e0a\u8ff0\u4ee3\u7801\uff0c\u7136\u540e\u4fdd\u5b58\u4e3aHelloWorld.vb\u3002 \u4ee3\u7801\u7f16\u5199\u5b8c\u6210\u4e4b\u540e\uff0c\u8981\u4e48\u5728\u547d\u4ee4\u884c\u3001\u8981\u4e48\u5728VS.NET IDE\u4e2d\u7f16\u8bd1\u5b83\u3002\u5728Microsoft .NET Framework SDK\u4e2d\u5df2\u7ecf\u5305\u62ecVB.NET\u7f16\u8bd1\u5668vbc.exe[][1]\uff0c\u4eceIDE\u6216\u662f\u547d\u4ee4\u884c\u90fd\u53ef\u4ee5\u8c03\u7528\u3002\u8981\u4ece\u547d\u4ee4\u884c\u7f16\u8bd1HelloWorld.vb\uff0c\u8bf7\u5728\u547d\u4ee4\u884c\u7a97\u53e3\u8f93\u5165
vbc HelloWorld.vb /out:HelloWorld.exe /t:exe
\u7f16\u8bd1\u7ed3\u675f\u540e\uff0cHelloWorld.exe\u88ab\u521b\u5efa\u5230\u5f53\u524d\u76ee\u5f55\u4e0b\u3002\u5728\u8d44\u6e90\u7ba1\u7406\u5176\u4e2d\u53cc\u51fb\u56fe\u6807\u6216\u5728\u547d\u4ee4\u884c\u6267\u884c\uff0c\u7a0b\u5e8f\u6b63\u786e\u5730\u8fd0\u884c\u4e86\u3002\u795d\u8d3a\u4f60\u8fdb\u5165VB.NET\u5f00\u53d1\u8005\u7684\u884c\u5217\u3002
Imports \u8bed\u53e5
\u5982\u4f60\u6240\u77e5\uff0c\u5927\u90e8\u5206\u7684.NET\u7c7b\u578b\u90fd\u5728\u540d\u5b57\u7a7a\u95f4\uff08namespace\uff09\u4e2d\u5b9a\u4e49\u3002Namespace\u662f\u5b9a\u4e49\u548c\u7ba1\u7406\u7c7b\u522b\u7684\u8303\u7574\u3002\u5bdf\u770b.NET Framework Class Library\uff0c\u53ef\u4ee5\u770b\u5230\u6570\u4ee5\u767e\u8ba1\u7684namespace\u3002\u4f8b\u5982\uff0cSystem namespace\u5c31\u5305\u62ec\u4e86Console\u3001Object\u7b49\u7c7b\u578b\u5b9a\u4e49\u3002\u5982\u679c\u60f3\u4f7f\u7528Console\u7c7b\uff0c\u9700\u8981\u7528Imports\u6307\u4ee4\u5bfc\u5165System namespace\u3002\u5982\u4e0b\u6240\u793a\uff1a
Imports System\u751a\u81f3\u53ef\u4ee5\u660e\u786e\u5730\u8c03\u7528namespace\u800c\u65e0\u9700\u7528Import\u5bfc\u5165\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u5c55\u793a\u4e86\u4e0d\u7528Import\u7684\u201cHello World\uff01\u201d\u7a0b\u5e8f\uff1a
\u4ee3\u78011.2: Hello VB.NET World\u4f8b\u5b50Module Module1
Sub Main()
System.Console.WriteLine("Hello VB.NET World!")
End SubEnd Module1.4 \u89e3\u6790 "Hello VB.NET World!"\u7a0b\u5e8f\u7b2c\u4e00\u884c\u662f\uff1a
Imports System; System namespace\u5b9a\u4e49\u4e86Console\u7c7b\uff0c\u8be5\u7c7b\u7528\u4e8e\u8bfb\u5199\u63a7\u5236\u53f0\uff08\u547d\u4ee4\u884c\u7a97\u53e3\uff09\u3002\u7136\u540e\u4f60\u5b9a\u4e49\u4e86\u4e00\u4e2amodule\uff1aModule Module1
\u2026End Module\u6240\u6709\u7684VB\u7a0b\u5e8f\u90fd\u5305\u62ec\u4e00\u4e2aMain()\u65b9\u6cd5\uff0c\u5373\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u70b9\u3002\u5728\u4f8b\u5b50\u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u8c03\u7528Console.WriteLine()\u5411\u63a7\u5236\u53f0\u5199\u5165\u201cHello VB.NET World!\u201d\uff1a
Sub Main()
Console.WriteLine(\u201cHello VB.NET World!\u201d) End SubWriteLine()\u65b9\u6cd5\u5f52\u5c5e\u4e8eConsole\u7c7b\uff0c\u5b83\u8d1f\u8d23\u5411\u63a7\u5236\u53f0\u5199\u4e00\u4e2a\u5e26\u6709\u884c\u7ed3\u675f\u7b26\u7684\u5b57\u7b26\u4e32\u3002\u5982\u524d\u6240\u8ff0\uff0cConsole\u7c7b\u5b9a\u4e49\u4e8eSystem namespace\uff0c\u4f60\u901a\u8fc7\u76f4\u63a5\u5f15\u7528\u6765\u63a7\u5236\u7c7b\u6210\u5458\u3002
Console\u7c7b\u8d1f\u8d23\u8bfb\u5199\u7cfb\u7edf\u63a7\u5236\u53f0\u3002\u8bfb\u63a7\u5236\u53f0\u8f93\u5165\u7528Read\u548cReadLine\u65b9\u6cd5\uff0c\u5411\u63a7\u5236\u53f0\u8f93\u51fa\u7528WriteLine\u65b9\u6cd5\u3002
\u88681.1 Console\u7c7b\u5b9a\u4e49\u7684\u65b9\u6cd5
\u65b9\u6cd5 \u7528\u9014 \u4f8b\u5b50
Read \u8bfb\u5165\u5355\u4e2a\u5b57\u7b26 int i = Console.Read();
ReadLine \u8bfb\u5165\u4e00\u884c string str = Console.ReadLine();
Write \u5199\u4e00\u884c Console.Write("Write: 1");
WriteLine \u5199\u4e00\u884c\uff0c\u5e76\u5e26\u4e0a\u884c\u7ed3\u675f\u7b26
Console.WriteLine("Test Output Data with Line");
1.5 VB.NET\u6709\u4ec0\u4e48\u65b0\u7279\u70b9\uff1f VB.NET\u6bd4 VB6.0\u66f4\u52a0\u7a33\u5b9a\uff0c\u800c\u4e14\u5b8c\u5168\u9762\u5411\u5bf9\u8c61\u3002\u4e5f\u8bb8\u4f60\u8fd8\u8bb0\u5f97\uff0cVB6.0\u4e0d\u652f\u6301\u7ee7\u627f\u3001\u91cd\u8f7d\u548c\u63a5\u53e3\uff0c\u6240\u4ee5\u4e0d\u662f\u771f\u6b63\u9762\u5411\u5bf9\u8c61\u7684\u3002\u800cVB.NET\u5219\u652f\u6301\u8fd9\u4e9b\u9762\u5411\u5bf9\u8c61\u7279\u6027\u3002VB6.0\u6709\u4e24\u4e2a\u8584\u5f31\u73af\u8282\u2014\u2014\u591a\u7ebf\u7a0b\u548c\u5f02\u5e38\u5904\u7406\u3002\u5728VB.NET\u4e2d\uff0c\u5f00\u53d1\u591a\u7ebf\u7a0b\u5e94\u7528\u548c\u4f7f\u7528C++/C#\u522b\u65e0\u4e8c\u81f4\uff0c\u7ed3\u6784\u5316\u5f02\u5e38\u5904\u7406\u4e5f\u5f97\u5230\u652f\u6301\u3002\u7a0d\u540e\u6211\u4eec\u4f1a\u8be6\u7ec6\u89e3\u91ca\u8fd9\u4e9b\u7279\u6027\u3002
\u4e0b\u9762\u662fVB.NET\u7684\u7279\u6027\u5217\u8868\u2014\u2014
\u00b7\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u652f\u6301\u7ee7\u627f\u3001\u91cd\u8f7d\u3001\u63a5\u53e3\u3001\u5171\u4eab\u6210\u5458\u548c\u6784\u9020\u5668\u3002\u00b7\u652f\u6301\u6240\u6709\u7684CLS\u7279\u6027\uff0c\u5982\u5b58\u53d6\u63a7\u5236.NET\u7c7b\u3001\u4e0e\u5176\u5b83.NET\u8bed\u8a00\u4ea4\u4e92\u3001\u5143\u6570\u636e\u3001\u516c\u5171\u6570\u636e\u7c7b\u578b\u3001\u59d4\u6258\u7b49\u7b49\u3002\u00b7\u591a\u7ebf\u7a0b\u652f\u6301\u3002\u00b7\u7ed3\u6784\u5316\u5f02\u5e38\u5904\u7406\u3002 1.6 \u540d\u5b57\u7a7a\u95f4\u4e0e\u96c6\u5408 \u524d\u9762\u8ba8\u8bba\u4e86\u6211\u4eec\u7684\u7b2c\u4e00\u4e2aVB.NET\u7a0b\u5e8f\u3002\u8be5\u7a0b\u5e8f\u4e2d\u9996\u5148\u5f15\u4eba\u6ce8\u610f\u7684\u662f\u540d\u5b57\u7a7a\u95f4\uff08namespace\uff09\u3002\u5728.NET\u53c2\u8003\u6587\u6863\u4e2d\uff0c\u4f60\u4f1a\u53d1\u73b0\u6bcf\u4e2a\u7c7b\u90fd\u5f52\u5c5e\u4e8e\u67d0\u4e2anamespace\u3002\u90a3\u4e48\uff0cnamespace\u5230\u5e95\u662f\u4ec0\u4e48\uff1f
\u4e00\u4e2anamespace\u662f\u7c7b\u548c\u7ec4\u4ef6\u7684\u903b\u8f91\u7ec4\u5408\uff0c\u5176\u76ee\u7684\u5728\u4e8e\u5c06.NET class\u6309\u7c7b\u522b\u5b9a\u4e49\u3002\u5fae\u8f6f\u501f\u7528\u4e86C++ class packaging\u6982\u5ff5\uff1anamespace\u6765\u63cf\u8ff0\u8fd9\u79cd\u7ec4\u5408\u3002.NET Framework\u4e2d\u7684\u7ec4\u4ef6\u88ab\u79f0\u4e3a\u96c6\u5408\uff08assembly\uff09\u3002\u5168\u90e8.NET\u4ee3\u7801\u5728\u6570\u767e\u4e2a\u5e93\u6587\u4ef6\uff08DLL\uff09\u4e2d\u5b9a\u4e49\u3002Namespace\u628aassembly\u4e2d\u5b9a\u4e49\u7684\u7c7b\u7ec4\u7ec7\u8d77\u6765\u3002\u4e00\u4e2anamespace\u53ef\u4ee5\u5305\u62ec\u591a\u4e2aassembly\uff0c\u4e00\u4e2aassembly\u4e5f\u53ef\u4ee5\u5728\u591a\u4e2anamespace\u4e2d\u5b9a\u4e49\u3002 namespace\u6811\u7684\u6839\u8282\u70b9\u662fSystem namespace\u3002\u5728.NET Library\u4e2d\uff0c\u6bcf\u4e2aclass\u90fd\u5728\u4e00\u7ec4\u76f8\u4f3c\u7684\u7c7b\u522b\u4e2d\u5b9a\u4e49\u3002\u4f8b\u5982\uff0cSystem.Data namespace\u53ea\u5305\u62ec\u6570\u636e\u76f8\u5173\u7c7b\u3002\u540c\u6837\uff0cSystem.Multithreading\u53ea\u5305\u62ec\u591a\u7ebf\u7a0b\u7c7b\u3002
\u5728\u4f7f\u7528.NET\u652f\u6301\u7684\u8bed\u8a00\uff08\u5982C#\u3001VB.NET\u3001C++.NET\u7b49\uff09\u521b\u5efa\u65b0\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u4f60\u4f1a\u6ce8\u610f\u5230\u6bcf\u4e2a\u5e94\u7528\u7a0b\u5e8f\u90fd\u88ab\u5b9a\u4e49\u4e3a\u4e00\u4e2anamespace\uff0c\u800c\u6240\u6709\u7684class\u90fd\u5f52\u5c5e\u4e8e\u8fd9\u4e2anamespace\u3002\u901a\u8fc7\u5f15\u7528\u8fd9\u4e2anamespace\uff0c\u5176\u5b83\u5e94\u7528\u7a0b\u5e8f\u5c31\u80fd\u5b58\u53d6\u8fd9\u4e9bclass\u3002 \u5728.NET\u4e2d\uff0c\u4ee3\u7801\u88ab\u7f16\u8bd1\u4e3a\u4e2d\u95f4\u8bed\u8a00\uff08Intermediate Language\uff0cIL\uff09\uff0cassembly\u4e2d\u5b58\u50a8\u4e86IL\u4ee3\u7801\u3001\u5143\u6570\u636e\u548c\u5176\u5b83\u8d44\u6e90\u6587\u4ef6\u3002\u540c\u4e00\u4e2aassembly\u53ef\u4ee5\u9644\u5c5e\u4e8e\u4e00\u4e2a\u6216\u591a\u4e2aExe/DLL\u3002\u6240\u6709\u7684.NET\u5e93\u90fd\u5b58\u50a8\u5728assembly\u4e2d\u3002
1.7 VB.NET: \u5b8c\u5168\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u62bd\u8c61\u3001\u5c01\u88c5\u3001\u591a\u6001\u3001\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u7684\u56db\u4e2a\u57fa\u672c\u5c5e\u6027\u3002VB6.0\u4e0d\u652f\u6301\u7ee7\u627f\uff0c\u800cVB.NET\u5219\u4e0d\u7136\u3002\u6240\u4ee5\uff0c\u548cC++\u4e00\u6837\uff0cVB.NET\u4e5f\u662f\u5b8c\u5168\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u3002
Class \u548c ModuleVB.NET\u7528Class...End Class\u8bed\u53e5\u5bf9\u521b\u5efaclass\u3002\u6bcf\u4e2aVB.NET\u81f3\u5c11\u5305\u62ec\u4e00\u4e2aModule\uff08\u6a21\u5757\uff09\u3002Module\u5728Module\u2026End Module\u8bed\u53e5\u5bf9\u4e2d\u5b9e\u73b0\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u8981\u6a21\u5757\u662fMain\u65b9\u6cd5\uff0c\u4ea6\u5373\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u70b9\u3002
\u548cVB6.0\u76f8\u4f3c\u7684\u5730\u65b9\u662f\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528Function/Sub\u5173\u952e\u5b57\u5b9a\u4e49\u65b9\u6cd5\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u663e\u793a\u4e86\u5982\u4f55\u521b\u5efaclass\u3001\u6dfb\u52a0\u65b9\u6cd5\uff0c\u5e76\u4ece\u4e3b\u7a0b\u5e8f\u8c03\u7528\u65b9\u6cd5\uff1a Imports System
Module Module1
Sub Main()
Dim cls As TestClass = New TestClass
Console.WriteLine(cls.MyMethod)
End Sub
Class TestClass
Function MyMethod() As String
Return "Test Method"
End Function
End Class
End ModuleProperty\u5c5e\u6027\uff08Property\uff09\u662f\u7c7b\u53d8\u91cf\u7684\u516c\u5171\u63cf\u8ff0\u3002Property\u2026End Property\u8bed\u53e5\u7528\u4ee5\u521b\u5efaproperty\u3002\u5c5e\u6027\u7684Get/Set\u65b9\u6cd5\u5206\u522b\u7528\u4e8e\u53d6\u5f97\u548c\u8bbe\u7f6e\u5c5e\u6027\u503c\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0cData\u662fTestClass\u7684\u5c5e\u6027\u3002
Imports System
Imports System.Console
Module Module1
Sub Main()
Dim cls As TestClass = New TestClass
WriteLine(cls.MyMethod)
WriteLine(cls.Data)
cls.Data = "New Data"
WriteLine(cls.Data)
End Sub
End Module
Class TestClass
Private strData As String = "Some Data"
Function MyMethod() As String
Return "Test Method!"
End Function
' Adding Data property to the class
Public Property Data() As String
Get
Return strData
End Get
Set(ByVal Value As String)
strData = Value
End Set
End Property
\u91cd\u8f7dVB.NET\u901a\u8fc7overload\u5173\u952e\u5b57\u652f\u6301\u65b9\u6cd5\u91cd\u8f7d\u3002\u4f7f\u7528\u8fd9\u4e2a\u5173\u952e\u5b57\uff0c\u4f60\u53ef\u4ee5\u5b9a\u4e49\u540c\u540d\u4f46\u4e0d\u540c\u53c2\u6570\u7684\u65b9\u6cd5\u3002
\u7c7b\u6210\u5458\u8bbf\u95ee\u57df
\u9664\u4e86\u539f\u6709\u7684Private\u548cPublic\uff0cVB.NET\u5f15\u5165\u4e86\u51e0\u4e2a\u65b0\u5173\u952e\u5b57\u3002\u5168\u90e8\u8bbf\u95ee\u57df\u5173\u952e\u5b57\u5217\u8868\u5982\u4e0b\uff1a
\u5173\u952e\u5b57 \u4f5c\u7528\u57df
Private \u9650\u4e8eclass\u5185\u90e8
Public \u53ef\u4ee5\u4ececlass\u5916\u8bbf\u95ee
Friend \u9650\u4e8eclass\u6240\u5c5e\u7684\u5e94\u7528\u7a0b\u5e8f\u5185
Protected \u53ea\u80fd\u88abclass\u548c\u5176\u6d3e\u751f\u7c7b\u8bbf\u95ee
Protected Friend \u80fd\u88abclass\u3001\u5e94\u7528\u7a0b\u5e8f\u548c\u6d3e\u751f\u7c7b\u8bbf\u95ee
\u7ee7\u627f\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u8bed\u8a00\u4e2d\u6700\u5e38\u7528\u7684\u6280\u672f\u3002\u7ee7\u627f\u8ba9\u4f60\u80fd\u591f\u91cd\u7528\u7c7b\u4ee3\u7801\u548c\u529f\u80fd\u3002
VB.NET\u652f\u6301\u7ee7\u627f\uff0c\u800cVB6.0\u5219\u4e0d\u652f\u6301\u3002\u7ee7\u627f\u7684\u597d\u5904\u5728\u4e8e\u4f60\u80fd\u4f7f\u7528\u4efb\u4f55\u4eba\u7f16\u5199\u7684\u7c7b\uff0c\u4ece\u8fd9\u4e9b\u7c7b\u6d3e\u751f\u81ea\u5df1\u7684\u7c7b\uff0c\u7136\u540e\u5728\u81ea\u5df1\u7684\u7c7b\u4e2d\u8c03\u7528\u7236\u7c7b\u529f\u80fd\u3002\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0cClass B\u6d3e\u751f\u81eaClass A\uff0c\u6211\u4eec\u5c06\u4eceClass B\u4e2d\u8c03\u7528Class A\u7684\u65b9\u6cd5MethodA\u3002
Imports System
Imports System.Console
Module Module1
Sub Main()
Dim bObj As B = New B
WriteLine(bObj.MethodA())
End Sub
End Module
' Class A defined
Public Class A
Function MethodA() As String
Return "Method A is called."
End Function
End Class
'Class B, inherited from Class A. All members (Public and Protected)
' can be access via B now.
Public Class B
Inherits A
Function MethodB() As String
Return "Method B is called."
End Function
End Class
\u53ef\u4ee5\u4ece\u4e00\u4e2aclass\u4e2d\u6d3e\u751f\u591a\u4e2a\u81ea\u5b9a\u4e49class\uff0c\u4e5f\u53ef\u4ee5\u4ece\u591a\u4e2aclass\u6d3e\u751f\u4e00\u4e2a\u81ea\u5b9a\u4e49class\u3002
\u5171\u4eab\u7684\u6210\u5458\u7c7b\u7684\u5171\u4eab\u6210\u5458\u88ab\u7c7b\u7684\u6240\u6709\u5b9e\u4f53\u5171\u4eab\u3002\u5171\u4eab\u6210\u5458\u53ef\u80fd\u662f\u5c5e\u6027\u3001\u65b9\u6cd5\u6216\u5b57\u6bb5/\u503c\u57df\u3002\u5728\u4f60\u4e0d\u60f3\u8ba9\u7528\u6237\u5168\u9762\u63a7\u5236\u81ea\u5df1\u7684\u7c7b\u65f6\uff0c\u5171\u4eab\u6210\u5458\u76f8\u5f53\u6709\u7528\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5f00\u53d1\u4e00\u4e2a\u7c7b\u5e93\uff0c\u8ba9\u7528\u6237\u901a\u8fc7\u5171\u4eab\u6210\u5458\u4f7f\u7528\u5176\u4e2d\u7684\u90e8\u5206\u529f\u80fd\u3002
\u53ef\u4ee5\u901a\u8fc7class\u672c\u8eab\u5f15\u7528\u5171\u4eab\u6210\u5458\uff0c\u800c\u65e0\u9700\u901a\u8fc7\u7c7b\u7684\u5b9e\u4f53\u3002\u4f8b\u5982\uff1aModule Module1
Sub Main()
WriteLine(A.MethodA())
End Sub
End Module
' Class A defined
Public Class A
Shared Function MethodA() As String
Return "Method A is called."
End Function
End Class
\u591a\u7ebf\u7a0bVB\u8bed\u8a00\u7684\u4e00\u5927\u5f31\u70b9\u5c31\u662f\u7f3a\u4e4f\u7f16\u5199\u81ea\u7531\u7ebf\u7a0b\uff08free-threaded\uff09\u7a0b\u5e8f\u7684\u80fd\u529b\u3002\u5728.NET Framework\u4e2d\uff0c\u6240\u6709\u8bed\u8a00\u5171\u4eabCRL\uff08Common Runtime Library\uff0c\u516c\u5171\u8fd0\u884c\u5e93\uff09\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ef\u4ee5\u7528VB.NET\u3001C#\u6216\u5176\u5b83.NET\u8bed\u8a00\u7f16\u5199\u540c\u6837\u7684\u7a0b\u5e8f\u3002
System.Threading namespace\u5b9a\u4e49\u4e86\u7ebf\u7a0b\u7c7b\u3002\u6211\u4eec\u53ea\u9700\u8981\u5f15\u5165System.Threading namespace\uff0c\u5373\u53ef\u4f7f\u7528\u7ebf\u7a0b\u7c7b\u3002
System.Threading.Thread\u7c7b\u63d0\u4f9b\u7ebf\u7a0b\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528Thread\u7c7b\u521b\u5efa\u6216\u7834\u574f\u7ebf\u7a0b\u3002
\u521b\u5efa\u7ebf\u7a0b\u4f7f\u7528Thread\u7c7b\u7684\u5b9e\u4f53\u521b\u5efa\u4e00\u4e2a\u65b0\u7ebf\u7a0b\uff0c\u7136\u540e\u7528Thread.Start\u65b9\u6cd5\u5f00\u59cb\u6267\u884c\u7ebf\u7a0b\u3002\u7ebf\u7a0b\u6784\u9020\u5668\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8be5\u53c2\u6570\u6307\u660e\u4f60\u8981\u5728\u7ebf\u7a0b\u4e2d\u6267\u884c\u7684procedure\u3002\u5728\u4e0b\u4f8b\u4e2d\uff0c\u6211\u60f3\u5728oThread1\uff08Thread\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f53\uff09\u7684\u7b2c\u4e8c\u7ebf\u7a0b\u4e2d\u6267\u884cSecondThread\u8fc7\u7a0b\uff1a
oThread1 = New Thread(AddressOf SecondThread)
SecondThread procedure looks like below:
Public Sub SecondThread()
Dim i As Integer
For i = 1 To 10
Console.WriteLine(i.ToString())
Next
End Sub
\u7136\u540e\uff0c\u8c03\u7528Thread.Start()\u5f00\u59cb\u7ebf\u7a0b\uff1a
oThread1.Start()
\u4e0b\u9762\u7684\u4ee3\u7801\u521b\u5efa\u4e24\u4e2a\u7b2c\u4e8c\u7ebf\u7a0b\uff1a
Imports System
Imports System.Threading
Module Module1
Public oThread1 As Thread
Public oThread2 As Thread
Sub Main()
oThread1 = New Thread(AddressOf SecondThread)
oThread2 = New Thread(AddressOf ThirdThread)
oThread1.Start()
oThread2.Start()
End Sub
Public Sub SecondThread()
Dim i As Integer
For i = 1 To 10
Console.WriteLine(i.ToString())
Next
End Sub
Public Sub ThirdThread()
Dim i As Integer
For i = 1 To 10
Console.WriteLine("A" + i.ToString())
Next
End Sub
End Module
\u7834\u574f\u7ebf\u7a0b \u8c03\u7528Abort\u65b9\u6cd5\u6765\u7834\u574f\uff08\u4e2d\u6b62\uff09\u4e00\u4e2a\u7ebf\u7a0b\u3002\u5728\u8c03\u7528Abort\u4e4b\u524d\uff0c\u786e\u4fdd\u7528IsAlive\u5224\u65ad\u7ebf\u7a0b\u5904\u4e8e\u6d3b\u52a8\u72b6\u6001\u3002
If oThread1.IsAlive Then
oThread1.Abort()
End If
\u6682\u505c\u7ebf\u7a0b\u53ef\u4ee5\u4f7f\u7528Sleep\u65b9\u6cd5\u6765\u6682\u505c\u7ebf\u7a0b\u6267\u884c\u3002Sleep\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\u7684\u53c2\u6570\uff0c\u6307\u660e\u7ebf\u7a0b\u5e94\u5f53\u6682\u505c\u591a\u957f\u65f6\u95f4\u3002
\u4e0b\u9762\u7684\u4f8b\u5b50\u8ba9\u7ebf\u7a0b\u6682\u505c1\u79d2\u949f\uff1a
oThread2.Sleep(1000)\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528Suspend\u548cResume\u65b9\u6cd5\u6765\u6302\u8d77\u548c\u7ee7\u7eed\u7ebf\u7a0b\u6267\u884c\u3002
\u8bbe\u5b9a\u7ebf\u7a0b\u4f18\u5148\u7ea7Thread\u7c7b\u7684Priority\u5c5e\u6027\u7528\u4e8e\u8bbe\u5b9a\u7ebf\u7a0b\u4f18\u5148\u7ea7\u3002\u8be5\u5c5e\u6027\u53ef\u4ee5\u8bbe\u7f6e\u4e3aNormal\uff0cAboveNormal\uff0cBelowNormal\uff0cHighest\u548cLowest\u3002\u5982\uff1a
oThread2.Priority = ThreadPriority.Highest\u7ebf\u7a0b\u4e0eApartment\u4f7f\u7528ApartmentState\u5c5e\u6027\u8bbe\u7f6e\u7ebf\u7a0b\u7684apartment\u7c7b\u578b\uff0c\u8be5\u5c5e\u6027\u503c\u53ef\u4ee5\u4e3aSTA\uff0cMTA\u6216\u662fUnknown[][2]\uff1a
oThread.ApartmentState = ApartmentState.MTAMTS\u610f\u5473\u7740\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u6a21\u5f0f\uff0c\u800cSTA\u5219\u53ea\u80fd\u662f\u5355\u7ebf\u7a0b\u6267\u884c\u3002
Public Enum ApartmentState
{
STA = 0,
MTA = 1,
Unknown = 2,
}
1.8 \u7ed3\u6784\u5316\u5f02\u5e38\u5904\u7406\u5f02\u5e38\u5904\u7406\u4e5f\u88ab\u79f0\u4e4b\u4e3a\u9519\u8bef\u5904\u7406\u3002\u4f5c\u4e3aVB\u7a0b\u5e8f\u5458\uff0c\u4f60\u4e00\u5b9a\u5bf9On Error Goto\u548cOn Error Resume Next\u8fd9\u4e9bVB6.0\u9519\u8bef\u5904\u7406\u8bed\u53e5\u8033\u719f\u80fd\u8be6\u3002\u8fd9\u79cd\u7c7b\u578b\u7684\u9519\u8bef\u5904\u7406\u88ab\u79f0\u4e3a\u975e\u7ed3\u6784\u5316\u5f02\u5e38\u5904\u7406\uff08Unstructured Exception Handling\uff09\u3002\u800c\u5728VB.NET\u4e2d\uff0cMicrosoft\u63a8\u51fa\u4e86\u7ed3\u6784\u5316\u5f02\u5e38\u5904\u7406\u673a\u5236\u3002VB.NET\u652f\u6301\u7c7b\u4f3cC++\u7684TryCatch..Finally\u63a7\u5236\u3002Try..Catch..Finally\u7ed3\u6784\u5982\u4e0b\uff1a Try
' \u53ef\u80fd\u5bfc\u81f4\u5f02\u5e38\u7684\u4ee3\u7801
Catch
' \u5f53\u5f02\u5e38\u53d1\u751f\u65f6\u5904\u7406\u5f02\u5e38\u7684\u4ee3\u7801
Finally
' \u6e05\u7406\u73b0\u573a
End Try
Try\u8bed\u53e5\u5757\u7528\u4ee5\u629b\u51fa\u5f02\u5e38\u3002\u5982\u679c\u5f02\u5e38\u53d1\u751f\uff0c\u5728Catch\u8bed\u53e5\u5757\u4e2d\u5904\u7406\u3002Finally\u8bed\u53e5\u5757\u662f\u53ef\u9009\u7684\uff0c\u5728\u9700\u8981\u91ca\u653e\u8d44\u6e90\u65f6\u7279\u522b\u6709\u7528\u3002
1.9 VB6.0\u4e0eVB.NET\u7684\u4e0d\u540c\u4e4b\u5904\u9664\u4e86\u4e0a\u9762\u8c08\u5230\u7684\u8bed\u8a00\u8fdb\u5316\uff0c\u8fd8\u6709\u4e00\u4e9b\u8bed\u6cd5\u4e0a\u7684\u53d8\u5316\u3002\u6240\u6709\u8fd9\u4e9b\u8bed\u8a00\u548c\u8bed\u6cd5\u7684\u53d8\u5316\u5728MSDN\u4e2d\u5747\u53ef\u67e5\u5230\uff0c\u672c\u6587\u53ea\u4f5c\u7b80\u5355\u4ecb\u7ecd\u3002
\u6570\u636e\u7c7b\u578b\uff08Data Type\uff09\u7684\u6539\u53d8VB.NET\u4e2d\u6709\u4e9b\u6570\u636e\u7c7b\u578b\u5f97\u5230\u6539\u8fdb\u3002\u4e0b\u9762\u662f\u53d8\u5316\u5bf9\u7167\u8868\u3002
\u6570\u636e\u7c7b\u578b VB6.0 VB.NET
Integer 16 bit size 32 bit size
Long 32 bit size 64 bit size
Currency \u7528\u4e8e\u5b58\u50a8\u5927\u6d6e\u70b9\u6570 \u88abdecimal\u66ff\u4ee3\uff0c\u652f\u6301\u66f4\u9ad8\u7cbe\u5ea6
Variant \u53ef\u4ee5\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u6570\u636e \u88abObject\u7c7b\u578b\u66ff\u4ee3\uff0c\u4e5f\u53ef\u4ee5\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u6570\u636e\uff0c\u4f46\u7ed3\u679c\u66f4\u597d
Date Date\u7c7b\u578b\u88ab\u5b58\u50a8\u4e3adouble \u5f15\u5165DateTime\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u4e0d\u540c\u683c\u5f0f\u7684\u65e5\u671f
\u5728VB.NET\u4e2d\uff0cShort\u6570\u636e\u7c7b\u578b\u662f16 bit\u7684\u3002Short\uff0cInteger\u548cLong\u90fd\u7b49\u540c\u4e8eCLR\u7684System.Int16\u3001System.Int32\u548cSystem.Int64\u7c7b\u578b\u3002 \u53d8\u91cf\u58f0\u660e\u7684\u53d8\u5316\u5728VB6.0\u4e2d\uff0c\u53d8\u91cf\u58f0\u660e\u6709\u8bb8\u591a\u9650\u5236\u3002\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u4e0d\u80fd\u540c\u884c\u58f0\u660e\u591a\u4e2a\u53d8\u91cf\u3002\u5982\u679c\u4e00\u5b9a\u8981\u5728\u4e00\u884c\u4e2d\u58f0\u660e\u591a\u4e2a\u53d8\u91cf\uff0c\u5c31\u4e00\u5b9a\u5f97\u6307\u660e\u6bcf\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u5426\u5219\u5c06\u88ab\u9ed8\u8ba4\u4e3aVariant\u7c7b\u578b\u3002
Dim a1, a2 As Integer Dim a3 As Integer, a4 As Integer \u7b2c\u4e00\u884c\u4e2d\u7684a1\u662fVariant\u7c7b\u578b\uff0ca2\u662fInteger\u7c7b\u578b\u3002\u7b2c\u4e8c\u884c\u4e2d\u4e24\u4e2a\u53d8\u91cf\u90fd\u662fInteger\u7c7b\u578b\u3002VB.NET\u652f\u6301\u540c\u884c\u58f0\u660e\u591a\u4e2a\u53d8\u91cf\uff0c\u4e3e\u4f8b\u5982\u4e0b\uff1a
Dim a1, a2, a3 As Integer \u53d8\u91cf\u521d\u59cb\u5316\u662f\u53e6\u4e00\u4e2a\u95ee\u9898\u3002\u5728VB6.0\u4e2d\u4e0d\u80fd\u540c\u65f6\u58f0\u660e\u548c\u521d\u59cb\u5316\u53d8\u91cf\uff0c\u800cVB.NET\u5219\u652f\u6301\u8fd9\u4e2a\u7279\u6027\u3002
Dim name As String = "Mahesh"System.Console.Write(name) \u58f0\u660e\u5e38\u91cf\u4e5f\u53ef\u4ee5\u7167\u6b64\u529e\u7406\uff1aConst DT_COUNT As Integer = 23 New\u5173\u952e\u5b57\u3002\u5728VB.NET\u4e2d\uff0cNew\u5173\u952e\u5b57\u7528\u4e8e\u521b\u5efa\u5bf9\u8c61\u3002\u7531\u4e8e\u6570\u636e\u7c7b\u578b\u662f\u5bf9\u8c61\uff0c\u6240\u4ee5New\u5173\u952e\u5b57\u7528\u4ee5\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\u5bf9\u8c61\u3002
Dim i As Integer = New Integer()i = 10System.Console.WriteLine(i.ToString()) \u4ee3\u7801\u5757\u7ea7\u522b\u652f\u6301\u3002\u50cfC++\u4e00\u6837\uff0cVB.NET\u652f\u6301\u4ee3\u7801\u5757\u7ea7\u522b\u7684\u4f5c\u7528\u57df\u68c0\u67e5\u3002\u5728\u8bed\u53e5\u5757\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\u53ea\u5728\u5757\u5185\u6709\u6548\u3002
For i = 1 To 10Dim p As LongSystem.Console.WriteLine(i.ToString())NextSystem.Console.WriteLine(p.ToString()) \u8fd9\u6bb5\u4ee3\u7801\u5728VB.NET\u4e2d\u4f1a\u5f97\u5230\u4e00\u4e2a\u7f16\u8bd1\u9519\u8bef\uff0c\u56e0\u4e3ap\u5728For..Next\u8bed\u53e5\u5757\u4e4b\u5916\u4e0d\u53ef\u8bbf\u95ee\u3002\u5728VB6.0\u4e2d\u8fd9\u6bb5\u4ee3\u7801\u53ef\u4ee5\u901a\u8fc7\u3002
\u6539\u8fdb\u4e86\u7684\u7c7b\u578b\u5b89\u5168
\u5728VB6.0\u4e2d\uff0c\u5f53\u4f60\u58f0\u660e\u4e00\u4e2a\u5bf9\u5916\u90e8\u8fc7\u7a0b\u7684\u5f15\u7528\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u4efb\u610f\u7c7b\u578b\u7684\u53c2\u6570\u4e3aAs Any\u3002Any\u5173\u952e\u5b57\u7981\u6b62\u4e86\u7c7b\u578b\u68c0\u67e5\uff0c\u5141\u8bb8\u4efb\u610f\u6570\u636e\u7c7b\u578b\u4f20\u5165\u548c\u8fd4\u56de\u3002
VB.NET\u4e0d\u652f\u6301Any\u5173\u952e\u5b57\u3002\u4f60\u5fc5\u987b\u6307\u5b9a\u6bcf\u4e2a\u53c2\u6570\u548c\u8fd4\u56de\u503c\u7684\u6570\u636e\u7c7b\u578b\u3002\u6570\u7ec4VB.NET\u5bf9\u6570\u7ec4\u4f5c\u4e86\u660e\u663e\u7684\u6539\u52a8\u3002
\u6570\u7ec4\u8303\u56f4\u3002\u5728VB.NET\u4e2d\uff0c\u4f60\u9700\u8981\u683c\u5916\u7559\u610f\u6570\u7ec4\u8303\u56f4\u95ee\u9898\u3002VB6.0\u9ed8\u8ba4\u6570\u7ec4\u4e0b\u754c\u4e3a0\uff0c\u6545\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u7b49\u4e0e\u6570\u7ec4\u4e0a\u754c\u503c\u52a0\u4e00\u3002\u4e0b\u9762\u7684\u6570\u7ec4\u754c\u9650\u4eceA(0)\u5230A(10)\uff0c\u5171\u670911\u4e2a\u5143\u7d20\uff1a
Dim A(10) As Single\u53ef\u4ee5\u4f7f\u7528Option Base\u6539\u53d8\u4e0b\u754c\u503c\u4e3a1\u3002\u5728VB.NET\u4e2d\uff0c\u6570\u7ec4\u548cC++\u4e00\u6837\uff0c\u4e0b\u754c\u503c\u4e3a0\uff0c\u4e0d\u652f\u6301Option Base\u3002\u6ce8\u610f\uff1aMSDN\u6587\u6863\u6307\u51fa\u6570\u7ec4\u53ea\u80fd\u5305\u62ec\u4e0e\u5176\u5c3a\u5bf8\u76f8\u7b49\u7684\u5143\u7d20\u6570\u91cf\uff0c\u4f8b\u5982\uff1aDim A(10) As Integer \u53ea\u80fd\u5305\u62ec10\u4e2a\u5143\u7d20\uff08\u4eceA(0)\u5230A(9)\uff09\uff0c\u4f46\u5728\u7f16\u8bd1\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u65f6\u6211\u53d1\u73b0\u5b83\u8fd0\u884c\u826f\u597d\uff0c\u770b\u8d77\u6765\u6570\u7ec4\u4e2d\u5bb9\u7eb3\u4e8611\u4e2a\u5143\u7d20\u3002
Dim A(10) As Integer A(0) = 12 A(2) = 24 A(10) = 23 System.Console.WriteLine(A(0).ToString()) System.Console.WriteLine(A(10).ToString())System.Console.WriteLine(UBound(A).ToString()) System.Console.WriteLine(LBound(A).ToString()) Lbound\u548cUbound\u5206\u522b\u8fd4\u56de 0\u4e0e10\u3002ReDim\u548cFixed Array\u3002\u4f60\u53ef\u4ee5\u5728VB6.0\u4e2d\u6307\u5b9a\u56fa\u5b9a\u957f\u5ea6\u7684\u6570\u7ec4\u3002
Dim ArrWeekDays(0 To 6) As Integer
\u8fd9\u91cc\u7684ArrWeekDays\u6570\u7ec4\u662f\u56fa\u5b9a\u957f\u5ea6\u7684\uff0c\u4e0d\u80fd\u7528ReDim\u8bed\u53e5\u6539\u53d8\u957f\u5ea6\u3002VB.NET\u4e0d\u652f\u6301\u56fa\u5b9a\u957f\u5ea6\u6570\u7ec4\uff0c\u6240\u4ee5ReDim\u603b\u662f\u6709\u6548\u3002
\u53ef\u4ee5\u7528\u4e0b\u9762\u4e24\u79cd\u65b9\u5f0f\u58f0\u660e\u6570\u7ec4\uff1a Dim ArrWeekDays(6) As IntegerDim ArrWeekDays() As Integer = {1, 2, 3, 4, 5, 6} ReDim\u8bed\u53e5\u3002\u5728VB6.0\u4e2d\uff0cReDim\u7528\u4e8e\u521d\u59cb\u5316\u52a8\u6001\u6570\u7ec4\u3002\u5728VB.NET\u4e2d\u4f60\u4e0d\u80fd\u628a\u5b83\u5f53\u4f5c\u58f0\u660e\u7528\u3002ReDim\u53ea\u80fd\u7528\u4e8e\u6539\u53d8\u6570\u7ec4\u957f\u5ea6\uff0c\u4e0d\u8fc7\u4e0d\u80fd\u6539\u53d8\u6570\u7ec4\u7ef4\u5ea6\u3002
Variant\u5bf9\u9635ObjectVB6.0\u4e2d\u7684Variant\u6570\u636e\u7c7b\u578b\u80fd\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u53d8\u91cf\uff0cVB.NET\u4e2dObject\u5177\u5907\u76f8\u540c\u80fd\u529b\u3002
\u7b97\u672f\u64cd\u4f5c\u7b26VB.NET\u652f\u6301\u7c7b\u4f3cC++\u7684\u5feb\u6377\u65b9\u5f0f\u3002\u4e0b\u9762\u7684\u8868\u683c\u663e\u793a\u4e86\u5e38\u89c4\u64cd\u4f5c\u4e0e\u5feb\u6377\u64cd\u4f5c\u7684\u4e0d\u540c\u4e4b\u5904\u3002\u5feb\u6377\u65b9\u5f0f\u4e5f\u53ef\u7528\u4e8e*\u3001/\u3001|\u3001&\u7b49\u64cd\u4f5c\u7b26\u3002
\u64cd\u4f5c\u7b26 \u5e38\u89c4\u8bed\u6cd5 \u5feb\u6377\u65b9\u5f0f\u52a0\u6cd5 A = A+5 A +=5 \u51cf\u6cd5 A = A \u2013 5 A -+ 5\u56fa\u5b9a\u957f\u5ea6\u5b57\u7b26\u4e32
\u5728VB6.0\u4e2d\uff0c\u53ef\u4ee5\u5728\u58f0\u660e\u5b57\u7b26\u4e32\u65f6\u6307\u5b9a\u5176\u957f\u5ea6\u3002VB.NET\u4e0d\u652f\u6301\u56fa\u5b9a\u957f\u5ea6\u5b57\u7b26\u4e32\u3002
\u5e03\u5c14\u64cd\u4f5c\u7b26VB6.0\u4e2d\u7684And\u3001Or\u6216\u662fXor\u8bed\u53e5\u662f\u6309\u4f4d\u64cd\u4f5c\u7b26\u3002\u800c\u5728VB.NET\u4e2d\uff0c\u5b83\u4eec\u662f\u5e03\u5c14\u64cd\u4f5c\u7b26\u3002\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\u5c06\u8fd4\u56detrue\u6216false\u3002VB.NET\u5f15\u5165\u65b0\u64cd\u4f5c\u7b26\u6765\u5b8c\u6210\u6309\u4f4d\u64cd\u4f5c\u3002
\u64cd\u4f5c\u7b26 \u63cf\u8ff0 BitAnd \u6309\u4f4dAndBitOr \u6309\u4f4dOrBitXor \u6309\u4f4dXorBitNot \u6309\u4f4dNot\u7ed3\u6784\u4e0e\u81ea\u5b9a\u4e49\u7c7b\u578b\u5728VB6.0\u4e2d\uff0c\u4f60\u4f7f\u7528Type\u2026End Type\u8bed\u53e5\u5757\u521b\u5efa\u7ed3\u6784\u6216\u81ea\u5b9a\u4e49\u7c7b\u578b\u3002\u4f8b\u5982\uff1a
Type StdRec
StdId As Integer
StdName As String End Type
VB.NET\u5f15\u5165\u65b0\u7684\u8bed\u6cd5\uff1aStructure\u3002Type\u2026End Type\u4e0d\u518d\u88ab\u652f\u6301\u3002Structure\u2026End Structure\u4e0eC++\u7528\u6cd5\u76f8\u540c\u3002\u53ef\u4ee5\u6307\u5b9a\u7ed3\u6784\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u53ef\u8bbf\u95ee\u57df\uff0c\u5982Public\u3001Protected\u3001Friend\u3001Protected Friend\u3001Private\u7b49\u3002\u4f8b\u5982\uff1a
Structure StdRec
Public StdId As Integer Public StdName As String
Private StdInternal As String End StructureVB.NET\u4e2d\u7684Structures\u5c31\u50cf\u7c7b\u4e00\u6837\uff0c\u4e5f\u53ef\u4ee5\u62e5\u6709\u65b9\u6cd5\u548c\u5c5e\u6027\u3002New\u548cNothing\u5173\u952e\u5b57VB6.0\u4e2d\uff0cAS New\u548cNothing\u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e\u4e00\u4e2a\u5bf9\u8c61\u5e76\u521d\u59cb\u5316\u5b83\u3002 VB.NET\u4e0d\u652f\u6301\u9690\u5f0f\u521b\u5efa\u5bf9\u8c61\u3002\u5982\u524d\u6240\u8a00\uff0c\u751a\u81f3\u8fde\u6570\u636e\u7c7b\u578b\u90fd\u662f\u5bf9\u8c61\u3002\u4f60\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u521b\u5efa\u6570\u636e\u7c7b\u578b\u6216\u5bf9\u8c61\uff1a Dim i As Integer Dim i As Integer = New Integer() // Do something if i = Nothing Then End If \u4e0d\u652f\u6301Set\u8bed\u53e5VB6.0\u4f7f\u7528Set\u8bed\u53e5\u6307\u6d3e\u5bf9\u8c61\u3002\u4f8b\u5982\uff1aSet myObj = new MyObjectSet a = b\u5728VB.NET\u4e2d\uff0c\u4e0d\u9700\u8981\u4f7f\u7528Set\u6307\u6d3e\u5bf9\u8c61\u3002\u4f8b\u5982\uff1amyObj = new MyObj()a = b\u8fc7\u7a0b\uff08procedure\uff09\u8bed\u6cd5\u7684\u53d8\u5316\u5728VB.NET\u4e2d\u8fc7\u7a0b\u8bed\u6cd5\u6709\u4e86\u5f88\u591a\u53d8\u5316\u3002\u4f8b\u5982\u7c7b\u4f3cC++\u7684\u8fc7\u7a0b\u8c03\u7528\u65b9\u5f0f\u3001ByVal\uff08\u4f20\u503c\uff09\u4e3a\u9ed8\u8ba4\u7c7b\u578b\u3001Optional\u5173\u952e\u5b57\u3001return\u8bed\u53e5\u7b49\u7b49\u3002\u7c7b\u4f3cC++\u7684\u8fc7\u7a0b\u8c03\u7528\u65b9\u5f0f VB6.0\u5141\u8bb8\u4e0d\u7528\u52a0\u5706\u62ec\u53f7\u8c03\u7528\u8fc7\u7a0b\uff08sub\uff09\u3002\u4e0d\u8fc7\uff0c\u7528Call\u8bed\u53e5\u8c03\u7528\u51fd\u6570\u6216sub\u65f6\uff0c\u4e00\u5b9a\u8981\u4f7f\u7528\u5706\u62ec\u53f7\u3002\u4f8b\u5982\uff1aDim I as IntegerCall EvaluateData(2, i) EvaluateData 2, i \u5728VB.NET\u4e2d\uff0c\u6240\u6709\u7684\u65b9\u6cd5\u8c03\u7528\u90fd\u9700\u8981\u5706\u62ec\u53f7\uff0c\u800cCall\u8bed\u53e5\u5219\u662f\u53ef\u9009\u7684\u3002 ByVal\u662f\u9ed8\u8ba4\u53c2\u6570\u7c7b\u578b\u5728VB6.0\u4e2d\uff0c\u5728\u8c03\u7528\u51fd\u6570\u6216sub\u65f6ByRef\uff08\u4f20\u5740\uff09\u662f\u9ed8\u8ba4\u7c7b\u578b\u3002\u90a3\u610f\u5473\u7740\u6240\u6709\u6539\u53d8\u5c06\u53cd\u6620\u5230\u4f20\u5165\u7684\u53d8\u91cf\u3002VB.NET\u6539\u53d8\u4e86\u8fd9\u79cd\u65b9\u5f0f\u3002\u73b0\u5728\uff0c\u9ed8\u8ba4\u7684\u53c2\u6570\u7c7b\u578b\u662fByVal\uff08\u4f20\u503c\uff09\u3002 Optional\u5173\u952e\u5b57VB6.0\u4f7f\u7528Optional\u5173\u952e\u5b57\u53ef\u7528\u6765\u8ba9\u7528\u6237\u51b3\u5b9a\u4f20\u5165\u4e00\u4e2a\u9ed8\u8ba4\u503c\uff0c\u4e4b\u540e\u5728\u8c03\u7528IsMissing\u51fd\u6570\u5224\u65ad\u53c2\u6570\u662f\u5426\u6709\u6548\u3002 \u800c\u5728VB.NET\u4e2d\uff0c\u6bcf\u4e2a\u53ef\u9009\u53c2\u6570\u5fc5\u987b\u58f0\u660e\u5176\u9ed8\u8ba4\u503c\uff0c\u65e0\u9700\u8c03\u7528IsMissing\u51fd\u6570\u3002\u4f8b\u5982\uff1aSub MyMethod(Optional ByVal i As Integer = 3)
Return\u8bed\u53e5VB.NET\u7684Return\u8bed\u53e5\u4e0eC++\u76f8\u4f3c\u3002\u4f7f\u7528Return\u8bed\u53e5\u628a\u63a7\u5236\u6743\u4ece\u8fc7\u7a0b\u8fd4\u8fd8\u7ed9\u8c03\u7528\u8005\u3002\u5728VB6.0\u4e2d\uff0cReturn\u8bed\u53e5\u4e0eGoSub\u8bed\u53e5\u4e00\u8d77\u4f7f\u7528\u3002VB.NET\u4e0d\u518d\u652f\u6301GoSub\u8bed\u53e5\u3002\u6d41\u7a0b\u63a7\u5236\u7684\u6539\u53d8\u4e0b\u9762\u662fVB.NET\u5bf9\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u7684\u4fee\u6539\uff1a1. GoSub\u4e0d\u518d\u53d7\u5230\u652f\u6301\u30022. Call\u3001Function\u548cSub\u8bed\u53e5\u5747\u53ef\u7528\u4e8e\u8c03\u7528\u8fc7\u7a0b\u30023. On ... GoSub\u548cOn ... GoTo\u8bed\u53e5\u4e0d\u518d\u53d7\u652f\u6301\u3002\u53ef\u4ee5\u4f7f\u7528Select Case\u8bed\u53e5\u6765\u66ff\u4ee3\u30024. While ... Wend\u8bed\u53e5\u73b0\u5728\u6539\u4e3aWhile\u2026End While\u8bed\u53e5\u3002\u4e0d\u518d\u652f\u6301Wend\u5173\u952e\u5b57\u3002\u5c0f\u7ed3 Visual Basic .NET\u662f.NET\u7248\u672c\u7684Visual Basic\uff0c\u5df2\u7ecf\u4ece\u6839\u672c\u53d1\u751f\u4e86\u53d8\u5316\uff01\u901a\u8fc7\u672c\u6587\u4f60\u4e86\u89e3\u5230VB6.0\u548cVB.NET\u7684\u533a\u522b\u662f\u5f88\u5927\u7684\uff0c\u53ef\u4ee5\u8bf4\u6839\u672c\u5c31\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u8bed\u8a00\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u5185\u6838\u53d1\u751f\u4e86\u53d8\u5316\uff0cVB6.0\u662f\u57fa\u4e8eCOM\u800cvb.net\u662f\u57fa\u4e8e.net\u6846\u67b6\u7684\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u53d8\u5316\uff0c\u6240\u4ee5\u5728\u6784\u9020\u7c7b\u65f6\u4e5f\u53d1\u751f\u4e86\u6839\u672c\u6027\u7684\u53d8\u5316\u3002
VB.NET生成的是托管代码,必须运行于.NET框架之上.VB6则依赖于VB6运行时的支持.
在WINDOWS的下一版本WINDOWS 7中仍然会提供VB6的支持,不过再到以后的版本就没了.
如果你是第一次学,个人觉得还是直接转向VB.NET学习好了.
托管代码就是基于.net元数据格式的代码,运行于.net平台之上,所有的与操作系统的交换有.net来完成,就像是把这些功能委托给.net,所以称之为托管代码。非托管代码则反之。
举个例子l
Vc.net还可以使用mfc,atl来编写程序,他们基于MFC或者ATL,而不是.NET,所有是非托管代码,如果基于.net比如C#,VB.net则是托管代码
VB6 非真正的面对对象
VS.NET 真正的面对对象
VS6.0里的代码是非托管的,也就是说可能产生不安全的因素。
VS.net里的代是有托管的,也有非托管。
语法有些区别,支持库不一样,vb6.0是十几年前的产品,vb.net现在电脑支持比较好,但也不是主流编程语言
绛旓細VB鍜孷B.NET鐨勪富瑕佸尯鍒湪浜庡畠浠殑缂栫▼妯″瀷銆佽瑷鐗规у拰杩愯鐜銆俈B.NET 鏄 Visual Basic (VB) 鐨勭幇浠e寲鍗囩骇锛屾棬鍦ㄦ彁渚涙洿楂樼殑鎬ц兘鍜屾洿濂界殑闆嗘垚鑳藉姏銆傜紪绋嬫ā鍨嬶細VB 6.0 鍙婃洿鏃╃殑鐗堟湰浣跨敤鍩轰簬瀵硅薄鐨勭紪绋嬫ā鍨嬶紝鑰 VB.NET 鍒欓噰鐢ㄤ簡鏇寸幇浠g殑闈㈠悜瀵硅薄缂栫▼锛圤OP锛夋ā鍨嬨傝繖鎰忓懗鐫 VB.NET 鏀寔绫汇佺户鎵裤...
绛旓細VB.NET鏄畬鍏ㄩ潰鍚戝璞″拰鍚庣幇浠e寲鐨勮瑷(JAVA鐙叿鐨勬柊姒傚康)VB.NET鏄嚜鐢辩嚎绋嬭瑷 VB.NET鐨勮繍琛岄熷害姣擵B6瑕佸揩 VB.NET浠庤娉曚笂鏉ヨ鏇村姞绱у噾鍜屽叿鏈夎寰嬫 VB.NET寮鏀句簡鐣岄潰璁捐浠g爜 VB.NET鍙互鏇村ソ鍦伴泦鎴愬井杞殑鏂颁骇鍝佸拰鏂版妧鏈 VB.NET鎷ユ湁鏇村姞寮哄ぇ闄勫睘缁勪欢 VB.NET鎷ユ湁绉诲姩寮鍙戠殑鑳藉姏 VB.NET灏佽鐨勭被鍔熻兘...
绛旓細VB6.0鏄熀浜庡璞$殑,VB.NET鏄潰鍚戝璞$殑,瀹冧滑涔嬮棿鐨勮娉曚笂宸窛杩樻槸姣旇緝澶х殑.VB.NET鐢熸垚鐨勬槸鎵樼浠g爜,蹇呴』杩愯浜.NET妗嗘灦涔嬩笂.VB6鍒欎緷璧栦簬VB6杩愯鏃剁殑鏀寔.鍦╓INDOWS鐨勪笅涓鐗堟湰WINDOWS 7涓粛鐒朵細鎻愪緵VB6鐨勬敮鎸,涓嶈繃鍐嶅埌浠ュ悗鐨勭増鏈氨娌′簡.濡傛灉浣犳槸绗竴娆″,涓汉瑙夊緱杩樻槸鐩存帴杞悜VB.NET瀛︿範濂戒簡....
绛旓細VB6.0灞炰簬VS6.0锛屾槸鐢ㄤ簬寮鍙慦in32妗岄潰搴旂敤绋嬪簭鐨勫紑鍙戣瑷鍜岀幆澧锛涙搷浣滅郴缁熶富瑕侀潰瀵筗indows9X\Win2K\WindowsXP绛夈俈B.net灞炰簬VS.net锛岄傜敤浜.net寮鍙戝钩鍙帮紝寮鍙戝熀浜.net妗嗘灦鐨勫簲鐢紱VB.net骞朵笉鏄疺B6鐨勫崌绾х増锛岃屾槸鍏ㄦ柊鐨勪竴绉嶅紑鍙戝钩鍙般傝娉曚篃鍜孷B鏈夊緢澶х殑鍖哄埆銆俈S6锛1998锛夊洜璇ユ槸鍘嗗彶涓婂井杞仛鐨勯潪甯镐紭...
绛旓細VB.NET鏄熀浜.NET妗嗘灦鐨勫畬鍏ㄥ鍚戝璞$殑缂栫▼璇█锛岃寁b 6.0鍙槸鍗婇潰鍚戝璞$殑璇█锛屼娇鐢╲b.net鍙互缂栧埗鍑哄姛鑳芥洿鍔犲己澶х殑windows绋嬪簭銆傜幇鍦紝鎴戜滑鎶妚b.net鍜寁b 6.0鍋氫竴涓嬫瘮杈冿紝鐪嬬湅vb.net瀵规瘮vb 6.0鏈夌潃浠涔堟牱鐨勭壒鎬у拰浼樼偣銆 1.鍦╲b 6.0涓紝鍒涘缓瀵硅薄鐨勬椂鍊欙紝闇瑕佺瓑杩欎釜瀵硅薄鍒涘缓瀹屾瘯鍚庯紝鍐嶅彟澶栬皟鐢...
绛旓細涓嶄竴鏍凤紝VB.net鏄竴绉嶅紑鍙戝熀浜.net骞冲彴鐨勭▼搴忔垨鑰呮槸杞欢锛岃孷B鏄敤Basic璇█鏉ュ紑鍙慦Indows搴旂敤绋嬪簭鐨勶紝鐜板湪.net鍜孞ava灏变笟鏄钩鍒嗗ぉ涓嬬殑
绛旓細锛5锛塿b.net鏄法骞冲彴鐨勶紝鏈夌潃寮哄ぇ鐨勭被搴撳拰.net framework妗嗘灦锛屽彲浠ュ拰C#绛夊绉.net妗嗘灦涓嬬殑璇█鍏卞悓杩愯銆傦紙6锛塿b.net鍦ㄤ笌web service缁撳悎鏂归潰鏄帇鍊掓у己杩噕b6.0鐨勩傦紙7锛塿b.net05鍦ㄦ暟鎹簱鎿嶄綔涓婇潪甯哥殑鐏垫椿鍜屾柟渚匡紝vb6.0鐪嬪埌涔熷彧鑳界珯涓杈广傛殏鏃惰閭d箞澶氫簡锛屼笉杩vb.net鍜寁b6.0鏈槸涓瀹讹紝鍚勮嚜...
绛旓細瑕佺湅浣犲紑鍙浠涔绋嬪簭浜嗭紝濡傛灉鏄竴浜涙櫘閫氱殑灏忕▼搴忕殑璇濆缓璁敤vb6.0锛屼絾濡傛灉鎯冲紑鍙戠◢寰ぇ鍨嬩竴鐐圭殑绋嬪簭鐨勮瘽锛屽缓璁敤vb.net锛屽洜涓烘讳綋涓妚b.net寮哄ぇ鐨勫锛屽鏋滄兂寮鍙戞洿澶у瀷涓鐐圭殑绋嬪簭鐨勮瘽锛岄偅灏辨湁蹇呰瀛++浜嗐傚洖鍒版棰橈紝瑕佸鐨勮瘽寤鸿vb.net锛屼笉杩囪繖涔熸湁涓瀹氶毦搴︼紝浣嗗Vb.net浠ュ悗浼氭湁骞跨殑搴旂敤 ...
绛旓細' 鍏充簬VB.net { Visual Basic.NET鏄熀浜庡井杞.NET Framework涔嬩笂鐨勯潰鍚戝璞$殑涓棿瑙i噴鎬ц瑷锛屽彲浠ョ湅浣滄槸Visual Basic鍦.Net Framework骞冲彴涓婄殑鍗囩骇鐗堟湰,澧炲己浜嗗闈㈠悜瀵硅薄鐨勬敮鎸併備絾鐢变簬鏀瑰姩澶ぇ锛屽鑷碫B.net瀵筕B鐨勫悜鍚庡吋瀹规т笉濂斤紝鍦ㄤ笟鐣屽紩璧蜂笉灏忕殑浜夎銆 } ' VB.net涓嶸B6.0鐨勪富瑕佸尯鍒 { VB.Net...
绛旓細vb.net鏄畬鍏ㄩ潰鍚戝璞$殑锛屾瘮vb6.0 锛 澧炲姞浜嗗緢澶氬嚱鏁板拰绫伙紝杩樻湁鍏跺畠鐨勶紝杩樺鍔犱簡鍛藉悕绌洪棿浠ュ尯鍒嗙被锛屽悇绉嶇被鐨勫睘鎬у拰鏂规硶鏇村姞璇︾粏锛屾洿鍔犲己澶,杩樻湁寰堝绫婚兘閲囩敤浜嗘祦锛岀畝鍗曠殑璇达紝鍦╲b.net涓紝璁稿鍔熻兘閮藉彲浠ョ洿鎺ュ畬鎴愶紝鑰寁b6.0涓氨瑕佺敤鍒癆PI,鎴戞渶鍠滄鐨勫氨鏄痸b.net涓殑鑷姩缂╄繘锛岃嚜鍔ㄥ畬鎴愶紝杩樻湁灞炴э紝...