{"id":7023,"date":"2005-09-13T13:32:00","date_gmt":"2005-09-13T13:32:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2005\/09\/13\/visual-basic-next-by-amanda-silver\/"},"modified":"2024-07-05T14:54:33","modified_gmt":"2024-07-05T21:54:33","slug":"visual-basic-next-by-amanda-silver","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/visual-basic-next-by-amanda-silver\/","title":{"rendered":"Visual Basic &#8212; NEXT (by Amanda Silver)"},"content":{"rendered":"<p class=\"MsoNormal\"><span>The first preview of the <i>next<\/i> version of Visual Basic goes live this morning! I&rsquo;m sitting in Bill and Jim&rsquo;s keynote right now, waiting for our announcement to be made public. The release is part of the .NET Language Integrated Query Framework, code-named &ldquo;project LINQ&rdquo;, which allows Visual Basic (and C#) developers to <i>their<\/i> language for querying over data in databases, objects in memory, and XML.<span>&nbsp; <\/span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>But there&rsquo;s much more that&rsquo;s in store for VB than just query. <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>The bits can be downloaded <a href=\"http:\/\/msdn.microsoft.com\/vbasic\/future\">here<\/a> and work on top of the most recent CTP that was released to MSDN on Monday. The samples shipped with this first release are focused on the deep XML integration.&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span><\/span><span>For this first entry, I&rsquo;ll provide a survey of the <i>language features<\/i> that are exposed in this first release. I won&rsquo;t go into the features in great depth; I&rsquo;ll save that for later entries. <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>Type Inference &ndash; <\/span><\/b><span>Allows the compiler to inspect the expression on the right-hand side of an assignment statement to infer the type of the variable. <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> int = 1<\/span><span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> doub = 1.2<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> str = <span>&#8220;Hello&#8221;<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> intArr = {1, 2, 3}<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> strArr = {{<span>&#8220;Fred&#8221;<\/span>, <span>&#8220;Barney&#8221;<\/span>}, {<span>&#8220;George&#8221;<\/span>, <span>&#8220;Judy&#8221;<\/span>}}<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> strBuilderArr = {<span>New<\/span> StringBuilder(), <span>New<\/span> StringBuilder()}<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> objArr = {<span>&#8220;Fred&#8221;<\/span>, 10}<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>The type inference feature extends to other statements in VB:<\/span><span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>For<\/span><span> <span>Each<\/span> <span>Dim<\/span> cust <span>In<\/span> Customers<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp; <\/span>MsgBox(<span>&#8220;Customer Name: &#8220;<\/span> &amp; cust.Name)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Next<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>Object Initializers &ndash; <\/span><\/b><span>Enables an extremely concise syntax for creating and initializing an Object. The compiler will call the parameterless constructor and assign to the properties. So, assuming we have a Class or Structure named Customer with two properties, Name and Address that are both String types, I can write:<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> cust <span>As<\/span> Customer = {Name := <span>&#8220;Nancy&#8221;<\/span>, Address := <span>&#8220;<\/p>\n<address>\n<address>123 Main St<\/address>\n<p>.<\/p><\/address>\n<p>&#8220;<\/span>}<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;<\/span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Which translates to:<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> cust <span>As<\/span> Customer = <span>New<\/span> Customer()<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>cust.Name <span>&#8220;Nancy&#8221;<\/span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>cust.Address = <span>&#8220;<\/p>\n<address>123 Main St<\/address>\n<p>.&#8221;<\/span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p><\/span><b><span>Query syntax<\/span><\/b><span> &ndash; I really think the code speaks for itself&hellip; <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> primes = {1, 2, 3, 5, 7, 9, 11, 13}<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> primesOverFive = <span>Select<\/span> p <span>From<\/span> p <span>In<\/span> primes <span>Where<\/span> p &gt; 5<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>But one of the most powerful aspects of this feature is that you can now query over all CLR objects. I think the following query illustrates this best:<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> procs = <span>Select<\/span> p.ProcessName _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>From<\/span> p <span>In<\/span> Process.GetProcesses() _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>Where<\/span> p.Threads.Count &gt; 6<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>XML Literals &ndash; <\/span><\/b><span>Based on the XLinq framework, the next version of Visual Basic includes deep support for constructing, inspecting, transforming, and querying<span>&nbsp; <\/span>XML.<span>&nbsp; <\/span>You can write the XML the way to want to see it directly in the Visual Basic language. You can even invoke expressions within the XML literal as I do in getting the values for the birthday from Microsoft.VisualBasic.Today.<\/span><span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> nancyD = &lt;Person Birthdate=(Microsoft.VisualBasic.Today)&gt;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Nancy Davolio<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;<\/span>&lt;\/Person&gt;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span><\/span><\/b>&nbsp;<\/p>\n<p class=\"MsoNormal\"><b><span>XML Late Binding &ndash; <\/span><\/b><span>Assuming I&rsquo;ve got a bit of XML with several elements like that above, I can bind to its members &ndash; both elements and attributes with the code:<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>For<\/span><span> <span>Each<\/span> <span>Dim<\/span> peep <span>In<\/span> people&#8230;Person<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp; <\/span>MsgBox(<span>&#8220;Name: &#8220;<\/span> &amp; peep.Value &amp; <span>&#8221; Birthday: &#8220;<\/span> &amp; peep.@Birthdate.Value)<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Next<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>Dynamic Identifiers &ndash; <\/span><\/b><span>With this feature, the identifier you&rsquo;d like to bind to can be determined at runtime. This is incredibly powerful for meta-\ndata driven scenarios in which you&rsquo;d like to bind to a particular property that&rsquo;s determined by input provided at runtime, like reading an XML schema. <span>&nbsp;<\/span>Assuming I&rsquo;ve got an object with two Subs on it, &ldquo;PrintHello&rdquo; and &ldquo;PrintHi&rdquo;. With the following bit of code, the member that&rsquo;s invoked is dependent on the result of Console.ReadLine.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Dim<\/span><span> t <span>As<\/span> <span>Object<\/span> = <span>New<\/span> PrintGreeting<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>t.(<span>Console.ReadLine())()<\/span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>Relaxed Delegates &ndash; <\/span><\/b><span>In the next version of Visual Basic you will be able to hook up event handlers to events that have different signatures:<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Sub<\/span><span> txtBoxHandler(<span>ByVal<\/span> sender <span>As<\/span> <span>Object<\/span>, <span>ByVal<\/span> e <span>As<\/span> EventArgs) _<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Handles<\/span><span> txtBox.Click, txtBox.KeyPress<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&lsquo; Handling code<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span>End<\/span><span> <span>Sub<\/p>\n<p><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>I&rsquo;m incredibly excited to be able to start discussing these features with you. Please download the bits, play, and enjoy!!<\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>(working on better formatting.)<\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>&#8211; Amanda <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first preview of the next version of Visual Basic goes live this morning! I&rsquo;m sitting in Bill and Jim&rsquo;s keynote right now, waiting for our announcement to be made public. The release is part of the .NET Language Integrated Query Framework, code-named &ldquo;project LINQ&rdquo;, which allows Visual Basic (and C#) developers to their language [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[192,195],"tags":[28,94],"class_list":["post-7023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-visual-basic","tag-amanda-silver","tag-linqvb9"],"acf":[],"blog_post_summary":"<p>The first preview of the next version of Visual Basic goes live this morning! I&rsquo;m sitting in Bill and Jim&rsquo;s keynote right now, waiting for our announcement to be made public. The release is part of the .NET Language Integrated Query Framework, code-named &ldquo;project LINQ&rdquo;, which allows Visual Basic (and C#) developers to their language [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/7023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=7023"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/7023\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=7023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=7023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=7023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}