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

I am doing this:

   cmbRunList.Items.Add(myreader("Run Description").ToString())

This run description is what i am shown. How do i add a hidden value to the dropdown that is not shown but i am able to use latter in the code?
Hi. In what code would I use to see if the site has been published. I have to run slightly different code to what I run in debug mode.
I want to practice by creating a few applications.  I can't seem to find a free download that when i download contains Where can i go to download this?
Hi. When I select an item in my DropDownList I don't see the value in the variable P below
Also after the section the DropDownList text is  blank. What might cause this

    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

        Dim P As String = Me.DropDownList1.Text

    End Sub
I currently use the following connection string in my code to connect to a local database
Server=(localdb)\MSSQLLocalDB;Integrated Security=true
What connection string would I use to connect to the local database shown in the following image

I am used to creating an email body using html in a string.
I have now been asked to create an email body from a SQL ntext field.
How would I do this in Is it similar?

I am using my local host to authenticate into the Xero API

Dim myxerocallbackurl = "https://localhost:51970/Default.aspx"

but am getting the following error


what are the possible causes? In my Xero app do I have to specify the local host?
Hi all.

I have a checkedlistbox that I populate via the code below. I also added a ContextMenuStrip that when the end user right clicks a row (regardless if it's checked or not) I want to be able to edit the text. To do this I need to get the SelectedValue but unfortunately with the code below, the SelectedValue (i.e. StepID) is blank.

What am I doing wrong? Thank you in advance.

Private Sub LoadSteps()

        Dim con As New SqlConnection
        Dim cmd As New SqlCommand

        con.ConnectionString = "Data Source=myserver;Initial Catalog=mydatabase;Integrated Security=True"


        cmd.Connection = con

        cmd.CommandText = "SELECT Step, Completed, StepID FROM CRMOpportunitySteps WHERE OpportunityID = @OpportunityID ORDER BY StepID"
        cmd.Parameters.AddWithValue("@OpportunityID", opportunityID)

        Dim sda As New SqlDataAdapter(cmd)
        Dim dt As New DataTable()


        CheckedListBox_OpportunitySteps.DisplayMember = "Step"
CheckedListBox_OpportunitySteps.ValueMember = "StepID"

If dt.Rows.Count > 0 Then
            For i As Integer = 0 To dt.Rows.Count - 1
 CheckedListBox_OpportunitySteps.Items.Add(CStr(dt.Rows(i).Item(0)), dt.Rows(i).Item(1))

 End If
    End Sub

Private Sub EditToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditToolStripMenuItem.Click

        Dim itm As String

        itm = 

Open in new window

I am having issues trying to populate a datagrid that has predefined columns. The array is 46 in length and I am trying to populate each row with the right information.

I have the code below but it only populates the first first and the first 3 cells. In the 4th cell I do have a combox, could this be what is holding it up?

  ArrayGWHIZModel = strDataCOM1.Split(New Char() {Chr(13)}, StringSplitOptions.RemoveEmptyEntries)
                    If ArrayGWHIZModel.Length = 46 Then
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), True, ArrayGWHIZModel(3), True, ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), ArrayGWHIZModel(2), ArrayGWHIZModel(3), ArrayGWHIZModel(4), ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), ArrayGWHIZModel(2), ArrayGWHIZModel(3), ArrayGWHIZModel(4), ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), ArrayGWHIZModel(2), ArrayGWHIZModel(3), ArrayGWHIZModel(4), ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))

Open in new window


I am quite confused as to what I can do and what I cannot do within the UploadComplete event of the AjaxFileUpload control.

There are 2 ASPX Label controls which are assigned values within the UploadComplete event, however, the assigned values do not appear on the page after the event completes. The uploaded file is saved to the designated directory, however.

I'm including the ASPX, the VB code behind and the web.config files as follows:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
	<form id="form1" runat="server">

			<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

			<asp:Label ID="Label1" runat="server"></asp:Label>

			<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpeg,jpg,gif" />

			<asp:Label ID="Label2" runat="server"></asp:Label>


Open in new window

VB Code Behind
Imports AjaxControlToolkit

