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 have a form in html how to declare a codebehind in in the submit button in order to store the fields data on database?

On Demand Webinar: Networking for the Cloud Era
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Is there a way to retrieve Mapped Network Drives using Visual Basic .NET?

The following command retrieve some drives; however, it does not return the Mapped Network Drives.

We are reading a specific text file and  outputting it with new data, but noticed that the  output file doesn't get  created  and even less, no data seems to be exported.  We went step by  step and there is no error.

Please advice on what's missing in  the below code so it  can export the variable 'zFullPath'.

Imports System.IO
Public Class Form1
    Private Sub cmdExportIt_Click(sender As Object, e As EventArgs) Handles cmdExportIt.Click
        Dim inFilePath = "C:\temp\pIN.txt"
        Dim Vars, PrevPathname, zPathname, zFilename, zAllData, zFullPath As String
        PrevPathname = "blank"
        For Each Line In File.ReadLines(inFilePath)
            If Microsoft.VisualBasic.Left(Line, 13) = " Rans)(*&" Then
                zPathname = Replace(Microsoft.VisualBasic.Right(Line, Len(Line) - 14), txtExtractDrive.Text, "")
                zPathname = PrevPathname
            End If
            PrevPathname = zPathname
            If Mid(Line, 3, 1) = "/" Then
                zFilename = Microsoft.VisualBasic.Right(Line, Len(Line) - 39)
                zAllData = zPathname & "_" & zFilename 
                zFullPath = zPathname & vbTab & zFilename & vbTab & zAllData
                File.WriteAllText("C:\temp\pOUT.txt", zFullPath)
            End If
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
End Class

Open in new window

i have changed an old  windows application made in VB to website in c#.Both are referring a same vb dll code.for that particular dll code, Both the applications show sometimes the out of string space error and we are fine with that. But the freqency of out of string space error is very high for website comparatively of windows application. This code generates a report. so it first write the data from database into an xml file and then generates a word file. while writing that xml,this error comes.
I have checked for the same object ,in windows application it took 6-7hours but finally it gives the report. While in website in around 1 hour it gives out of string space error.
What cold be the reason ?
I want to use WIA objects in my projects through late binding.
What are some good websites to help keep me current with the latest and greatest for C#.NET Full Stack development?
Hi Experts,

My customer needs a report like this(Please see the attached report). How to create something like this. I have all the Data. I am using ASP.Net, VB.Net and RDLC reports. Please help.

Thanks in advance.
Can EE give us samples of how to read in a text file line by  line in Visual Basic 2017.
I am developing a printserver app and on the oldest Print Server is a windows 2003 server. When you query the Print Server for desiredn values instead of a straight IP Address you get for example IP_168.112.75.11 i NEED TO LOSE THE IP_ so I can access the network printer's web interface. I Know there's a replace command but I'm just looking for a quick answer that works I know this is easy for you Experts Please in VB.NET CONTEXT.

Thanks EE you guys kick ass.
We have an older Windows server (Contract) and I need some code that looks at the C: drive and gets me a simple GB and %free remaining

10.25 GB and 25%free
Enroll in July's Course of the Month
Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

