Visual Basic.NET





Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to  Visual Basic pre-2002, it is not the same technology,

Share tech news, updates, or what's on your mind.

Sign up to Post

How do I right justify a label?  My labels are all fixed size and set to False on AutoSize in Visual Studio.  I tried few things, like lblCode1.Text = lblCode1.RightToLeft, but nothing seems to work. Isn't there a simple way to right justify labels? Here's an example of what I'm doing.
lblCode1.Text = IO.File.ReadLines(AppDomain.CurrentDomain.BaseDirectory + "_data/file1.txt").Last()
lblCode2.Text = IO.File.ReadLines(AppDomain.CurrentDomain.BaseDirectory + "_data/file1.txt").Last()
lblCode3.Text = IO.File.ReadLines(AppDomain.CurrentDomain.BaseDirectory + "_data/file1.txt").Last()

Open in new window

And I've tried to do the following before the above code, and I also tried it after the above code, but neither work.
lblCode1.Text = lblCode1.RightToLeft
lblCode2.Text = lblCode2.RightToLeft
lblCode3.Text = lblCode3.RightToLeft

Open in new window

I'm assuming there is an easy way to right justify a label?
Several years ago a developer in Seattle set up a cloud service for me and enhanced my program so it could access the service at  This app runs on older Symbol scanners using Windows CE and Compact Framework compiled using Visual Studio 2008, since we can't use any version more current than 2008.

Fast forward to now, where the developer has set up a new server for our new Android apps, while intending to make it possible for this older app to also access this new server as  If I simply change the Web Reference URL in my code to this, it compiles fine, but won't connect with the service.  He thinks it's because I'm having to now use a https connection vs. the old http.  

The developer does not know how to fix this problem--which is why I need help here at e-e.  He did make a few suggestions as follows in the conversation below--most of which I don't understand:


It could be that the legacy code is configured to only connect to non-secure/encrypted channels on that service call.
Odds are you need to alter the service binding to allow for a secure channel.  

He then told me to look for references to "BasicHTTP" and the conversation continued as follows:

There are about five points in the program that include “BasicHttp”, such as the one below.  Does this mean I can manually change those to “BasicHttps” and expect …

I am building a app that pulls data from an API using JSON in the procedure shown further on.
I have now been asked to edit the data using a POST and the following JSON string. What code would I use to do this? Thanks

{"LineID":2,"EmployeeID":"4720","EmployeeName":"Claire ","LogDate":"19 Apr 2019","Hours":2,"EmplyeeWorkType":"Work","Co_ID":6},
{"LineID":0,"EmployeeID":"4742","EmployeeName":"Will         Pretorius","LogDate":"19 Apr 2019","Hours":4,"EmplyeeWorkType":"Work","Co_ID":6}

 Function Get_MB_Employees_Hours(StoreID As Integer, Optional emplyeeID As Integer = 0) As List(Of EmployeeHours)

            'First declare the master API URL:
            Dim url As String = ""
            'Dim url As String = ""

            'When calling the API you are calling a method or function
            Dim API_Method As String = "EmployeeHours"

            'On there API we passthrough an additional header for the authorisation, 
            'this Is the username And password combined And split with :

            Dim Auth As String = Me.txtUsername.Text & ":" & Me.txtPassword.Text

            Dim EmpParam As String
            If emplyeeID = 0 Then
                EmpParam = ""
                EmpParam = emplyeeID
            End If

            Dim oStartDate As String = Me.Calendar1.SelectedDate.ToString("dd MMM yyyy")

Open in new window


I wonder is there any easy way to get number of dots;


' output dot number: 3
' last value: $N_Name4
' other values : $G_Name1.$B_Name2.$C_Name3

Any help would be great thank you.

In my web app I use the following code to create a link that will appear in emails. I want the link to look more like a button, possibly with
a gradient affect. How would I do this? Thanks

            oLink = "" & Replace(oShaft, " ", "%20")
            oHBody = oHBody & "<br>"
            oHBody = oHBody & "<a href=" & oLink & ">" & oShaftandRegion & "</a>"
            oHBody = oHBody & "<br>"

Open in new window

What tools are needed for .net mobile device development and where can I find some really good tutorials?

I'm thinking Xamarin, since it's write once, and C#. Does it also allow VB.NET?

