Yes, it is time to stop the madness called VB. In all shapes and sizes. In all versions and subversions. VB 1.0 VB 2.0 VB 3.0 VB 4.0 VB 5.0 VB 6.0 VB.Net 1.0 or VB7 VB.Net 2.0 or VB8 VB.Net 3.0 or VB9 VB.Net 4.0 or VB10 Lets also get rid of all other forms of Basic that annoy any serious developer out there. They ruin our nights, they ruin our day. They are sharp as knives and noone wants them.
This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.
The problem Just look at this code. And try to figure out what’s wrong with it. Without watching the solution. You can even compile and run it without a problem. Module Module1 Sub Main() Dim testClass = New Class1 Dim returnString = "" AddHandler testClass.OnSomething, Function(result) returnString = result testClass.Dosomething() Console.WriteLine(returnString) Console.ReadLine() End Sub Public Class Class1 Public Event OnSomething(result As String) Public Sub Dosomething() RaiseEvent OnSomething("test") End Sub End Class End Module``` The problem is that <code class="codespan">Console.WriteLine(returnString)</code> doesn’t write test as we would expect. And we know the event gets raised because we can easily debug that. And we know that debugging the lambda is a pain in the … so we don’t really know if that gets run. We just see that returnString never gets changed so we can expect it never to have run. ## The solution Now try this. ```vbnet Module Module1 Sub Main() Dim testClass = New Class1 Dim returnString = "" AddHandler testClass.OnSomething, Sub(result) returnString = result testClass.Dosomething() Console.WriteLine(returnString) Console.ReadLine() End Sub Public Class Class1 Public Event OnSomething(result As String) Public Sub Dosomething() RaiseEvent OnSomething("test") End Sub End Class End Module``` What changed? Not a lot. The lambda is now a Sub and no longer a Function. Apparently typesafety doesn’t include lambdas. Events are subs so your lambda should be a Sub to. If it is a function it does not throw an exception nor does it fail at compile time. It just silently ignores it, which isn’t funny. So remember Events are Subs and not Functions. <span class="MT_red">Update</span> As people have said in the comments what is probably happening is this. ```vbnet Module Module1 Sub Main() Dim testClass = New Class1 Dim returnString = "" AddHandler testClass.OnSomething, Function(result) Return returnString = result End Function testClass.Dosomething() Console.WriteLine(returnString) Console.ReadLine() End Sub Public Class Class1 Public Event OnSomething(result As String) Public Sub Dosomething() RaiseEvent OnSomething("test") End Sub End Class End Module``` Which I understand. But this still does not solve the problem why the compiler thinks an event can be a function. Seems to me some simple typechecking should have solved that. <span class="MT_red">Update2</span> And yes it is legal and called delegate relaxation. And I will let Julian Wischik explain it. > (1) A lambda written "Function(r) e" will ALWAYS assume that "e" is an expression. > > And a lambda written "Sub(r) s" will ALWAYS assume that "s" is a statement. > > So your hypothesis for what it’s doing is correct. > > In other words: the decision for whether or not to interpret the thing as an EXPRESSION or STATEMENT is done solely by whether the keyword is "Function" or "Sub". It is not determined by the target delegate type. > > (2) You wonder why it’s legal to assign a function-lambda to a void-returning-delegate-type. > > Well, that’s always legal in VB. We call it "delegate relaxation". It is type-safe. > > Here’s another example of delegate relaxation: > > ```vbnet Dim lambda = Function() > Return 1 > End Function > Dim a As Action = lambda ’ creates a wrapper which simply discards the returned value``` > Here’s another example of delegate relaxation: > > ```vbnet Dim lambda = Sub() Console.WriteLine("hello") > Dim a As Action(Of Integer, String) = lambda ’ here the wrapper discards the arguments``` > And here’s another example of that "wrapper which discards arguments"… > > ```vbnet Sub Button1Click() Handles Button1.Click``` > — here, the Button1.Click event has a delegate type with several parameters. We’re dropping them all implicitly. > > — > Lucian
Someone asked the following question on our forum: HHMMSS format in sysjobhistory. The sysjobhistory table in MSDB stores the run time of jobs in the format HHMMSS as an integer. Thus, a job that finishes in 18 minutes and 9 seconds is stored as 1809. If a job finishes in 4 seconds it’s stored as 4, and another that finishes in 7 hours, 21 minutes, 33 seconds as 72133. I’m trying to get to this data and need it formated in the time data type. Thus I’m looking for 00:18:09, 00:00:04, and 07:21:33 respectively.
The following question was asked I’ve got a sql server that’s set up to have database files to default to e drive, but the model’s files are on c. will new database pick up the setting from the server and put them on e, or will they pick it up from the model and put them on c? What SQL Server does is that it will pick up the settings from the server settings. We can easily verify that by running some scripts
The SQL Server 2012 RC0 is finally here! The news of this today is bringing many hopes that SQL Server 2012 release in RTM form will be on time so we as SQL Server Professionals can take ahold of this major new version in the life of SQL Server. Key parts of this impressive version of SQL Server include
SQL Server 2012 RC0 is available for download, you can download the bits here: http://www.microsoft.com/download/en/details.aspx?id=28145 To read all my SQL Server 2012/Denali posts go here: /index.php/All/denali:
Here is the definition of chocolatey as stated on the chocolatey.org website. Chocolatey NuGet is a Machine Package Manager, somewhat like apt-get, but built with windows in mind. Chocolatey can be easily installed. To install chocolatey now, open a powershell prompt (execution policy needs to be unrestricted – Set-ExecutionPolicy Unrestricted), paste the following and type Enter: PS:> iex ((new-object net.webclient).DownloadString(“http://bit.ly/psChocInstall”)) And Chocolatey also has a GUI if you like those kinds of things. Yeah I wrote that GUI, sorry.
You know that you can mark a proc to run at startup in SQL Server. What you have to do is create the stored procedure in the master database and after that you have to set the startup flag to true. If your stored procedure name is spMyProc, the code would look like this. exec sp_procoption N'spMyProc', 'startup', 'on' What if you want to list all the stored procedures on your server which are set to run on startup? Here is how you do this
Introduction Like I said in a [previous post of mine][1]. From time to time I answer a few questions on Stackoverflow, mostly because you can learn a lot from someone else’s problems and it makes you think. [ ][2] Thinking is something you need to practice every day.
So I downloaded the source for pdfviewernet and just ran it out of the box. And it worked. If you go look in the properties of the Samplepdfviewer you will notice that it is set to run for a .net 2.0 framework. You might want to change that to .net 4. If you try to run this now you will get this error. An error occurred creating the form. See Exception.InnerException for details. The error is: Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.