A = Freefile()   'A is 1
Fileopen (A, File1,......

FileClose(B)    'B is not set yet BUT File1 is Closed !!!!
B = Freefile()   'B is 1  because file1 is closed !!!!!

FileGet(A .......    'gives an error (Bad file name or number)

closing an unopened file causes closing a previously opened file!!!!
Any body noticed this issue? or there is something I missed?
The following code has two counters. One runs directly from the form (in the main thread) and another is performed by a BackgroundWorker. Interestingly, the two counts do occur at the same time (which is the!) but the progressbar doesn't change at all until after the BackgroundWorker has finished. Of course, I'd like the progressbar to update during the counting. Help?

Note: The code below is just a test I'm performing so I can take the structure and expand it to a real-world, time-consuming, stored-proc.
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ProgressBar1.Maximum = 10
    End Sub

    Private Sub btnHeavyTask_Click(sender As Object, e As EventArgs) Handles btnHeavyTask.Click
        Debug.Print("Starting to count now")
        BackgroundWorker1.WorkerReportsProgress = True
    End Sub

    Private Sub mainThreadTask() 
        Dim i As Integer = 0

        Do Until i = 15
            Me.txtHeavyTask.AppendText(vbCrLf + i.ToString)
            i += 1

        Me.txtHeavyTask.Text = "Done"
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim i As Integer = 1

        Do Until i = 10

Open in new window

How to save all my listview item to arrays ?

I have just started trying to learn Visual Basic 2015 and the book I am using has in the code instructed me to use the following code :

"Val" to convert a text string; and
"Me" to reference the current form

Neither of which are recognisied by Visual Basic 2015.

    private void Form1_Load(object sender, EventArgs e)


        private void button1_Click(object sender, EventArgs e)
            Sum.Text = Val(Num1.Text) + (Val(Num2.Text));

  public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            Me.Text = InputBox("Enter a Caption...")

I have a screen that a user can either enter information(about 5-6 fields) and click Add Item or they can enter in an ID(one of the fields) and click Search and it will populate all the other fields. This works great. I had RequiredFieldValidators for the fields that are mandatory(all of them) and I noticed that when I tried to do a search that the fields would have the validation messages next to them and it would never hit the code behind for the search button. Obviously the validator is working on the client side and doing its job but it wouldnt let the server side code to run? I want to have the functionality of the search button to fill the fields with data and for the RequiredFieldValidators to work when the Add Item is clicked.
 Now, I read where you can set EnableClientScript="true" in the validators(client side) and that allows the server side code to run when I click Add Item but then the validators are allowing missing fields. I tried to set the EnableClientScripts back to false but when I test and click Add Item, with no data, its saving a blank record and thats not cool!!!
Any thoughts on this? Any help would be appreciated!!!

Hi EE,

in, I have a TreeView control.

each nodes (lets say I have 5) like this :


each of them has an "ID" or a "Code" in the background.  lets say its :

Apples     [0020]
Tomatoes   [0025]
Oranges     [0060]
Grapes     [0061]
Bananas    [0110]

My 2 questions are :

1) If I have a button "Add item" is it possible to add a node at the end of the tree, the user writes the name of the fruit, then he could drag the new node somewhere in between 2 fruits to place it where he wants it ?

2) since there are codes to each fruit, if user drags it in between [0025] and [0060] I would like the code to be automatically created at 0026 to be placed in between !

But it goes to another question, what If after the user creates another one and wants to place it in between of 0025 and 0026 ? now there is not space anymore between the codes ! we would have to increment of + 1 all the codes then place it in between.

so thats my issues... I realyl need help on this...
thank you.

(I am using fruits as an example but this is for work in our Logistic menu in our system. right now its not efficient, I have created the TreeView and reading values from SQL, but im stuck there for the rest)

I use the following code to dynamically edit a SQL table in a Windows Form DataGridView.
Most of the time things work but around one out of every 5 times I get the error shown in the image below.
Why would this be? Is there a better way to dynamically update a SQL table based on changes made by the user?

    Sub oDynamic_SQL_Save()

            Dim builder As New SqlCommandBuilder(dbadp2)

            builder.QuotePrefix = "["
            builder.QuoteSuffix = "]"

            dbadp2.UpdateCommand = builder.GetUpdateCommand()


        Catch ex As Exception
            MsgBox(Err.Description & " mmm")
        End Try
    End Sub

Open in new window

Dear Experts,

Can anybody help me to sort out the issue?

Issue Description : I need to get the textbox entered value in gridview at the time of linkbutton click event.

Design Page :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="prefLine"
                                                    AllowPaging="True" AllowSorting="True"
                                                    OnPageIndexChanging="GridView1_PageIndexChanging" Width="100%" BackColor="White" BorderColor="#999999" EnableModelValidation="True" GridLines="Vertical">
                                                        <asp:TemplateField HeaderText="Edit" >
                                                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#String.Format("frmSls.aspx?id={0}&det={1}", HttpUtility.UrlEncode(Eval("nSlsID").ToString()), HttpUtility.UrlEncode(Eval("nSlsDetID").ToString())) %>'
                                                                    Text="Edit" CommandName="select">

Open in new window

Hi all. I have a windows form created in (visual studio 2013) that is displaying the following error:

Conversion from type 'DBNull' to type 'Decimal' is not valid

