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

Need a module to merge PDF's
is any idea or some freeware that achive that, we can't purchase several PDF pro licences only for that propouse.
Pleas help me out you experts!
I have an event for my datagridview currentcelldirtystatechanged, because when i'm selecting a item from my DataGridViewComboboxCell and run another method before commit it it returns nothing so i found a solution with below code;

    Private Sub CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgvList1.CurrentCellDirtyStateChanged
    End Sub

Open in new window

But i have several datagridviews to do that same eventhandler. Is there a way yo use a single Sub to handle other datagridviews for Dirty State Changed.

I am converting an old VB6 program to VB.NET. I have a lot of it converted and working.. However I occasionally run into situations that elude and I need additional assistance. I am at another one of those junctures.

I am now working on the FTP portion of my code. Admittedly the previous VB6 code only required the 'DownLoad' properties and so it has worked fine for many years. I googled several  solutions but I am still having trouble getting files up to my server.  I can access the server with FileZilla and I can also upload files from a 'Command Window' via FTP as well. The code I currently have fails with the Following error: "System.Net.WebException: 'The remote server returned an error: (553) File name not allowed.'" I am using Visual Studio 2017 Express.

The files I am trying to upload are image .JPG files and the names of the files are all digits except the extension. Maybe someone can spot where I went wrong...


        Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create("" + ThisUPC + ".jpg"), FtpWebRequest)

        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile

        ' Confirm the Network credentials based on the user name and password passed in.
        ftpRequest.Credentials = New 

Open in new window

I have an ASP.Net webforms app with a GridView.  (The Gridview automatically generates the columns on binding because the data source is dynamic and the number of columns vary.)

I have code in place so when a cell in the GridView is clicked by the user it will display some data relative to the clicked cell in a Panel via the ModalPopupExtender control (from AJAX control toolkit).

The problem I have is the ModalPopupExtender fires BEFORE the GridView_RowCommand.   I need to run a query in the GridView_RowCommand event to collect the data to populate the labels in the Panel control, that is displayed via the ModalPopupExtender.   The query needs to run in the GridView_RowCommand event because this is where I get the needed Row and Cell index data for the query.

How do I get the ModalPopupExtender to fire AFTER the GridView_RowCommand event?

ASPX code (Pertinent):

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

    <style type="text/css">



        background-color: Black;
        filter: alpha(opacity=90);
        opacity: 0.8;




        background-color: #FFFFFF;
        border-width: 3px;
        border-style: solid;
        border-color: black;
        padding-top: 10px;
        padding-left: 10px;
        width: 300px;
        height: 140px;



                        <asp:GridView ID="grdKanban" runat="server" 

Open in new window

In, how can I get a reference to a property of a specific instance of an object?

I know I can do something like this

            Dim P As PropertyInfo
            P = Me.GetType.GetProperty("acRecordSource")


But how can I save a reference to *this* property of *this* instance so anywhere in my code I could type:


