from net471 to .NET Standard noob questions [closed] - vb.net

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a very old VB project I am looking to modernize to which I created a new solution (will convert code to C# later on), am re-adding the libraries and web projects to the new solution to eliminate the old project having old .publishproj, references to mscorlib 2.0 (despite best efforts to resolve through re-adding references) and several other issues that will likely go away.
In the process, I figured to try to go to .NET Standard for the standardized PCL that will allow for future use with Xamarin, Mono, etc. I am not fully versed in .NET Standard so need some input (attempting 2.0 based on the scaling effect of 2.0 down from what I read)
The problems I am running into are:
1) I have several basic CORE functions from the .NET Framework that are not recognized in .NET Standard:
IsNumeric, IsNothing, IsDBNull, IIF
Any suggestions as to why this is?
(re-edit to remove Hold)
Thank you to jmcilhinney for answering :-)

All four of IsNumeric, IsNothing, IsDBNull and IIf are VB-specific. They can't be part of .NET Standard if they've never been accessible to other languages without referencing the Microsoft.VisualBasic assembly. You really shouldn't have been using any of them previously anyway as they are holdovers from VB6.
In the case of IsNumeric, it uses Double.TryParse internally anyway. In fact, Double.TryParse was written specifically to improve the performance of IsNumeric. You should be using the TryParse method of the appropriate numeric type yourself if you want to know whether a String can be converted to that type.
In the case of IsNothing, you should simply be comparing your reference to Nothing, e.g. instead of:
If IsNothing(myThing) Then
you should be using:
If myThing Is Nothing then
In the case of IsDBNull, you should be doing much as above, e.g. instead of:
If IsDBNull(myThing) Then
you should be using:
If myThing Is DBNull.Value Then
That said, both a DataRow and a data reader have their own dedicated methods to tell you whether one of their fields is NULL.
In the case of IIf, it always had it's issues because it is a method that people tried to treat like an operator in many cases. I think it was VB 2008 that actually did introduce an If operator that works much like the C# ternary operator, so you should have been using that since then anyway, e.g. instead of:
myVar = IIf(someBooleanExpression, someValue, someOtherValue)
you should have been using:
myVar = If(someBooleanExpression, someValue, someOtherValue)
There are some subtle differences between IIf and If but I'll leave you to read about how If works for yourself.

Related

Bitdefender detects my console application as Gen:Variant.Ursu.56053 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I've developed a console application that does a lot of routines, but the Antivirus detected it as a malware of type Gen:Variant.Ursu.56053.
How can I fix this without touching the antivirus policy because it's not allowed for us to create any exceptions for any found threat.
I'd like also to mention that If i changed the assembly name the antivirus is no longer consider the new file virus, but it looks that it considers it virus because I invoke it many times, with different parameters.
Any suggestions, I'm really suffering from this,
I know this thread is very old, but for people which will come here - to fix this issue simply add icon to the program, im not even joking, it works.
FALSE +VE ALERT!!! Many antivirus engines have name pattern matching as their Swiss-knife to detect malicious files,If any of them matches the name they have in their Database then you can't do much about it. Its simply became a False +ve !!! Also your assembly name should consist of the technology area and component description, or company name and technology area (depending on your preferance). So try changing it to more specific one. :)
Assuming that you are talking about .NET (with relation to Visual Studio) For Ex:
Project: Biometric Device Access
Assembly: BiometricFramework.DeviceAccess.dll
Namespace: ACME.BiometricFramework.DeviceAccess
I had the same problem with Bitdefender, but mine is a Gen:Variant.Ursu.787553 when I tried creating a .exe file from my C program.
I simply moved it out of quarantine manually, and it worked well. You might have to that every time you build a new program. Hope this helps!

