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 datagridview whose styling is kept as follows

    dgvCreatinine.AutoGenerateColumns = False
            dgvCreatinine.AutoSize = False
            dgvCreatinine.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill
            dgvCreatinine.DataSource = dtTemp

It is appearing as shown in the attached image

As you can see the gridview is not resizing to the content along row wise. Could someone tell me how this can be accomplished? Thanks in advance.
I have two series with Legends being added to a chart in

creatinine_series.LegendText = "Creatinine (mg/dL)"
creatinine_series.IsVisibleInLegend = True


urineOutput_series.LegendText = "Urine Output(ml/kg/hr)"
urineOutput_series.IsVisibleInLegend = True

But only urineOutput_series legend shows up. creatinine_series legend doesn't showup. I have no clue why this isn't appearing.

Also I would like to position two legends (If both of them show up). How to position them. Please kindly help me get though this issue.

We have a simple application that was done by a predecessor. All it does is allows users to enter 'item numbers' and send to print. The item data is saved on a separate excel sheet in the same folder. All dll files, EXE. file and excel file are in the same folder. I've just copied this folder to a new machine trying to replicate the process. I can run the application but when I click send to print button on the application I get below error;

"Unhandled exception has occurred in your application if you click continue the application will..."

"could not load file or assembly microsoft.reportviewer.common version="

I've tried installing the relevant files for above exceptions. However, think this is to do more with the 'Print' button on the application and coding behind it.
Please see attached.

Can someone advise what I need to do to get this to work please?

Thanks in advance.
For a stored query (name is "CREAT_Plot") like the following in Access, what would be the or C# code to call this query and also pass a parameter in place of "[Reports]![TestReport]![Subject]"

SELECT CREAT.Subject, CREAT.CREAT, (IIf([CREAT.TargetDays]=".",".",Val([CREAT.TargetDays])*24)) AS TargetDays
WHERE (((CREAT.Subject)=([Reports]![TestReport]![Subject])))

I have googled about this but could not find an example to call stored query that prompts for input parameters.
Please kindly give me small code snippet to achieve this one.

Thank you
How can I convert this HEX string to a readable result? I get this string returned from a device I am sending a function to. What can I use to parse and represent the actual result from the device?

HEX String
I am develop application using VB.Net with SQL Server, and i use dataset to bind data to GridView, but my Field is stored Unicode Character (Khmer Unicode) with collation 'Khmer_100_Bin". To select data from this field correctly i need to use prefix N' , But my concern is i am using dataset with variable @a so i don't know how to use prefix N with that variable, anyone can help me about this?

Note:: My dataset Query is in picture attached.

Thanks in advance.

I'm writing a COM component, basically an enumerable class (so I can use the for .. each loop from VBA).

I managed to write the Following wich work:
<ComClass(FieldValidators.ClassId, FieldValidators.InterfaceId, FieldValidators.EventsId)>
Public Class FieldValidators
    Implements IEnumerable

#Region "GUID COM"
    Public Const ClassId As String = "2d368af9-55a7-4cca-a79d-06b6c3a91554"
    Public Const InterfaceId As String = "5094acfa-2799-491d-b7f0-ebc4a2d0e755"
    Public Const EventsId As String = "a31bb5c3-99c6-4548-85cc-fbe83d407867"
#End Region

    Private mFieldValidators As List(Of IFieldValidator)

    Public Sub New()
        mFieldValidators = New List(Of IFieldValidator)
    End Sub

    Protected Overrides Sub Finalize()
        mFieldValidators = Nothing
    End Sub

    Public Sub Add(ByRef validator As IFieldValidator)
    End Sub

    Public Function Count() As Long
        Count = mFieldValidators.Count
    End Function

    Public Iterator Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
        For Each fieldValidator In mFieldValidators
            Yield fieldValidator
    End Function

    Default Public ReadOnly Property item(ByVal index As ULong) As IFieldValidator
            item = mFieldValidators(index)
        End Get
    End Property