How can i organize the below value via type.val ascending or descending. Any help would be grateful

       Dim getOVnames = From ov In list
                         Group ov By Type = ov.type.val Into Group
                         Select Type, ForceGroup = Group

Open in new window

Hi. In my code I use the following SQL statement. I need to build a further SQL statement where the [Date] is Month to Date
            S = "Select convert(varchar(11),[Performance].[Date],113) As [Date],[Performance].[Shaft], Sum([Performance].[Drilled Total]) As Metres,Cast([vShafts_StartDate].[Target] As Money) * Count(DISTINCT [Performance].[Date]) As Target, Sum([Drilled Total])/(Count(DISTINCT [Date])*Count(DISTINCT [Machine Number])) As [Ave M/Mach/Shift], Sum([Performance].[Delay Hours 1]) As Delays"
            S = S & ", Sum(Case When [Delay Code 1] In('drill','dwr','evd','mhd','mmd','msd','s54','sdt') Then [Delay Hours 1] End) As [Mine Delays]"
            S = S & ", Sum(Case When [Delay Code 1] In('led','lhd','lmd','lpd','rig','tp') Then [Delay Hours 1] End) As [Lesedi Delays]"
            S = S & " FROM [Performance] Inner Join [vShafts_StartDate] On [Performance].[Shaft] = [vShafts_StartDate].[Shaft]"
            S = S & " WHERE [Date] >= " & oUseFromDate & " And [Date] <= '" & Me.Calendar2.SelectedDate.ToString("dd MMM yyyy") & "'And [Performance].[Shaft] = '" & Me.DropDownList_Shafts.Text & "'"
            S = S & " GROUP BY [Performance].[Date],[Performance].Shaft,[vShafts_StartDate].[Target]"

Open in new window

I want to read and XML file and get specific information.  Currently, my code is:

        Dim xmlDoc As New XmlDocument()

        Dim DocNodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes(vDoc )

My variable  vDoc = "/Transport/BOL/Sheets/Doc[@type='Invoice']".

This works fine except when I have two with the same type and I only want to read the one marked valid.
XML = Doc type="Invoice" charge ="Standard" isValid="true"

I tried "/Transport/BOL/Sheets/Doc[@type='Invoice' @isValid='true']" but that did not work.  Any ideas?

How do I limit my node to the two characteristics?
I have seen VB Code samples on how to add a User to a AD Group but not a AD Computer added to a AD Group.
I am decent at VB.NET and I am learning Powershell
This is something I found does anyone know how to tweak it to have a computer get added tom a AD Group
PS C:\> Add-ADGroupMember -Identity SvcAccPSOGroup -Members SQL01,SQL02

Open in new window


In my chart I used the following code in the pie chart series
The problem is that it substantially shrunk the size of the actual chart
Is there a way to stop the actual chart from shrinking so much?
I have included an image of the chart with the code and below that without it.
Please ignore the different percentages. I used two different data sets but the shrinkage was the same

       series1.Label = "#VALX (#PERCENT)"
            series1("PieLabelStyle") = "Outside"
            series1("PieStartAngle") = "45"

Open in new window

I'm getting some lists via COM-Interface from third part tool. It gives me some lists with same size but some of the items are comes as empty according to configuration.

For example i'm getting 3 list from tool like below.

Dim list1 As List(Of String) = ("Fx", "Fy", "Fz", "Fm", " ", "Dy", "Dz", " ", "Ax", " ", "Az")

Dim list2 As List(Of String) = ("Fx", "Fy", "Fz", " ", "Dx", "Dy", "Dz", "Dm", " ", " ", " ")

Dim list2 As List(Of String) = ("Fx", "Fy", "Fz", "Fm", " ", " ", "Dz", " ", " ", "Ay", "Az")

Open in new window

And finally i'd like to get a final list like below.

Dim allList As List(Of String) = ("Fx", "Fy", "Fz", "Fm", "Dx", "Dy", "Dz", "Dm", "Ax", "Ay", "Az")

Open in new window

As you can see all items same position but missing parts are filled from another lists.

Any help would be grateful.


I'm using below code to add values to datagridviews according to their types.

                For Each force In forceList
                    Dim tp As TabPage = DirectCast(tabCtrl.Controls("tabCheckForceOut_" & force.type.val.ToString), TabPage)
                    Dim dgv As DataGridView = DirectCast(tp.Controls("dgvCheckForceOut_" & force.type.val.ToString), DataGridView)

Open in new window