setting Visual Studio to help me better document my code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
What I am trying to do is setup Visual Studio 2017 Enterprise to have it help me keep track of my code architecture better. I am running on Windows 8.1 if that makes any difference. An example will (hopefully) demonstrate what I mean:
If I want to use the sine function, Visual Studio insists that I pre-pend Math. in front of it: Rise = Math.sin(Angle)
What I want to do is have the same behavior for libraries that I have created. I have created a class called K2Math (called out as Public Class K2Math) and in it are functions like: Public Shared Function CheckForCollinear( . . . ) as Boolean. I have bundled it up into a separate DLL.
In my caller code, in the project references I have a reference to K2Math.DLL. As the functions are Public Shared, I don't have to use 'New K2Math' setup call like I would with a more conventional DLL. However, in the caller program I can use the CheckForCollinear function without having to pre-pend K2Math. I can also call it using K2Math.CheckForCollinear and the compiler doesn't complain.
What I would like the compiler to do is complain and force me to pre-pend the K2Math. This would help to make it obvious to me or whoever is reading my code how the code is architected and segregated.
But I can't seem to figure out how to do that. Also, I haven't figured out how to succinctly pose the question to do a proper Google search.
If I am being unclear, please so note that and I'll try to clear things up.
Create a Library lets say CustomizedMathLibrary
In that create a class K2Math. WRAP in a NAME SPACE (This is important)
Build and Use It by Importing name space in your code.

vba code refactoring - are there any tools to assist? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am trying to refactor my VBA code. I am so used to using refactoring in Java-based IDEs for a number of years. Does VBA editor support any refactoring or are there any add-ins? MZ Tools did not have any such functionality.
I want to be able to do at least the following:
1. Rename variables
2. Split Procedures into sub-procedures to make the code more readable
3. Change the scope of the variable from global to procedure and vice-versa
Disclaimer: I'm heavily involved with this project.
Rubberduck is an open-source add-in for the VBA/VB6 IDE under [very] active development, that includes this functionality.
Version 1.3 includes a Rename refactoring:
Version 2.0 (beta available, still stabilizing) includes a dozen refactorings:
Introduce Parameter promotes a local variable to a parameter
Introduce Field promotes a local variable to module scope
Encapsulate Field turns a public field into a property
Move Closer to Usage moves a field that's only used in 1 procedure, into that procedure. Or moves a local variable immediately above its first use.
Extract Interface lets you pick what class members to extract into an interface, creates a new class modules with stubs for them, and makes the original class implement the extracted interface.
Implement Interface creates stubs for all members of an unimplemented interface, so you don't need to create them manually by selecting them one by one in the code pane dropdown:
Implements IClass1
Public Sub IClass1_DoSomething()
Err.Raise 5 'TODO implement interface member
End Sub
Public Function IClass1_GetFoo() As Integer
Err.Raise 5 'TODO implement interface member
End Function
Sub DoSomething()
End Sub
Function GetFoo() As Integer
End Function
More refactoring tools are on the project's roadmap (including Extract Method), which you can follow on GitHub.
The only 'refactoring' tool I know of in VBA is Ctrl+F and Ctrl+R.
I use V-Tools for refactoring-like work as it will do find / replace in objects, not just VBA code.
http://www.skrol29.com/us/vtools.php
Yes there is.... almost
In the good old days i used this one.
http://www.moshannon.com/speedferret.html
helped me alot and I think i have the 3.5" disks somewere ;)
The trick is to copy your excel code to Access or VB6 and do your refactoring there.
Replacing scope: solution is creative naming and using replace.
spitting procedures... well thats a manual I'm sorry.
It's usually not worth it unless you have some serious excel vba code, I would recoment converting most of it into c# or VB.Net dll where you can do refactoring, testing and some modern magic and only do as little you can in VBA.

Len() function vs String.Length property; which to choose?