End Class

Open in new window

But the resulting enumerator is poorly typed (IEnumVARIANT), I would like to return objects of type IFieldValidator.

Is it doable ?
Hello.  I am creating XML files including schemas based on several tables in an MS SQL database:


Open in new window

From a VB.NET WinForms app, I receive the XML output as a string.  I am trying to take these XML strings and create NEW tables that match the schema in the XML as well as the row data.

At first I thought the datatable.ReadXML function would be able to read SQL XML files as-is, but they do not.  There is probably a better way to do this, like a Stored Procedure that takes the XML as input, uses the schema to automatically create a new table, and then import the rows.  I just can't find an example online.

I am a first-time poster, please forgive me if I didn't include enough info or did anything else wrong.  :)  Thanks!
Using is there a way to get .Net FrameWork and IIS versions?

I'm trying to build a simple COM component (class Library) usable with from VBA, but so far it isn't working as expected (I recieve a DLL loading error whenever I try to add a reference).

I'm using Visual Studio Community 2017 / Visual BAsic.Net /  .Net Framework 4.6.1, the source code compile, the COM component is Registered, but no way to add a reference to it.
What did I miss ?

For record, here is the source code:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1

#Region "GUID COM"
    ' Ces GUID fournissent l'identité COM pour cette classe 
    ' et ses interfaces COM. Si vous les modifiez, les clients 
    ' existants ne pourront plus accéder à la classe.
    Public Const ClassId As String = "2f55bb60-0e65-4056-b6cb-d4883b531da6"
    Public Const InterfaceId As String = "5fdb7171-a274-4ee8-94b9-4346050233f5"
    Public Const EventsId As String = "b451bac4-a9b5-4874-bc36-e292dfdf33c5"
#End Region

    ' Une classe COM pouvant être créée doit avoir Public Sub New() 
    ' sans paramètre, sinon, la classe ne sera pas 
    ' inscrite dans le Registre COM et ne pourra pas être créée 
    ' via CreateObject.
    Public Sub New()
    End Sub

    Public Function getValue() As String
        getValue = "bla blah"
    End Function

End Class

Open in new window

I'm using the MSChart in and it works fine a few times then eventually gets a memory error.  I'm pretty sure the error occurs on execution of this line:


This isn't my code, just trying to support it so I'm not really sure what it's doing or why it's failing.

Here's the error:  -2147467261: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Any ideas?  Thank you so much!
Hi Experts,

I have the following code which works fine for Win8 OS, while in Win7 it gives me an error, "cannot connect to the server".