I have also function like below and it's returning a list of double.

        Private Function EvaluateForce(ByVal xObj As IScrForce) As List(Of Double)
            Dim ovNumber As Integer = xObj.getNumOv
            Dim resList As New List(Of Double)
            For i As Integer = 1 To ovNumber
                resList.Add(CoreGlobal.Base.Server.Spck.Slv.eval("FORCEOV(" + xObj.fullName + "," & i & ")"))
            Return resList
        End Function

Open in new window

In normally if the output value number is certain for each type of force it'll be easy for me to add rows like that.

Dim result As List (Of Double) = EvaluateForce(force)
dgv.Rows.Add(force.parent,, result.item(0), result.item(1), result.item(2))

Open in new window

As you can see if i know "result" list has 3 items it's easy for me to add.

But if i dont know the list size/ item number how is it possible to add row to DataGridView?

Thank you.

I'm using below code to generate datagridviews in some tabs.After that i'd like to access them but i dont know how is it possible?

        Dim list As List(Of IScrForce) = ModelBase.GetForceList(CType(mdl, IScrModelBase), True)

        Dim ftypes = From l In list
                     Select l.type.val

        Dim uniqueFactors = From factor In ftypes Distinct

        For Each f In uniqueFactors

            Dim tabpage As New TabPage
            tabpage.Text = f.ToString

            Dim dgv As New DataGridView
            dgv.Dock = DockStyle.Fill
            dgv.Name = "dgv" & f.ToString

            Dim dgvcol As New DataGridViewColumn
            dgvcol.HeaderText = "Name"




        For Each item In list
            Dim dgv As DataGridView = ' Here i would like to get by name like ; "dgv" & item.type.val.ToString

Open in new window

Here i would like to accessing by name;
            Dim dgv As DataGridView = ' Here i would like to get by name like ; "dgv" & item.type.val.ToString

Open in new window

Hi All,

Ok I have a Function that needs to run in the background from the Same UI as the rest of the Program. I am using Visual Studio 2017 and

I have been able to get most of the Function working in the background using the Backgroundworker control. This is a Very large function and it DOES need to periodically output some data to a TEXTBOX during its operation.

I know that I need to setup DELEGATES to workaround this Cross-Thread problem but I am only partially successful in my endeavors.  With the Delegate that I created I can only write to one TEXTBOX but not another..

So in my research I find that there is a method of turning off  the Checking of this condition.. I see that the option that I must set is 'Control.CheckForIllegalCrossThreadCalls. I understand that this is not recommended  but my  problem is that I Can Not find this Option to set...

Also if I try to use the 'INVOKE' method I cannot find the 'InvokeRequired' method which I believe is the reason  why my DELEGATE is only partially successful.

I would be grateful for help in either finding these options or in getting my delegates to work properly.
Obviously I will provide as much of my code as you wish  to see upon request.

Thanks in advance
I'm using below code for CurrentCellDirtyStateChanged but i have to add all of them manually to list as you can see. It's a bit hard because sometimes you may forgot to add event list so is there any way to do that automatically?

    Private Sub CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles _
        dgvBuildExportList3d.CurrentCellDirtyStateChanged, dgvBuildExportListFe.CurrentCellDirtyStateChanged, dgvBuildExportListHp.CurrentCellDirtyStateChanged,
        dgvBuildExportListIfctn.CurrentCellDirtyStateChanged, dgvBuildExportListInfo.CurrentCellDirtyStateChanged, dgvBuildExportListMp.CurrentCellDirtyStateChanged,
        dgvBuildExportListPa.CurrentCellDirtyStateChanged, dgvBuildImportListFe.CurrentCellDirtyStateChanged, dgvBuildImportListHp.CurrentCellDirtyStateChanged, dgvBuildImportListInfo.CurrentCellDirtyStateChanged, dgvBuildImportListMp.CurrentCellDirtyStateChanged,
        Dim dgv As DataGridView = DirectCast(sender, DataGridView)
    End Sub

Open in new window

I'm using COM-interface which belongs to 3rd part program. In this COM-structure there's a function getElements which returns a class IscrElementList and it stores IscrElement items.

IscrElementList has two property count and item. I have chance to access item by item(int index)

In my method i'm getting these IscrElement items like;

Dim objList As IScrElementList = mdl.getElementList(False)
        For i As Integer = 0 To objList.count - 1
            Dim obj As IScrElement = CType(objList.item(i), IScrElement)

