Define String ENUM in VB.Net

For non-integer values, Const in a Structure (or Class) can be used instead: Structure Test Const PersonalInfo = “Personal Info” Const Contanct = “Personal Contanct” End Structure or in a Module for direct access without the Test. part: Module Test Public Const PersonalInfo = “Personal Info” Public Const Contanct = “Personal Contanct” End Module In … Read more

Integer.TryParse – a better way?

No need to declare the integer. If Integer.TryParse(intToCheck, 0) Then or If Integer.TryParse(intToCheck, Nothing) Then If you have .Net 3.5 ability you can create an extension method for strings. Public Module MyExtensions <System.Runtime.CompilerServices.Extension()> _ Public Function IsInteger(ByVal value As String) As Boolean If String.IsNullOrEmpty(value) Then Return False Else Return Integer.TryParse(value, Nothing) End If End Function … Read more

Serilog – Output/Enrich All Messages with MethodName from which log entry was Called

in case you need a version in C#: public static class LoggerExtensions { public static ILogger Here(this ILogger logger, [CallerMemberName] string memberName = “”, [CallerFilePath] string sourceFilePath = “”, [CallerLineNumber] int sourceLineNumber = 0) { return logger .ForContext(“MemberName”, memberName) .ForContext(“FilePath”, sourceFilePath) .ForContext(“LineNumber”, sourceLineNumber); } } use like this: // at the beginning of the class … Read more

Creating and appending text to txt file in VB.NET

Try this: Dim strFile As String = “yourfile.txt” Dim fileExists As Boolean = File.Exists(strFile) Using sw As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate)) sw.WriteLine( _ IIf(fileExists, _ “Error Message in Occured at– ” & DateTime.Now, _ “Start Error Log for today”)) End Using

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)