I'm making the transition from VB6 to VB.Net (VS 2010) and have a basic rather than expansive understanding of the latter. I obviously have quite a bit of code to... I hesitate to use the word "upgrade" when "port" would be more apt given that the upgrade wizard in past versions of VS may as well have just commented out the code and said "Hey, why don't you re-start from scratch?"
In one procedure which I'm bringing across the Len() function was used to determine the length of a string variable. That still works in VB.Net (though I imagine that it's actually a call to the Strings.Len Method), but the other alternative is to just query the .Length property of the variable.
The question is which to use and why. I've looked through the relevant MSDN pages and all they seem to tell me is that the method/property exists. Nothing is said about performance issues, particularly when loops of large numbers of calls might be involved.
My question, then, is whether anyone is aware of any tested and confirmed benefit of using one approach over the other, or whether it's merely a question of personal preference. Any pointers on similar situations that I might encounter as I make the progression would also be appreciated though given the Stack Overflow guidelines it's just this one issue that I'm interested in seeing whether there's a specific answer to.
Because you're using VB.NET, your Strings can be Nothing and unless you explicitly check for that, most VB methods, including Len, will treat it the same as String.Empty i.e. "".
With Reflector you can see Len is implemented as a null check, returning 0 for Nothing and otherwise returning .Length, and the JITter will likely in-line the call.
So, if you're using other VB methods, I'd suggest using Len too, unless you know the String is not Nothing or check for Nothing everywhere.
So according to this:
Len, another classic BASIC function, returns the length of a string. System.String has the Length property that provides the same information. Is one better than the other?
Performance-wise, these two functions show little difference over 1000’s of iterations. There doesn’t appear to be any reason to prefer one over the other in this case plus there is no functional difference. I’m kind of partial to using the property value rather than the VB function since it encourages thinking of .NET strings as objects. However, at the core, it’s really only a personal preference thing.
If you trust their word, then there's your answer. Otherwise, coding up a test and iterating should give you the final answer.
I'm not sure about the specifics of the Len() method (my language of choice is C#), but I would say definitely go with the Length property. Length is a member of the System.String class, whereas Len() isn't.
My guess is that Len() is just a VB shim on top of the Length property. Someone could probably make the argument that using Len() is more idiomatic, from a VB point of view. I think I'd prefer to use the property built in to the class, rather than just use a different mechanism just because it's provided by the language.
The Len method is provided for backwards compatibility with old VB6 (and earlier) non-.NET code. There's nothing technically wrong with using it. It will work, and just as well, at that. But, it's better to use the new .NET way of doing things whenever possible. Outside of getting you more into the ".NET mindset", though, the only real tangible benefit of using String.Length is that it makes it easier to port the code to other .NET languages in the future.
In addition to #Andrew's post, the Len() is string function from Visual Basic run-time library where as Length is a property of System.String class of .net framework API.
Recently I faced problem with my old VB.Net code that was using Len() function. I upgraded my project to Core which was referencing the old VB.net dll file and it was using Len() function. I got run time compatibility error - Method not found: 'Int32 Microsoft.VisualBasic.Strings.Len(System.String)'
I have to change all such old function that Core has deprecated. So I stand by using String.Length over Len() as suggested by Steven Doggart.

LGPL grammar file licensing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Given a LGPL'ed grammar file, is the source generated by a compiler-compiler for the grammar a derivative works? What about if the grammar file was modified before it was given as input to the compiler-compiler? There isn't any linking, at least not in the conventional sense.
If the output is a derivitive work, must I then simply provide the (modified) grammer sources making any best efforts to ensure the grammar will function without dependencies imposed by the program/library using it? Or are there more restrictions which must be resolved?
1) Since the grammar contains the essence of the resulting code, it definitely belongs to "all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities" and is not a part of "the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work". In brief, LGPLv3 applies.
So, you need to convey the "Minimal Corresponding Source" (the one used to build the version in the Combined Work) according to sec.4 d) 0) or GPLv3 sec.6, mark it as modified if it is and possibly include custom tools if required by GPL's definition of "Corresponding Source". (In general, as sec.0 says, LGPLv3 is effectively GPLv3 with a few additional provisions.)
2) It might be a derivative work of the generator used as well if the latter inserts parts of itself into the code (see FSF FAQ#Can I use GPL-covered tools... to compile...?) - check the generator's workings and licensing terms if necessary. If it is, you'll have to satisfy both LGPLv3 and the generator's terms that apply to the results of its work.
The best answer, and which everyone should be giving you is as follows:
Contact a lawyer
Disclaimer: IANAL and if you want something "official" you should talk to one. That said...
A common-sense approach says that yes, the result of compilation of something that is compilable is a derivative work. For instance, the compiled version of an LGPL library is still LGPL - you can't say that you obtained a compiled version of the library and never compiled it yourself and somehow dodge providing the source code that way.
Thus, the LGPL would require you to distribute the (potentially modified) source of the original LGPL work, such that if an individual wanted to further modify the work, they could.