Open in new window

Is it possible to get this items via using Linq ?

Any help would be grateful. Thanks.

I have a tool like a picture below and it's getting bigger and bigger so it's hard to Debug it and work it. So i decide to seperate it to modules as on picture below but i don't know how is it possible because all modules are using same global variables and i don't how is it possible to link them.

Any help would be grateful. Thank you.
I have tiles that I am loading in a repeater using
For each tile, when they hover over the percentage I want to display a tag that is a button.
I want to use Jquery to do this, but I also want to make sure that it's displaying the 'View More' tag that is tied to the corresponding percentage label. Is this possible?

This is my code. I simplified the table so it wouldn't have all the fields. It just has the fields that are concerned with my question.
<table id="TableTraining" class="display scrollTable cards" style="width: 100%; text-align: left !important; font-size: 14px;">
                <tr class="colorFontRTOBlue" style="font-size: 12px;">
                    <th class="">Percentage
            <tbody id="dataContainer" clientidmode="Static" runat="server">
                <asp:Repeater ID="repRepeater" runat="server">
                        <tr id="row" class="<%# Eval("divRowClass").ToString()%>" style="cursor: pointer;">
                            <td class="stylRow5Perc stylTileLabel stylTileActive stylActivePercent">
                                <asp:Label ID="lblActiveStatus" Text='<%# Eval("ActiveStatus").ToString()%>' runat="server"></asp:Label>
                                <asp:Label ID="lblPercentageTile" Text='<%# Eval("Percentage").ToString()%>' 

Open in new window


I am using the following code in creating an chart
        Dim series4 As New Series()
        series4.Name = "Series 4"
        series4.ChartType = SeriesChartType.Line
        series4.Color = Drawing.Color.Green
        series4.BorderWidth = 2
        series4.XValueMember = "Date"
        series4.YValueMembers = "Day Work Rate"
        series4.LegendText = "Day Work Rate"

Open in new window

I want to flip the axes of the chart. Should I just use

 series4.XValueMember = " series4.XValueMember = "Date"
        series4.YValueMembers = "Day Work Rate"
        series4.YValueMembers = "Date"
        series4.LegendText = "Date"

Open in new window

I am try to take a 1 dimensional array of data and transform it to display in X number of columns each with X number of rows for each page into a datatable to easily display as the sample below shows. I am not sure the best way to do this.

Just to test the example I want 3 columns per page, and each column will contain 3 rows with the sample data below there should be 2 pages with 3 columns and a 4 page will have only 1 col and 1 row of data remaining.

samplearray= "{"100","110","120","130","140","150","160","170","180","190","200","210","220","230","240","250","260","270","280"}"

Example Output:

[Page #1]

[Column #1]     [Column #2]     [Column #3]
100                     130                    160
110                     140                    170
120                     150                    180

[Page #2]

[Column #1]     [Column #2]     [Column #3]
190                     220                     250                    
200                     230                     260                    
210                     240                     270                    

[Page #3]

[Column #1]     [Column #2]     [Column #3]
Anybody has a good example Using Exchange Web Service (EWS) to get the emails from and specific folder?

 have a Folder call it Filesemail  and I would like to get the email form that specific folder

im using

thank you
I have a Main TabControl and it has several TabPages and this TabPage's has several tab controls and continues like this. Main TabControl is not directly the main container of datagridviews.

I'd like the list all DataGridViews under this Main Tab control and clear their rows.

How can i do that? Any help would be grateful.
I'm using below code to split my filename and get into string array after that i'm writing them  to datagridview. In here if it's index out of bound for example filenameArr(2) is not existing how can i show it simple "-" string value.
            Dim filename As String = Path.GetFileNameWithoutExtension(str)
            Dim filenameArr() As String = filename.Split(New String() {"__"}, StringSplitOptions.None)
            dgv.Rows.Add(, filenameArr(0), filenameArr(1), filenameArr(2), filenameArr(3), filenameArr(4))

Open in new window

I want to post a MP3 file on my website.  I am using   When the user clicks on the file I need it to play.  One option I tried was to just put a hyperlink to the file.  On edge and chrome it works fine but in IE it asks to download or run.   I need the file to play without asking to download or run.    Any help would be appreciated.

thank you

Visual Basic.NET





Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to  Visual Basic pre-2002, it is not the same technology,