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

Very simple VB Windows Application Question.  I have a form with a text box and a save button.  I want the user to type in a company name.  I want the company name they type in to be stored on the form for the next time they run the compiled EXE program so that we can use it until they change it again.
OWASP Proactive Controls
LVL 19
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

I am very new to .net but have but lots of years of vb 6 and before. Very simple form has a textbox and I have the following validating code:

  Private Sub tbOrderNumber_Validating(sender As Object, e As CancelEventArgs) Handles tbOrderNumber.Validating
        If Not tbOrderNumber.Text Like "########" Then
            e.Cancel = True
            MessageBox.Show("Invalid order number, please enter a valid order number.")
        End If

    End Sub

I have stripped all other code out of solution, This code works as I would expect it to, if the mouse is used to move somewhere else, but if a Tab is pressed it fires this sub twice. Why?

The code below causes my project to freeze, but despite using try catch method the error message does not appear, how do I solve this issue?
The code does not activate Message box "B". The AOPs.xml files looks ok while code is implemented.


         Dim curfile As String = (Application.StartupPath + "\AOPs.xml")
        fslinkBEL = New System.IO.FileStream(Application.StartupPath + "\AOPs.xml", IO.FileMode.Open)
        dtsetlinkBEL.ReadXml(fslinkBEL)  '*****Error Line
 Catch ex As Exception
        End Try
Hi all.

I'm getting the following error when trying to export the data from a datagridview component to Excel:

Creating an instance of the COM component with CLSID from the IClassFactory failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

Please note, this just started happening to one specific workstation, the end user was able to complete this task 2 weeks with no issue. When I do the same from my computer I do not get the same error, it exports the data to Excel.

Below is my code that exports to Excel:

Private Sub btnExcelExport_Click(sender As Object, e As EventArgs) Handles btnExcelExport.Click

        Dim oXLApp As Excel.Application       'Declare the object variables
        Dim oXLBook As Excel.Workbook
        Dim oXLSheet As Excel.Worksheet

        oXLApp = New Excel.Application  'Create a new instance of Excel
        oXLBook = oXLApp.Workbooks.Add  'Add a new workbook
        oXLSheet = oXLBook.Worksheets(1)  'Work with the first worksheet

        oXLApp.Visible = True               'Show it to the user
        oXLSheet.Range("A" & ":" & "A").NumberFormat = "@"
        With oXLApp
            Dim Col As DataGridViewColumn
            Dim i As Integer = 1
            For Each Col In DataGridView1.Columns
                .Cells(1, i).Value = Col.HeaderText
                i += 1
            i = 2
            Dim RowItem As DataGridViewRow

Open in new window

I am trying to get multiple selected items from a listbox. I have tried several examples found online but not having any luck.  Below is some sample code.
        Dim value As String = String.Empty
        Dim values As String = String.Empty
        categoryID = String.Empty

        'If (ls.Items.Count > 0) Then
        '    For i = 0 To ls.SelectedItems.Count - 1
        '        If (ls.Items(i).Selected) Then
        '            value += " " + ls.Items(i).Text + ","
        '        End If
        '    Next
        '    value = value.Trim()
        'End If

        If (ls.Items.Count > 0) Then
            For index = 0 To ls.SelectedItems.Count - 1
                value += " " + ls.Items(index) + "," 'ls.SelectedItems(index).ToString
                values += " " + ls.SelectedValue.ToString
        End If

        'For Each item As ListItem In ls.Items
        '    If item.Selected Then
        '        value += " " + item.value + ","
        '        'If selectedIndex = "" Then
        '        'selectedIndex = item.Value
        '        'Else
        '        'selectedIndex = selectedIndex & ", " & item.Value
        '        'End If
        '    End If

        If value.Trim() <> String.Empty Then
            value = Strings.Left(value, Len(value) - 1)
        End If

        categoryID = value

Open in new window

I have an serial communication interface application in It was working fine earlier but now I am getting "?" Instead of data. Not able to understand why it is happening like that. Kindly help.
Thanks in advance
How do I write a VB6 DriveListBox, DirListBox, and FileListBox in VB.Net?
I open an excel program from my .net program. The user sends data to the cells and then closes the form inside excel.

How can I monitor this application close and if it does get closed I return to my .net application?
I need to embed a webbrowser to link to a specific website that will only work in Google Chrome or FireFox - they are not supporting IE.