In the following code:
Dim frm As New ContractEditItem
 frm.stdcost = DataGridDetails.SelectedRows(0).Cells("StdCost").Value

Open in new window

When the StdCost cell in the DataGridDetails datagrid is null. The StdCost cell is of type Decimal and the frm.stdcost variable is also of type Decimal.

There are times when records do not have a stdcost and there are times when it does.

First question: How can I fix this error?
Second question: There may be times when the end user will do some changes to some other fields and then click a Save button which will insert records into a table and the stdcost field may be null and this is ok for our systems, will I also get an error when that happens?

Thank you in advance.
PeopleSoft Has Never Been Easier
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Hey I am working on a Windows App in where I load a Dropdown box and a Listview with Printers from a Printserver.
I can do this if it were pulling data from a database but  the goal is to type in dropdown the Printername and dropdown autocompletes like a Google Search My Challenge is when dropdown is selected I want listview to filter to the name in dropdown.
Here is the visyuals and code. I don't know how to sort to printer in listview.
Printer App with dropdown wanting to sort to the desired Printer NAMEHere are the Print names next to Icon of Printer
Print App displaying all the Printers.
  Public Sub Printers()
        Dim options As ConnectionOptions
        options = New ConnectionOptions
        options.Username = "xxxxxx"
        options.Password = "xxxxxxxxxxxx"
        '* Test the connection

        '  Dim ps() As Services

        LSPrinters.Columns.Add("", 150, HorizontalAlignment.Center)
        LSPrinters.Columns.Add("Name", 150, HorizontalAlignment.Left)
        LSPrinters.Columns.Add("DriveName", 250, HorizontalAlignment.Left)
        LSPrinters.Columns.Add("Location", 250, HorizontalAlignment.Left)

        LSPrinters.Columns.Add("Port Name", 200, HorizontalAlignment.Left)
        ' LSPrinters.Columns.Add("Document", 150, HorizontalAlignment.Left)
        ' LSPrinters.Columns.Add("Jobstatus", 150, HorizontalAlignment.Left)
        '' LSPrinters.Columns.Add("PagesPrinted", 150, HorizontalAlignment.Left)

Open in new window

so its a basicaly a complaint form ,if the complaint is solved it should remove the row automatically from datagridview

How do I connect to a SQL server - and return a recordset? (Trusted_Connection=True)

For example (Select * from mytable where field1=1)

Using VB.NET

Thanks in advance

 I want to upload my excel data file to access using button event. Below is my code.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim Conn As OleDbConnection

        Dim Cmd As OleDbCommand

        Dim Filename As String = "D:\Ayyappan\claimDump.xlsx"



        Dim StrFileName As String = String.Empty

        Dim XLA As New OleDbDataAdapter

        Dim XLTable As New DataTable

        Dim StrSelect = "SELECT * FROM [{0}]"


        OpenFileDialog1.FileName = ""

        OpenFileDialog1.Filter = "Excel |*.xlsx|All files (*.*)|*.*"

        If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.OK Then

            Exit Sub

        End If

        StrFileName = OpenFileDialog1.FileName

        Conn = DBConn()


        Cmd = New OleDbCommand("INSERT INTO claimDump([a],[b],[c],[d],[e],[f])  SELECT * INTO [Excel 12.0 xml;DATABASE=" & StrFileName & ";Extended Properties=Excel 8.0;]", Conn)


        ' Catch ex As Exception

        ' MsgBox("Some error")


        'End Try


    End Sub

While running the code I got "IErrorInfo.GetDescription failed with E_FAIL(0x80004005" this error.

Am checking my excel sheet the header name is same as per the insert statement like a,b ,c etc..

Can anyone help me on that.

I have to insert a row in MS SQL when my application starts and update the same row when the application closes.

I'm know where to put the code, but how do I update the same row? (i have no uniq identifiers)

Thanks in advance

I have a subdomain subdomain1 in a primary domain
I created a folder myfolder under the subdomain root, and granted public read/write access on

When I write the following code In my windows application,
            Dim upload As New System.Net.WebClient()
            upload.UploadFile("" , mylocalfilefullpath)

I am getting error 404 (non existing folder or file. What Am I doing wrong. Thanks for the help

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,