and get the value of Property P for instance Me?  (Because varP refers to the "acRecordSource" property of instance Me?

I found this code to compile and execute code in runtime:

 Dim entrada As String


            entrada = My.Computer.FileSystem.ReadAllText("Codigo1.txt")
        Catch ex As Exception
            MessageBox.Show(" Erro : " + ex.Message)
        End Try

        Dim codigo = <code>
                       Imports System
                       Imports System.Windows.Forms

                       Public Class TempClass
                           Public Sub ResultadoTexto(ByVal txtOutput As TextBox)
                               <%= entrada %>
                           End Sub
                       End Class


            Dim vbProv = New VBCodeProvider()

            Dim vbParams = New CompilerParameters()

            vbParams.GenerateExecutable = False

            vbParams.GenerateInMemory = True

            Dim resultadoCompilacao = vbProv.CompileAssemblyFromSource(vbParams, codigo.Value)

            If resultadoCompilacao.Errors.Count > 0 Then

                For Each er In resultadoCompilacao.Errors

                Dim obj As Object = 

Open in new window


What is the coding difference between c# and
I am looking from syntax point of view.
Any suggestion are appreciated.

I am starting to use vbconversions software to translate some of my vs2008 projects over to c#.  These projects have been running for years on Symbol/Zebra scanners, and vs2008 is as high as I can go while developing apps for these devices.

vbconversions software is a paid subscription, and so far seems to do a very good job.  In the most recent conversion, I'm getting two errors that I need help with.

The code I've been using to play .wav files is:

    'This is the setup to make the PlaySiren sub work, to play a .wav on the scanner for errors...
    Public Class win32
        Public Declare Function PlaySoundW Lib "coredll.dll" Alias "PlaySoundW" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
        Public Const SND_FILENAME = &H20000
        Public Const SND_ASYNC = &H1
        Public Const SND_SYNC = &H0
    End Class

...and there is a line at the top of the module that says "Imports System.Runtime.InteropServices".

Someone gave me this code years ago to play .wav files on the scanners, but I must admit I don't understand what all is being done here or how this works.  I may have come from an e-e contributor long ago.

Then when vbconversions did the translation to c#, it created this code:

            //This is the setup to make the PlaySiren sub work, to play a .wav on the scanner for errors...
            public class win32
                  [DllImport("coredll.dll",EntryPoint="PlaySoundW", …
I had this question after viewing Concurrency Violation Error.

Using Vb.Net and VS2017. I am trying to update a SQl table and everything works fine when I test the code with a variable (integer) set to a number that is in the table as a PK. However, when I load the same variable with the PK taken from either the datagridview (DGV) column or the dataset that fills the DGV I get a concurrency violation error. Single user so no update violations. The update are carried out with parameters. Here are some snippets of code.

This works
 ' Create the UpdateCommand.
        DiD = 137 ' This works
        sqlString = "UPDATE Data SET  PaidIn = @PMPaidIn WHERE DataID =@DiD"
        command = New SqlCommand(sqlString, connection)
        command.Parameters.Add("@DID", SqlDbType.Int).Value = DiD
        command.Parameters.Add("@PMPaidIn", SqlDbType.Decimal).Value = PMPaidIn

        adapter.UpdateCommand = command

Open in new window

but when I do this

Private Sub DgvData_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvData.CellValueChanged

        If e.RowIndex < 0 Then Exit Sub
        row = e.RowIndex
        DiD = dts.Tables(0).Rows(row).Item("DataID") ' When debugging this DataID is 137 but violation occurs
more code load the variables for other columns
End Sub

Open in new window

I have checked GetType() of the DiD variable and DataID
The following visual basic code fails to run.

       Dim srce As String = "C:\Users\ZZZ\Documents\My Great Data\Audio"
        Dim dest As String = "T:\My Great Data\Audio"

        Dim MyProcess As Process

        MyProcess = New Process

            With MyProcess.StartInfo
                .FileName = "C:\Windows\SysWOW64\robocopy.exe"
                .Arguments = srce & " " & dest & " /S /E /M"
                .UseShellExecute = False
                .CreateNoWindow = True
                .RedirectStandardInput = False
                .RedirectStandardOutput = True
                .RedirectStandardError = True
            End With


However running the following PowerShell script works fine

robocopy "C:\Users\ZZZ\Documents\My Great Data\Audio" "t:\My Great Data\Audio" /S /E /M


I think the problem is the fact that the srce & dest contains spaces.

How can I make this work?
Anybody installed Visual Studio 2019 yet?

I plan to instal it in prep for a code camp, and wonder who else has it running.

Let me know.

Hi all.

I have a Chart object in my Visual Studio windows application, I'm using VB.NET.

The problem I'm running into sometimes is when some of the columns have really low values compared to other columns with really high values, for example, one stacked column will have a Y value of 50 and another stacked column will have a Y value of 1,000 then the 1,000 stacked column will be cut off at the top. I have 2 series, the first series is a stacked chart that sums up the sales for each product line and the second series is a line chart type which is a sum of all the stacked columns for each year. From my screen shot you can see that it's cutting of the second series (line chart). Any help would be appreciated!

Here's my code to load the chart:

Private Sub LoadChartProductLine()


Dim query As String = "SELECT ProductLine, SalesYear, Sales, TotalYearSales"
        query += " FROM CRMProductLineSales WHERE AccountID = '" & txtPMID.Text & "'ORDER BY ProductLine"
Dim dt As DataTable = GetData(query)

        If dt.Rows.Count = 0 Then
            Chart1.Visible = False
            Exit Sub
            Chart1.Visible = True
        End If

        'Get the DISTINCT product lines
        Dim productlines As List(Of String) = (From p In dt.AsEnumerable() Select p.Field(Of String)("ProductLine")).Distinct().ToList()
        Dim years As List(Of Integer) = (From p In dt.AsEnumerable() Select 

Open in new window

I have a project written in VB.Net. My updates to the SQL Server are working fine except when I restart my project all changes are lost. After a lot of searching I found that I have to change 'Copy to Output Directory' to 'Copy if Newer' or 'Do Not Copy' (depending which site I read) in the properties of the database in Solutions Explorer. I can change the Copy to Output in properties of the form but I don't have the database in my Solutions Explorer. Totally lost and confused. I am teaching myself from VBA to VB.Net.
Any help would be appreciated.
How can I take advantage of the WPF rich design content inside a project. I am looking to create a cool splash screen with a login screen using WPF.
The question I have because I have not played with WPF inside a application what issues would this cause and is it even recommended?
I am working on a app that that two dropdownlist that autopostback.  My problem is when selecting my reset button
the autopostback dropdownlist does not reset. I am using a javascript in an attempt to reset the dropdownlist.

All other fields in the form reset except the dropdownlist and capthcha as well once the capthcha accepts the page.

There is a masterpage as well.

Any clues?


<div class="form-group">
                    <div class="col-xs-12 col-md-8 col-sm-10 nill">
					    <asp:Label ID="lblSubject" runat="server" AssociatedControlID="ddlSubject" Text="Subject *" CssClass="control-label" />
					    <asp:DropDownList ID="ddlSubject" CssClass="form-control" runat="server" aria-label="Subject" required="required"  AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
						<span class="required"></span>
                  <div id="divQuantity" class="form-group" runat="server" Visible="false">
                       <div class="col-xs-12 col-md-8 col-sm-10 nill">
                       <asp:Label ID="lblQuantity" runat="server" AssociatedControlID="ddlQuantity" Text="Medicine Disposable Bags *" CssClass="control-label" />
                        <asp:Dropdownlist  ID="ddlQuantity"  CssClass="form-control" runat="server"  aria-label="Medicine Disposable Bags" required="required" AutoPostBack="true" 

Open in new window

Greetings.... OK maybe a somewhat embarrassing question...

I am New to Visual Studio 2017 and all of it's nice new features. I have started on VB.NET a program/application and got some of the functionality done. I wanted to make sure that I could 'Deploy' the  program easily so I installed the 'Installer' package into VS 2017. I was successful in getting an .msi package created and working. (everything worked).

I have since continued to work on the Main program and in the process have created Files and Folders that need to be deployed along with all other executables and libraries..

Here is the embarrassing part,,, how do I RE-RUN the Setup Wizard in VS2017 so that I can add all the files and folders. I have done a lot of Google searches and have even searched EE but apparently I am "asking the wrong question" because so far I not found an information on how RE-RUN/REBUILD the Install package.

Please forgive me, I know there is probably an easy answer but so far it has eluded me...


Don't know if there is a solution like this, but I am looking for a software or tool that I can use to have the programmers collaborating in software development, history software versions, privileges to access codes, able to assign programmer to specific codes, possibility to have start/end-dates for each software to developed that has been assign, possibility to have at least 2 o 3 programmers work with the code simultaneously (and when done, the software tool would merge all changes into the code) and finally some sort of history of each code on who have worked on it, who started it, who finished it.  The programmers work with VB. Net.

Thank you very much for you help.
I need help with the following code.  Both SourceFile and TargetFile contains spaces.  How do I make this work?  Currently it does nothing.

    Dim RoboCopyArgs As New StringBuilder

    With RoboCopyArgs
                        .Append(" ")
                        .Append(" /S /E ")
                    End With

                    Dim proc As Process = Process.Start("C:\Windows\SysWOW64\Robocopy.exe", RoboCopyArgs.ToString)


I am trying to write code that will determine the resolution of the screen the user is using in order to properly size charts.  I am having trouble getting anything to work. Can someone please help? I am using ASP.Net chart control and

Following is code that does not work.

Thanks for the help.

Dim CurScreenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim CurScreenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
        Dim DesignWidth As Integer = 1680        
Dim DesignHeight As Integer = 1050 
        Dim WidthRatio As Single
        Dim HeightRatio As Single

        WidthRatio = CurScreenWidth / DesignWidth
        HeightRatio = CurScreenHeight / DesignHeight

        Dim ChartWidth As Single = DesignWidth * WidthRatio * 0.96         
Dim ChartHeight As Single = DesignHeight * HeightRatio * 0.85

Open in new window


I am converting and old VB6 program to VB.NET. Currently I am working on the function that takes a 'Listing File'  and uploads it to eBay. This function uses the eBay File Exchange API and has worked flawlessly for years within the VB6 program. I have modified/Converted it to VB.NET but I am still having some kind of issue with it. The API seems to execute fine but I receive the following error from the File Exchange 'Manager': "An unknown problem interrupted the file transfer. Please try again" The file that I am using as a test works fine and is uploaded to eBay  from the VB6 program so I am confident that the file is good with no syntax errors. I know that this might be a difficult task but hopefully another set of eyes can help me. I am including both function here for comparison.... Thanks in advance - Rick

Private Function PostListingsToEbay(UploadFileName As String) As String
    On Error GoTo MyTmpError
    Dim xmlHTTP As New MSXML2.ServerXMLHTTP40
    Dim MyBase64 As New Base64
    Dim XMLNodeValue As String
    Dim sContactURL As String
    Dim sUploadContents As String
    Dim sResponse As String
    Dim csUserNamePassword As String
    Dim sFileName As String
    Dim sEntityBody As String
    Dim RtnVal As Integer
    Dim RtnValue As Integer
    RtnValue = MsgBox("Are You 

Open in new window

How do you copy a HUGE file from one location to another using Async in Visual Basic 2015?
OK Greetings..

I have done some searching and I have not quite found the answer to my issue so I guess I will ask the question here. (I'll include code snippets)

(1) I use Visual Studio 2017 express
(2) I Use Visual Basic .NET
(3) I am creating a Windows Application

OK.. I have a ListView Control  contained with a TabControl on a Form... The ListView has a Header of 40 fields and I can populate as many rows as I desire each with 40 fields of data.. (all working).

I need to get each row from the list and output that row data to a .TXT file but NOT All of the fields of data and NOT in the same order as represented in the ListView Header.

I actually have most all of this working EXCEPT my code will output a Duplicate record for the number of records within the ListView control..  Example if I have 3 rows of data and a header record  it will successfully output the desired number of data fields in the desired order for the first row of data then it will REPEAT/DUPLICATE that row of data for the number of rows in the ListView Control and then one more for the Header row.. ie 4 in the current example..

The following code snippet  is what I currently have and need a bit of help. Please note that I load the Header field names into an Array and then use that array
to INDEX into the ROW Item data.

BTW I hope that this is the right way to ask and or present questions to EE.. If not please let me know.
Thanks in advance.

I have this date string:
2018/05/23 22:15:14

I want to subtract 5 hours and return the date time in AM/PM format. But when I do, I get the message:
String was not recognized as a valid DateTime.

I've tried:

                  Dim newdate As DateTime = Now()
                    Dim getDate2 As String = "2018/05/23 22:15:14"

 newdate = DateTime.ParseExact(getDate2, "MM/dd/yyyy HH:mm:ss", Nothing)
and this:
newdate = DateTime.Parse(getDate2)

I was going to do this afterwards to deduct the 5 hours, but I never get that far:
newdate = newdate.Date().AddHours(-5)

I saw a webpage with an example and it has this:
' From
        time = DateTime.Parse("2009/02/26 18:37:58")

So why is this not a valid datetime?
2018/05/23 22:15:14

Hi Experts,

I have a report exported to Excel that contains info with headers and details.

looking to write a script that will just obtain all details along with the name portion of the header.

Purpose of this, to export all this into a SQL table.

See example attached.
In, I have a combobox's "SelectedValue" property bound to a field of a datatable.  When I select an item from the combobox, the SelectedValue gets saved and the ColumnChanged event of the DataTable is triggered; however, when I clear the combobox, neither the SelectValue gets saved to the DataTable nor does the ColumnChanged event get triggered.  How can I get a Null value to be saved to the bound field of the DataTable when the combobox is cleared?

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,