Someone already helped me set this up in one Win7 pc, however now I need to move this over to another pc.

    Dim objHTTP As New WinHttp.WinHttpRequest

            Set objHTTP = New WinHttp.WinHttpRequest
            url = ""
            objHTTP.Open "POST", url, False
            objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            objHTTP.Send "grant_type=client_credentials&client_id=MyID&client_secret=MySecretID"
            ResponseText = Right(objHTTP.ResponseText, Len(objHTTP.ResponseText) - 17)
            access_token = Left(ResponseText, InStr(ResponseText, """") - 1)

Open in new window

PS. this only happens when trying to access secured accounts (Hipaa).

As far I remember we did applied those attached last time, but so far this didn't help.

Thanks in advance.
Hi there I have created webservice client which works fine when posting single parameterized string. Now I need to pass multiple strings in one post. Can some please help me to guide in right directions.

From below code snipet I need to repeat whuMailInDispatchOrderLines multiple times.
Dim PostRepairDataRequest As New ServiceReference1.whuMailInDispatchUpdateInfoType With {
           .dispatchId = dispatchId, _
           .shipper = shipper, .trackingNumber = trackingNumber, _
           .repairOrders = {New ServiceReference1.whuMailInDispatchOrderLines() With {.oldSerialNumber = oldSerialNumber, .serialNumber = OrderLinesSerialNumber,
            .comptiaCode = comptiaCode, .comptiaModifier = comptiaModifier}}

Open in new window

I have a Datagrid with bound fields using a SQL Datasource
I have buttons for Save, Add etc
I notice that when I click 'Save' after filling out some text boxes, I see no change in the gridview, NOR does the SQL table update.
IF I subsequently click AGAIN, it saves the row to SQL, AND the Gridview shows the new line of data.

I have a

Open in new window

command at the end of the Try block for the Save function
I also trued a DataBind in the  

Open in new window

Event Handler, to no effect

I currently have a menu

I want to be able to edit the menu using javascript which will be bound to a user control.
The sitemap generates a

Open in new window

with the list of links
I see that the menu text does not have IDs

The menu text does not have an ID for the links, so how can we modify the parameters of the link using javascript?

This is the code of a hyperlink within the table:

<td style="white-space:nowrap;width:100%;"><a class="ctl00_lft_LinkList_linkList1_1 ctl00_lft_LinkList_linkList1_3" disabled="true" style="margin-left:12px;">Compression</a></td>

Open in new window

I want to change the td here so that we can change disabled="true" to disabled="false"
Hello experts,

I have an application on vb net that runs searches through "indexing service" on a server with "windows server 2008 r2", but the application was migrated to a new server with "windows server 2012 r2", where the "windows search service" is used, so my application no longer works. What should I adjust to my code to use "windows search service"?
Please Help... I need to freeze the heading row in a GridView.

I am utilizing the GridView in a routine that exports the contents of a DataTable to HTML, in Excel format.

Before I render the grid to HTML, I wanted to do some cell formatting , hoping that these customizations are then reflected in the exported XLS.

Here is my routine:


 Sub ExportSpreadsheet(dtExport As DataTable, strExportPathAndFilename As String)

        Dim gvReport As New GridView()

        gvReport.AllowPaging = False

        '-- Load the GridView
        gvReport.DataSource = dtExport

        gvReport.HeaderRow.BackColor = Color.LightGray

        For Each gvRow As GridViewRow In gvReport.Rows

            For Each gvCell As TableCell In gvRow.Cells

                If gvRow.RowIndex Mod 2 = 0 Then
                    gvCell.BackColor = Color.White
                    gvCell.BackColor = Color.AliceBlue
                End If

                gvCell.Wrap = False

                If IsDate(gvCell.Text) Then
                    gvCell.HorizontalAlign = HorizontalAlign.Center
                End If



        Dim swReport As New StringWriter()
        Dim hwReport As New HtmlTextWriter(swReport)


        '-- Write XLS-file to disk
        Dim streamReport As New StreamWriter(strExportPathAndFilename)
Hi All,

I have a GL project. This a project will be called by any other project.
One of the feature is showing forms from other project, for example form for sales order :

1. At project A is frmSalesInvoice
2. At project B is frmSalesInvoiceWithRoll

How could I solved this problem ?

Thank you.
I'm trying to embed an Outlook Popup warning that warns the Sender when they hit the send button, if 2 or more recipients (To, CC or BC) of the email contain 2 different domains. For example: To contains (; CC contains ( Another example: To contains (;

See code that I have so far, it just is not working:
The message code to use for the popup is:
        prompt = "This email contains receipients to multiple domains:" & vbNewLine & strMsg & "Are you sure you want to send?"
        If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Warning! About to send to messages to multiple domains") = vbNo Then
            Cancel = True
        End If
I need to be able to read rfid tags using a HID Omnikey 5022 reader using
Hi All,

I have a data with date time value '2015-12-01 22:19:15.020'
I save it to  

 dim dteCrtDate as datetiem = DateTime.Parse(dtRowTransaksi("CrtDate").ToString)
 dteCrtDate = '#12/1/2015 10:35:49 PM#'

dteCrtDate = DateTime.Parse(dtRowTransaksi("CrtDate").ToString("yyyy-MM-dd HH:mm:ss.fffffff"))
Conversion from string  "yyyy-MM-dd HH:mm:ss.fffffff" to type 'integer' is not valid.

dteCrtDate.ToString("yyyy-MM-dd HH:mm:ss.fffffff") =  '2015-12-01 22:36:58.0000000', the problem at milisecs

How could I save to variable and format it into  '2015-12-01 22:19:15.020'?

Thank you.
I have a function that makes my .doc lose functionality, but it works for me in .dotm...
The function is "ActivateReferenceLibrary"; it runs on both the "Document_New" and "Document_Open" stage.
I know it is this function that is causing the issue because when I comment out the call function for it everything works.

Any ideas as to why this is happening? What am I doing wrong?



Sub ActivateReferenceLibrary() 'Activate Specific Object Libraries via GUID #

  Dim chkRef As Variant
  Dim BoolExists As Boolean
    On Error Resume Next
    For Each chkRef In VBProject.References
        If chkRef.GUID = "{00062FFF-0000-0000-C000-000000000046}" Then
            BoolExists = True
            GoTo Cleanup
        End If

    If BoolExists = True Then
        Exit Sub
        VBProject.References.AddFromGuid GUID:="{00062FFF-0000-0000-C000-000000000046}", Major:=0, Minor:=0 'This is Outlook GUID
    End If
End Sub

I'm able to pass the query parameter successfully to the field however when the item is saved the record is not being saved to the list. What's interesting is that if I manually override the passed value by typing into the field on the form and then clicking save, the record is saved to the list .

We have a working example of this on the same site for a different list that we created about a year ago and does not have this issue.

Original Code Provided when a new form was created for the list in SPD:
<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="New" FieldName="AttachmentsID" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@AttachmentsID')}"/>
<SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="AttachmentsID" ControlMode="New"/>

Removed the above code and replaced with the following:                                                            
<asp:TextBox runat="server" id="ff1{$Pos}" Name="FileName" Text="{$AttachmentsID}" Value="{@AttachmentsID}" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@AttachmentsID')}" Width="100px" Height="20px" BorderWidth="0" />
I created a form in VB10 containing an animation control generated by the MICROSOFT animation control SP6 Control (MSCOMCT2. OCX), but together with the executable I generate 2 libraries (axinterop. MSCOMCTL2. DLL and INTEROP. MSCOMCTL2. DLL) without which the executable does not work.

There is no way not to generate the executable without the help of these 2 libraries, from what I understand there should be a statement to do in the code.
I have a database table that contains the following fields:
1. RecordID
2. Time
3. Action - The Action is either 3 - (StartTime) or 4 - (StopTime).
4. Name
5. Vehicle

Currently I use the following SQL to gather the data:

"SELECT [EventLog].[Date Time], [Events].[Description], [EventLog].[Operator Name],
                                           [Vehicles].[Truck Type] AS 'Vehicle ID'
                                           FROM EventLog INNER JOIN Events ON [EventLog].[Event ID] = [Events].[EventLog Number]
                                           INNER JOIN Vehicles on [Vehicles].[Device Type] = [EventLog].[Serial Number]
                                           WHERE (([Date Time] between '" & DateTime & "' AND '" & DateTime2 & "') AND
                                            ([EventLog].[Event ID] = '3' OR [EventLog].[Event ID] = '4')) ORDER BY
                                            [EventLog].[Operator Name], [EventLog].[Date Time], [Vehicles].[Device Type] ASC;"

But every other record contains either a (StartTime-1st, or StopTime-2nd).
I need the time difference between Start & Stop times, this will give me the running time for each Operator using a particular Vehicle in HH:mm:ss.
Is there any way to incorporate this time difference calculation within the SELECT SQL so I put this data directly into a DataGridView?
This would help by reducing the total number of records in half.

Thank you in advance,

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,