Partial Class _Default
	Inherits System.Web.UI.Page

	Private Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete

		Label1.Text = "Here we are 1."

		AjaxFileUpload1.SaveAs("C:\inetpub\ClientWebs\AjaxFileUploadSync\Images\" & e.FileName)

		Label2.Text = "Here we are 2."

	End Sub

End Class

Open in new window

<?xml version="1.0" encoding="utf-8"?>


		<compilation debug="true" targetFramework="4.0" />
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />



			<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />



Open in new window

Any assistance you might provide would be most helpful.

Much thanks,
David Bach
Hi.  There are times when DNS and a PC name do not match, and can determine this with PING -a, for example, I ping Computer 1 and returns an IP address, then PING -a the IP address and find the IP is associated with Computer2. I once wrote a simple batch that pinged the PC by name, captured the IP, then PING -a and if the PC names don't match, there's a conflict. That worked well.

Is there an elegant way to do this type of verification in   I have an app that depends on connectivity to a remote PC host (on an AD domain), but it fails if there's a DNS conflict.  I'd like to verify there's an actual DNS issue in VB, instead of calling on CMD to check.
Hello. I am a newbie to programming. I'm working on a web form in So my files are set up so that I have a Master page and aspx pages that look like this.
<%@ Page Title="" Language="VB" MasterPageFile="~/Layout.master" AutoEventWireup="false" CodeFile="delete.aspx.vb" Inherits="Appointment_Online_delete" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="wide" Runat="Server">
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

Open in new window

   I have everything built.  But on the form I want a collapsible panel.  I've tried all the basic tricks I know and nothing works.  I have no problem doing this on a page with only 1 button but this page will have 2.  One button to submit the form and the other button to expand a content div or panel.  No matter what I've tried when I click the button to expand the panel or div it doesn't do anything but jump to the top of the page and trigger all my form validators.  It seems like it tries to submit the form also.   Like I said, I've tried several different way to do it but this is the way I would like to do it if I can get it to work.

Here is the panel
<asp:Panel id="pnlfaq_content" runat="server" Visible="false">

Open in new window

As you see I start off with the visibility of false because I want the user to click the button to see the FAQ information.

This is my button.  I've tried different types of buttons but I think a asp linkbutton is what I need. Let me know if there is something better.
<asp:LinkButton ID="btnFAQ" runat="server" onclick="btnFAQ_Click" CssClass="btn b_g" Style="width: 80px;"><span>FAQ</span></asp:LinkButton>

Open in new window

I was hoping it would be so simple as to just add this in my code file .aspx.vb
Protected Sub btnFAQ_Click(sender As Object, e As EventArgs) Handles btnFAQ.Click
        pnlfaq_content.Visible = True
    End Sub

Open in new window

But this doesn't work.  It only sends to focus to the top of the page and triggers my form validators as if I was submitting the form.  

I would like some help in how to make this work.   Thank you.
VB .net creating mailitem via Microsoft.Office.Interop works for me but not others ??

They get the error...
System.BadImageFormatException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

I've already tried Target x86 in the compile options with no luck.
I've tried 2 ways of adding the Reference....

1. Add Reference/COM
2. Add via Nuget PM > Install-Package Microsoft.Office.Interop.Outlook -Version 15.0.4797.1003 (with Embed Interop Types = True)

All variations work on my machine (64 bit Win10 Administrator accounts) but not others (also 64 bit Win10 Administrator accounts)

When adding reference via COM and i check the properties i have an Identity = {00062FFF-0000-0000-C000-000000000046}\9.6\0\primary so I'm also wondering if this is a clue as the error is reported on 0006F03A-0000-0000-C000-000000000046 ??

All help appreciated

I am getting the following error "oShaft      Cannot obtain value of the local variable or argument because it is not available at this instruction pointer, possibly because it has been optimized away"
There are three rows of data in the GridView. I have included the html for the GridView below.

            Dim oGridView As GridView = Me.GridViewData
           Dim oGridViewRow As GridViewRow
            For i As Integer = 0 To oGridView.Rows.Count - 1

                oGridViewRow = GridViewData.Rows(i)

                Dim lblShaft As Label = oGridViewRow.FindControl("lblShaft")
                oShaft = lblShaft.Text

Open in new window

<asp:GridView ID="GridViewData" runat="server" AllowSorting="True" AutoGenerateColumns="False">
                 <asp:TemplateField HeaderText="Shaft" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Shaft">
                         <asp:Label ID="lblShaft" runat="server" Text='<%# Bind("Shaft")%>'></asp:Label>
                 <asp:TemplateField HeaderText="Site" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Site">
                         <asp:Label ID="lblSite" runat="server" Text='<%# Bind("Site")%>'></asp:Label>

Open in new window

I have created a new SQL database with all the required data and tables. The DB houses PDF's and other data. Using SSMS i can run query's and pull the data I need but it's not good for the staff.

What I want to do is to created maybe a simple web page (think google search) or front end where they can type in a key word, phrase, or combination of both and get a result list with a download option for the pdf/documents if any.

How would I start on creating such a front end? I have never made any front end's for SQL DB before
I have this code that works for joining a computer to a group, but occasionally fails to join. This does a search for the group, but I don't need to search, I know the exact name of the group and where it's located.  The user is adding the computer into the domain and then into groups using ldap credentials. This code searches for the group, but I have the name and location of the group so I want to avoid searching.

    Private Sub ComputerGroupAdd(ByVal GroupName As String, ByVal ComputerName As String)
            Dim sDomainName As String = "LDAP://mydomain.local"
            Dim adUserFolder As DirectoryEntry = New DirectoryEntry("LDAP://mydomain.local/DC=mydomain,DC=local")

            adUserFolder.Username = "mydomain.local\myUser"
            adUserFolder.Password = "mypassword"
            Dim adSearch As New System.DirectoryServices.DirectorySearcher(adUserFolder)

            adSearch.Filter = String.Format("(&(objectCategory=group)(sAMAccountName= {0}))", GroupName)

            For Each x As SearchResult In adSearch.FindAll
                Dim group As DirectoryEntry = x.GetDirectoryEntry
        Catch ex As Exception
        End Try
    End Sub

Open in new window

How can I add a computer to a group with credentials using the group's exact name and location. In other words, without searching for the group, which is what this code is doing. Thanks!
Hi there.

I'm a step further in my VB.NET study... and I ran into a problem when I'm supposed to create a BasePage.vb where I add the "Inherit System.Web.UI.Page" and after that edit an existing code behind from "Inherit System.Web.UI.Page" to "Inherit BasePage".
When I test the page, I get an error, that:

.... is not allowed here because it does not extend class 'System.Web.UI.Page'.

Even though it's all a bit new to me, it doesn't make sense, because the BasePage does inherit the System.Web.UI.Page...
Any idea what I'm doing wrong?
Let me know if you need more info.

Best regards

I have a program that will be launched by users on our network, but I only want one user to be able to open it at a time. I checked the option "Make single instance application", but that only keeps it from being launched more than once on the same computer.  How can I keep it from being launched more than once from any computers on the network?
I'm using MailKit and MimeKit in my VB.NET application to send out emails. In order to do this, the end user must configure settings like SMTP Server, Port, etc.

All of the end users have email clients installed, like Outlook or Thunderbird. Is there some way for my program to use the same credentials as those installed clients without the user having to enter them again? I'm assuming the answer is no, but wanted to ask those more experienced in this sort of thing.
Hi there.

Another question in my self-study of vb.NET:

I just tried deleting a control on a form, and I double-clicked a control because I wanted to add some vb-code. Later I deleted the control, but then I see, that the vb-code remains even though the control is gone.... and of course that causes a compiling error.
Is there a setting to automatically delete the related vb-code to a control, if the control is deleted?

Best regards

I am doing some VB.Net practice and learning.
For that purpose I need some SQL Server learning version or light version that is free and could be downloaded on my Widows PC.
I assume that is Microsoft web site that could be downloaded those anybody has some link or suggestion.
What is the future of VB.NET with .CORE?

Is .CORE only supporting C#?

Is VB.NET becoming obsolete?

Is .CORE replacing webforms?

What is the future of and webforms?

I am trying to update a database with info from a WinForm. I had no issues when using a “normal” SQL update command written by hand (parameters set to the text box values,) but I am trying to clean up and reduce my code and I thought I would bind the controls to a DataTable and use a DataAdapter's update command to achieve the same thing.

I have tried to get various combinations of setting parameters and update commands to work, but the Database is not getting updated from the new DataTable values. I have stepped through the code with each change and can see that the DataTable is getting the new textbox values, but those updates aren’t going to the Database. (This is seen when the Fill_Date block runs and selects all new data from the database.)

Things I’ve tried: Letting the binding get the new values vs. setting the parameters manually. Using the command builder to build the update command, using the .UpdateCommand.ExecuteNonQuery(), command and of course a straight.Update(DataTable) command.

Below is the code that I am using. I am hoping someone can tell me what it is I am doing wrong/missing, or what is the correct path to take. Is there a "best practice" or a better way to do this?

Public Class frmDATA
    Dim dt_Test As New DataTable
    Dim da_Test As New SqlDataAdapter
    Dim SQLcmd As SqlCommand

    Private Sub frmDemog_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Open in new window

I am calling GetOpenFileName() in Visual Studio and I want it to always appear on top of my current Main Form.
Is there a way in VB.Net to actively monitor a computer for when a new file has been created, an existing file has been edited, or a file has been deleted?

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,