I am using windows forms in visual studio (

Can I embed a webbrowser that will run Chrome or Firefox embedded in my form and NOT opening up in a separate window?

I have an chart control inside an panel control on a web form.  I am trying to move the chart control in the horizontal direction only while it is in the panel.  I won't to do this because the chart control is wider than the panel control.  I don't want to use scrollbars because I cannot change the appearance of the scrollbars for other browsers like Edge.  Changing the color only works on IE for me.

So, I want to use a mouse move event on the chart control to move the chart horizontally to view the chart areas hidden behind the panel boundaries.  I have researched this and cannot find anything that matches what I am trying to do.

Can anyone help please!?
<asp:Panel ID="Panel7" runat="server" Width="470px" HorizontalAlign="Left"
                                            ScrollBars="None" Height="270px" Direction="RightToLeft" 
                                                CssClass="invisibleOverflow" BorderStyle="None" ><br />
                                            <asp:Chart ID="ChtCHART2" runat="server" DataSourceID="SqlDataSource2"
                                                Width="400px" BackColor="Black" EnableViewState="True"
                                                BackImageAlignment="TopLeft" BorderSkin-BackHatchStyle="LightHorizontal"
                                                BorderSkin-BackGradientStyle="TopBottom" BorderlineWidth="2" Height="230px">

Open in new window

CompTIA Cloud+
LVL 19
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hi , I need to create Power APP from Visual studio 2019.But i can't find in Visual studio 2019
How to give users the Printpreview for color settings in
Hi All,

Hope your well,

I have a VB script which is nearly there but just a small part missing.

The script is being configured to delete certain contacts with a particular attribute set. Within that subset of contacts with this particular attribute im also adding some additional logic to not delete all of them e.g.

as an example: I look for contacts with extensionattribute1 set with "SPECIALATTRIBUTE", I then say, if email address 2 is populated DO NOT DELETE, move on to the next. My aim is to delete all of these contacts without an email address 2 set. The bit where im stuck is that I'm also trying not to delete contacts that have a certain domain e.g but im not sure on the contains context. My ultimate goal is to look for contacts with a particular attribute, keep the ones that have an Email2address set and if their email1address contains and then delkete the rest that do not match these conditions.

Set objRecord = objItem.Find("[Extensionattribute1] = ""SPECIALATTRIBUTE""")

While Not objRecord Is Nothing
      If objRecord.Email2Address = "" And objRecord.Email1Address <> "*" Then objRecord.Delete

      Set objRecord = objItem.FindNext

Many Thanks.
I have website and I want to record changed field in to log table, for eg. That page has 20 textbox then I want to know which field User changed out of 20, so I can maintain
that in log table, Please let me know
We sell commercially an application developed in Visual Basic .NET (currently in VS 2008, though we're looking at making the upgrade to VS 2019). Reports from the application can be output as either Crystal Reports text reports displayed on screen or native Microsoft Excel files (created using Automation). One of our customers has told us that their auditors are requiring that they produce reports which are provably unaltered. While Excel is a format they prefer, there's no way to know if the cells were changed after the file was created, so for the time being they're giving their auditors Crystal Reports output exported to PDF.

If I could digitally sign the Excel file I create, I believe that would meet the audit requirement. However, I can't figure out a way to sign a document under program control, with a signing certificate that would be held safely inside the executable and couldn't be hijacked. Is this a pipe dream, a self-contradictory desire? Or is there a way to make this work? Or is there another way to accomplish the same thing, of an Excel file that can be reliably locked when it's created by a Visual Basic application?
Hi All,

I want to send message to WA from desktop application using

Please see below code.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MaiWA
    public class CWhatsapp
        private const string QR_CODE_XPATH = "//img[@alt='Scan me!']";
        private const string SEARCH_INPUT_XPATH = "//input[@title='Search or start new chat']";
        private const string CHAT_INPUT_XPATH = "//div[@class='_2S1VP copyable-text selectable-text']";
        //private static int TUNDA = 2000;
        private static IWebDriver _driver = null;

        public void StartWhatApp()
            _driver = new ChromeDriver(new ChromeOptions { LeaveBrowserRunning = false });
            _driver.Url = "";

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

        public bool OnLoginPage()
                if (_driver.FindElement(By.XPath(QR_CODE_XPATH)) != null)
                    return true;
                return false;
            return false;

        public void StopWhatApp()

        public bool KirimText(string 

Open in new window

I am trying to move a large Visual Basic .NET project from VS 2008 to VS 2019 Community Edition. In VS 2019, I am getting huge numbers of errors like

Requested operation is not available because the runtime library function 'System.Runtime.CompilerServices.AccessedThroughPropertyAttribute..ctor' is not defined.

Other functions are named on other occasions, such as "System.Runtime.CompilerServices.DateTimeConstantAttribute..ctor".

Even more strangely, I'm getting error BC30002, "Type 'System.String' is not defined", and the same error for other types (Void, Int32, DateTime, Decimal, etc.).

Clearly, some sort of reference linking the Windows forms app to runtime modules isn't getting loaded, but I can't figure out what's missing. I've looked at the VS 2019 version and the VS 2008 version, and the project references seem to match. Can you offer suggestions of how to get them properly loaded, and eliminate the current 75,000(!) errors?
Need to create setup app using MS Installer, VB.NET, and VS2017.

So far no coherent step-by step instructions for the MS Installer is found.

The efforts to produce this instructions (video, web page) is much appreciated. However, nothing works.

Posting a question is not possible because it's not yet known. Thank you for the help.
How to create a datatable with the time format string incremeted with nearest 15 minutes.
I am using


Dim dt as new datatable

If the string value is 2:32 then the datatable should have rows in time incrementing by around 15 minutes :

Having rows like :


String value is 4:34 then the datatable should have rows in time incrementing by around 15 minutes :

Having rows like :


Please let me know if you have any further queries.

Rowby Goren Makes an Impact on Screen and Online
LVL 19
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

I don't need a lesson on how to use an Event with a control in a control. The problem here is that the event is in a repeater in a control within the repeater:
                <asp:Repeater ID="repRows" runat="server">
                        <uc:BulkRow runat="server" ID="BulkRow" ></uc:BulkRow>

Open in new window

I have a repeater in the parent control. Inside the repeater is a child control that contains all of the form elements.

When the submit button is clicked for that row in  the child form elements control, I want to raise an event to trigger something in the parent control that has the actual repeater.

However, it is not triggering my parent repeater control's event handler.

BulkControl - parent
contains repeater and defines the handler on the ItemDataBound:
    Dim bulkRowCtrl As BulkRow = CType(e.Item.FindControl("BulkRow"), BulkRow)
        AddHandler bulkRowCtrl.AlertEvent, AddressOf AlertEventHandler

Open in new window

BulkRow child Control contains the event:
    Public Event AlertEvent(ByVal alertMessage As String)

Open in new window

and raises the event:
 RaiseEvent AlertEvent(alertEventMessage)

Open in new window

When I raise the event within the child control, it never triggers it in the parent control.
Need to read 2 values from a query in

            Dim nusa15 As String = "SELECT pagadot,nombre  FROM cheque WHERE id = '" & CustomerId & "'"
            Dim cmd15 As New OleDbCommand(nusa15, cn)
            valor = (cmd15.ExecuteScalar())

Open in new window

this one get me only pagadot that i asign to valor

how to get nombre in the same

what is the way dear experts
I am new to using web services.  I've created the Web Reference to the following Web Service:
And I was giving the following sample code: (see attached Sample Home More Request.xml)
I don't know how to move forward now that I created the Web Reference. My project is in VB.NET
How do you make a compatible referencing for Office libraries to work with Office 2010 and above while using  Visual Basic? I am using MS office object libraries. I also reference MS Excel Object Library. Will that be a problem?
I need to implement Google reCaptcha on an old ASP.NET VB Webforms platform and I need a complete code that would help me do that.

I haven't done VB before and have done some webforms development long time ago.

I have followed the instructions of the following link but can't seem to get it right.  I have added the Assembly Recaptcha.dll on the frontend code with the associated VB code inside a <script runat=server> tag just like the guide and after recompiling and replacing the compiled code on the site, it doesn't seem to be able to load the Assembly and pops out the following error message,

Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load file or assembly 'Recaptcha, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

Source Error: 

Line 1:  <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="register.aspx.vb" Inherits="Website.Members.clsRegister_Page" %>
Line 2:  
Line 3:  <%@ Register TagPrefix="uc1" TagName="ucMessageBox" Src="../controls/ucMessageBox.ascx" %>

Open in new window

All in all if you could help with with the exact implementation code, I would really appreciated it.
Anyone know how to get S.M.A.R.T. drive info from

i.e. id like to call a function and have it return if the drive is OK or having issues. Being as smart is enabled and we can query WMIC, id think this is possible. Anyone know how i could modify the above code examples to get that?


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,