Visual Studio 2022 Preview 4.0 + Visual Studio 2019 version 16.11.3

The Visual Studio 2022 update to Preview 4.0 is out. We are getting closer to the final release… Since this is scheduled for November, we can still expect a Preview 5.0 next month.

“He who stands still is lost”

Ah, a Visual Studio 2019 update is also out, to version 16.11.3, but by now there will be little new in this product, mostly bug fixes (unless new features made available with Visual Studio 2022 are added, but that’s pretty unlikely)

image

[VB] Expression evaluator

In my explorations on CodeProject I found another interesting project: a runtime expression evaluator for Visual Basic.
This project has its origin in a rather old article, then updated and extended in 2007, but always very useful when there is a need to evaluate expressions at runtime. This article solves the problem with a wide range of recognized operators.

Sample image Sample image

Sample image

[VB] Save the database connection string

In some articles I’ve published in this blog I’ve explained how it’s possible to use a string to connect to a database and how it’s possible and necessary to store it in an application configuration file.

Some readers asked me how it is possible to modify at runtime the connection string stored in the configuration file, since with My.Settings it is not possible to do so, since it is read-only.

Searching on CodeProject I found this interesting article that solves this problem: “How to persist changes to My.Settings.ConnectionStrings“.

The techniques shown are not particularly complex and therefore can be easily used by anyone, without particular problems.

At the end of the article, the author recommends “make sure that Save My.Settings on Shutdown is enabled“.

Home

#11 – Decimal to binary number conversion

To convert an integer number into a binary number we can use the BitArray class that converts an array of numbers into an array of bits. To represent the sequence of bits, then, we use a string and, to visually separate each byte, we also add a separator space:

Dim num As Integer = 32767 
Dim decimalNum() As Integer = {num} 
Dim binaryNum As New BitArray(decimalNum) 
Dim str As String = "" 
Dim bitCount As Integer = 0 
For i As Integer = (binaryNum.Count - 1) To 0 Step -1 
    If bitCount = 8 Then 
        str &= " " 
        bitCount = 0 
    End If 
    If binaryNum.Item(i) = False Then 
        str &= "0" 
    Else 
        str &= "1" 
    End If 
    bitCount += 1 
Next 
MessageBox.Show(str)

With the integer 32767 we get the following string:

00000000 00000000 01111111 11111111

[VB.NET and LINQ to SQL] Query multiple DBMS in the same query

Often there is a need to query data from heterogeneous sources, for example some present in a Microsoft Access database and others in a SQL Server database.

The article “LINQtoSQL: Query multiple databases in one LINQ expression and more…” published on CodeProject allows to understand the techniques behind extracting data from different sources. Accompanied by an example in VB.NET.

Home

[C#] Custom TextBox that Delays the TextChanged Event

I report the article published on CodeProject titled “Custom TextBox that Delays the TextChanged Event” which is very interesting, especially for its usefulness.

Home

The problem consists in the fact that the TextChanged event is triggered every time we type a new character in the TextBox, even if the data entry is not completed. For example, in an ASP.NET page, we may have a TextBox that we use to insert the page of data we want to access. If the page is 100, we first enter “1” (and the TextChanged event is triggered and then the database query is executed), then we type the “0” of “10” (and the event is further triggered with a second database query), and finally we type the final zero to get “100” (triggering for a third time event and query). This is undesirable both for the lousy visual effect and for the inefficiency and performance of the application.

So here the author has created a custom control derived from TextBox to delay the event by a certain number of milliseconds.

The article, equipped with source and example in C#, is quite easy to follow and is not particularly difficult to convert to VB.NET.


Book "Design of Relational Databases" (preview)

I have published the first chapter of my book “Design of Relational Databases“, I hope you enjoy it.

Cover

In order to design a relational database correctly, one cannot give in to improvisation and superficiality: it is necessary to adopt a consolidated methodology capable of guaranteeing a robust and error-free result that also allows easy maintenance over time. This is why in this book you will find theoretical topics to be applied in the field: relational algebra, conceptual, logical and physical design, entity/relationship diagrams, normalisation, relational integrity constraints and SQL language. This is complemented by an extensive chapter on a concrete example of a database designed step-by-step for a business application. A text to keep at your workstation, but also perfect for database design courses in high school and university.

#10 – Reversing a string

The function returns the inverted string passed to it as a parameter.

Public Function ReverseString(ByVal stringToReverse As String) As String 
    ' variables declaration 
    Dim i As Long 
    Dim tmpString As String = "" 
    Dim strLen As Long = 0 
    If stringToReverse = "" Then 
        ' if empty string return it 
        tmpString = "" 
    Else 
        ' otherwise perform the string inversion 
        strLen = stringToReverse.Length 
        For i = (strLen - 1) To 0 Step -1 
            tmpString = String.Concat(tmpString, _ 
                stringToReverse.Substring(i, 1)) 
        Next 
    End If 
    Return (tmpString) 
End Function

#9 – Repeating a string (VB)

The function is similar to VB’s native String(), with the added possibility of defining a string (and not a character) to be repeated.

Public Function RepeatString(ByVal repetitions As Long, _ 
        ByVal stringToRepeat As String) As String 
    ' declaration of variables 
    Dim i As Long 
    Dim tmpString As String = "" 
    If repetitions <= 0 Then 
       ' if the number of repetitions is less than 1 (zero or negative) 
       ' return an empty string 
       tmpString = "" 
    ElseIf repetitions = 1 Then 
       ' if the number of repetitions = 1, return the string itself 
       tmpString = stringToRepeat 
    Else 
       ' otherwise execute the repetition of the string 
       For i = 0 To repetitions - 1 
          tmpString = String.Concat(tmpString, stringToRepeat) 
       Next 
    End If 
    Return (tmpString) 
End Function

To test this function, create a form with 3 textboxes and a button (named TextBox1, TextBox2, TextBox3 and Button1 respectively) and insert the following code in the Click event of Button1:

Private Sub Button1_Click(ByVal sender As System.Object, _ 
        ByVal e As System.EventArgs) Handles Button1.Click 
    ' variables declaration 
    Dim stringToRepeat As String = "" 
    Dim repetitions As Long = 0 
    Dim stringFinal As String = "" 
    ' read TextBox1 with the string to be repeated (e.g.: "ABC") 
    stringToRepeat = Me.TextBox1.Text 
    ' reading the number of repetitions from field TextBox2 (e.g.: 3) 
    ' N.B.: usually the numeric input must be checked 
    repetitions = Long.Parse(Me.TextBox2.Text) 
    ' execution of the repeat string function 
    stringFinal = RepeatString(repetitions, stringToRepeat) 
    ' result in TextBox3 (e.g.: "ABCABCABC") 
    Me.TextBox3.Text = stringFinal 
End Sub