Visual Basic.NET

94K

Solutions

24K

Contributors

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 access a web page via code and try to export and download an excel file. But at the usual 'Open Save Cancel' window I can't get the save button to fire!
I found a few similar posts here but the solutions found don't work!

Here is what I have !

Code:
        Sub ClosePopup(ByVal WindowHandle As IntPtr)

        Dim clsChildHandles As ArrayList = GetChildWindowHandles(WindowHandle)
        Dim teststr As String
        Dim prthandleint As Long
        'look through all of the child handles of the window for an "Save" button (this method
        'can also be used to gather more specific information about the dialog itself, such as
        'the message being displayed)...
        For Each ptrHandle As IntPtr In clsChildHandles
            'if the Save button is found, click it...
            teststr = GetWindowText(ptrHandle)
            prthandleint = ptrHandle ' was having trouble with putting an intptr in debug.print!
            Debug.Print(teststr & " = Child TEXT:   len=" & teststr.Length & "handle = " & prthandleint & vbCrLf)

            If teststr.Contains("&Save") Then
                ClickButton(ptrHandle)  ' THIS PART WORKS AS I GET HERE!
                Exit For
            Else
                Debug.Print(teststr & " = ELSE Child TEXT:   len=" & vbCrLf)
            End If
        Next

    End Sub
 
    Const BM_CLICK As Long = &HF5&
    Public Const WM_LBUTTONDOWN As UInteger = &H201
    Public Const WM_LBUTTONUP As UInteger…
0
i had a datagrid control that reports out a series of values. I would like to bind those values in a chart control object so that if I select a value on the datagrid then it will highlight in the chart.

What are the binding properties to do this?
0
I know this will be simple but I cant seem to get there without help.


I have a VB.net project and I want to print onto multiple pages.  Could someone please take a look at the attached code a tell where I'm going wrong.

Private Function PreparePrintDocumentVATDetail() As PrintDocument
        ' Make the PrintDocument object.
        Dim print_document As New PrintDocument

        ' Install the PrintPage event handler.
        AddHandler print_document.PrintPage, AddressOf Print_PrintPageVATDetail

        ' Return the object.
        Return print_document
    End Function

    Private Sub Print_PrintPageVATDetail(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)

        Dim bottomMargin As Integer = Me.PrintDocument1.DefaultPageSettings.Margins.Bottom / 2
        Dim topMargin As Integer = Me.PrintDocument1.DefaultPageSettings.Margins.Top / 2
        Dim leftMargin As Integer = Me.PrintDocument1.DefaultPageSettings.Margins.Left
        Dim rightMargin As Integer = Me.PrintDocument1.DefaultPageSettings.Margins.Right

        Dim pageHeight As Integer = Me.PrintDocument1.DefaultPageSettings.Bounds.Height - topMargin - bottomMargin
        Dim pagewidth As Integer = Me.PrintDocument1.DefaultPageSettings.Bounds.Width - leftMargin - rightMargin
        Dim fontHeight As Integer = Me.lstCustCode.Font.Height
        Dim itemCount As Integer = pageHeight / fontHeight
        Dim x As Integer = leftMargin + 10
        Dim y As Integer = 

Open in new window

0
Adding items to a combo box
0
Hi there.

I'm a bit confused. I am working on how to use Visual Studio 2019 to create VB.NET web sites/applications. In my very first test project I got things with CodeBehind. Now I can't  seem to find that project type anymore that create the CodeBehind, because my next little project only makes Codefile. I use the "ASP.NET Web Application" to start a new project.
Any idea what is wrong here (beside me...)?

Best regards

Ulrich
0
We have a VB.net program that collects sensor data from hardware and then writes that data to a comma delimited file every one second.  We just learned that our client has written his own program (I don't have the source code), that reads our CSV file and displays some of the data from that file in the UI of his program.  Initially we were only writing to our file every 5 seconds and they asked us to speed up the process to every 1 second.
Now there is an occasional error message that our program has stopped working.

I have never run into this before and I'm wondering if my client's program could be causing the crash of our program by attempting to access the same CSV file that we are appending to.
0
I am using Visual Studio 2015 on a Windows 10 laptop. I have a Web Forms project that uses .NET Framework 4.5.2 and is done in Visual Basic .NET. I want to add a REST API to the project. I made a change like this to a C# Web forms project, but I can't get my code changes to work. I reverted my changes to start from scratch. I had to add a Global.asax.vb file to me project.

How do I add the REST Web API?
0
Hi, I have json string and I want to parse in vb.Net so I can select individual values, What will be simplest way to do that, I am attaching my code
Dim serviceUrl As String = "http://localhost:61210/Webservice/PService.svc"
        Dim input As Object = New With { _
                        .UserId = "14"
        }
        Dim inputJson As String = (New JavaScriptSerializer()).Serialize(input)

        Dim httpRequest As HttpWebRequest = DirectCast(WebRequest.Create(New Uri(serviceUrl & "/InsertLogInLog")), HttpWebRequest)
        httpRequest.Accept = "application/json"
        httpRequest.ContentType = "application/json"
        httpRequest.Method = "POST"

        Dim bytes As Byte() = Encoding.UTF8.GetBytes(inputJson)

        Using stream As IO.Stream = httpRequest.GetRequestStream()
            stream.Write(bytes, 0, bytes.Length)
            stream.Close()
        End Using
        Dim strText As String

        Using httpResponse As HttpWebResponse = DirectCast(httpRequest.GetResponse(), HttpWebResponse)
            Using stream As IO.Stream = httpResponse.GetResponseStream()
                strText = (New StreamReader(stream)).ReadToEnd()
            End Using
        End Using

Open in new window

0
I am using VB,NET 2017 and need to create a second worksheet in a workbook and loading data into it.
0
We have normal win10 users without the permission to install apps. What id like to do is to have them run my VB app when they login and have it still be able to have elevated permissions to do software installs.

I.e. it would launch non-elevated but maybe a GPO could allow that specific app elevated admin permissions?

Is this possible?
0
Hello,
I am getting an error 'Parameter is not valid'
   Using ms As New MemoryStream(imageData, 0, imageData.Length)
                            ms.Write(imageData, 0, imageData.Length)
                            Try
                                image = Image.FromStream(ms, True)
                                Dim oldbitmap As Bitmap = (image)
                                clsFrmain.ScaleImage(PicImageFin, oldbitmap)
                                OriginalimageLoaded = oldbitmap
                                PicImageHeight = PicImageFin.Height
                                PicImageWidth = PicImageFin.Width
                            Catch ex As Exception
                            End Try
                        End Using

Open in new window

It usually happens for large files especially PDF.

Any suggestion.

Thanks
0
I know that:

     "Selection.GoTo(What, Which)"

does not work when the "Selection" (Word document) is in "Web Layout".
(Note: the currently selected "Layout" can be viewed in the "View" menu on the left hand side).

To *GET* the current Page/Line # from within Word VBA I call:

        Dim iCurPage As Long
        Dim iLineNum As Long
       
        iCurPage = Selection.Information(wdActiveEndAdjustedPageNumber)
        iLineNum = Selection.Range.Information(wdFirstCharacterLineNumber)

      (I Store this information for later use).

To *SET* (move the cursor and set focus to) a newly opened document to the last Page/Line # from within VB.NET I call:

     Public theApp As Object
     theApp = Application

     theApp.Selection.GoTo(What:=Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage, Which:=Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute, Count:=iPage)
     theApp.Selection.GoTo(What:=Microsoft.Office.Interop.Word.WdGoToItem.wdGoToLine, Which:=Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToRelative, Count:=iLine - 1)


     (I hate and have disabled the "Welcome Back" feature).

I can *GET* the Page / Line #'s regardless of whether the document is in Print or Web Layout.  I don't care.
However, since I cannot *SET* the Page / Line when the document is in Web Layout, I programmatically:

     Change to Print Layout
     *SET* the cursor and focus to the Page / Line #
     Change back to Web Layout

The problem is that…
0
I am using Visual Studio 2017 mvc with Visual Basic. I want to have a view with two tables from my model. In my controller I have tried to set up a dynamic expandoobject (my code below).
Dim viewData As Object = New Dynamic.ExpandoObject()
            viewData = db.tblDivision.Where(Function(c) c.ExpireDt Is Nothing).ToList()
            viewData = db.tblGroup.ToList
            Return View(viewData)

When I go to the view, I can't find the correct way to define the modeltype to use the dynamic object. I have tried the below but it is not working.
@Modeltype IEnumerable(Of Dynamic.ExpandoObject)
@Model  viewData
0
I created a DataGridView with one text box and 8 comboboxes. I added these fields and the ComboBox collections through UI and then programmatically bound the columns using the following code:

  Private Sub UsersForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim conn As New SqlConnection(GlobalVariables.strConn)
        conn.Open()
        Dim sql As String = "SELECT User_Name, DefaultTeamType, PreDrill, Drilling, Completion, Frac, Facility, Pipeline, Workover FROM Users"
        da = New SqlDataAdapter(sql, conn)
        Debug.Print(sql)
        ds.Clear()
        da.Fill(ds, "Users")
        DataGridView1.DataSource = ds.Tables("Users")
        DataGridView1.RowsDefaultCellStyle.BackColor = Color.White
        DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray

    End Sub

When I open the form, the rows are filled but the combo boxes display the first value in the combo box collection.  I suspect I need to update the ValueMember setting but I am not sure how to set that.  Thanks for your help!
0
I have a form that contains 4 toolstrip buttons. The Problem is that I need to click the Save button more than one time to fire the action....Please can you advice me how to do.
0
I have a Parent Table Called Clients and a Child Table Called Insertion. Since Ms-Access 2007 does not support Transaction VB.Net I am looking for the best way to delete a child then a parent, but I want a method in case any error happens that prevent the 2 Queries to execute.

If we are using Transaction we can ROLLBACK but as I told you access 2007 doesn't support that

DELETE * From Child Table WHERE Condition

If Query 1 Execute with no error then go to query 2 otherwise abort the operation

DELETE * From Parent Table WHERE Condition

if Query 2 Execute with no error display a message otherwise abort the 2 execution
0
SSIS on SQL Server 2016 instance
Web Request Task is being used to upload data to a website.  Current coding works with existing address and key.
The new address and key is failing with a code of 4, indicating lost connection when GetRequestStream. I wrote a standalone VB.NET app with exact code and ran it without errors.  I placed the code below, without the actual address and key of course.  The failure occurs at this section of the code….

 Dim NewStream As Stream = REQUEST.GetRequestStream()
 NewStream.Write(bytes, 0, bytes.Length)
 NewStream.Close()

Private Function SEND_DATA_JSON(ByVal JSON_DATA$, ByVal ADDR$, ByVal KEY$) As String
        Try
            Dim baseAddress As String = ADDR

            Dim REQUEST As HttpWebRequest = CType(WebRequest.Create(New Uri(baseAddress)), HttpWebRequest)

            With REQUEST
                .Headers.Add("Authorization", KEY)
                .Accept = "application/json"
                .ContentType = "application/json"
                .Method = "POST"
                .ContentLength = JSON_DATA.Length
                .Credentials = CredentialCache.DefaultCredentials
                .KeepAlive = False
                .Timeout = -1
            End With

            Dim parsedContent As String = JSON_DATA
            Dim encoding As UTF8Encoding = New UTF8Encoding()
            Dim bytes() As Byte = encoding.GetBytes(parsedContent)

            Dim NewStream As Stream = REQUEST.GetRequestStream()
            

Open in new window

0
Private Sub GetEmployee()
        'Clear COMBOBOX...
        cmbEmployee.Items.Clear()
        OLEDBControls.ExecQuery("SELECT empId,empName FROM Employees;")
        'If Records are found, then add them to COMBOBOX....
        If OLEDBControls.RecordCount > 0 Then
            For Each r As DataRow In OLEDBControls.OledbDS.Tables(0).Rows
                cmbEmployee.Items.Add(r("empName"))
            Next
            cmbEmployee.SelectedIndex = 0
            cmbEmployee.MaxDropDownItems = 5
            cmbEmployee.ValueMember = "empId"
            cmbEmployee.DisplayMember = "Name"

        ElseIf OLEDBControls.Exception <> "" Then
            'Report Error..
            MsgBox(OLEDBControls.Exception)
        End If
    End Sub

    Private Sub GetEmpID()
        Dim id As Integer
        id = Me.cmbSite.SelectedValue
        MsgBox(id)
    End Sub

    Private Sub cmbEmployee_DropDown(sender As Object, e As EventArgs) Handles cmbEmployee.DropDown
        GetEmployee()
    End Sub

    Private Sub CmbEmployee_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbEmployee.SelectedIndexChanged
        GetEmpID()
    End Sub

Please I want to return the employee id for a selected Text but it returns zero...please need your help
0
I have a VB 10 project that utilizes 5 MS Access databases.  I need to know what references I need to add to my project deployment so that end users do not have to have MS Office installed on their system.  I load the databases when the project opens. I think I need the MS Office PIA dll for MS Access, but I would like a DB expert to advise me about this.
0
Hi All,

I want to delete data from dgv selected rows.

My Code:

 Private Function Delete_Data(ByRef intRow) As Boolean

        Delete_Data = True

        intRow = 0 

        Me.intMode = ERV_Global.MB_DEL

        Me.Text = Screen_Function.ErvMasterFormHeader(Me.intMode, strFormText, ERV_Global.strIndonesiaLanguage)

        Dim intCounter As Integer = dgvTMUSERMENU.Rows.GetRowCount(DataGridViewElementStates.Selected)

        If intCounter = 0 Then Exit Function

        Dim strMessage As String = ""

        If intCounter = 1 Then
            strMessage = "Hapus Data Ini ...?"
        Else
            strMessage = "Hapus Beberapa Data ...?"
        End If

        If MsgBox(strMessage, MsgBoxStyle.YesNo, Me.Text) = vbYes Then

            Try

                For Each dgvRow As DataGridViewRow In dgvTMUSERMENU.SelectedRows

                    strKey = dgvRow.Cells("Oid").Value.ToString.Trim

                    MsgBox(dgvRow.Cells("ProgNm").Value.ToString.Trim, MsgBoxStyle.Information, Me.Text)

                    strSqlCommand = "DELETE FROM " & strFileName & " WHERE Oid = '" & strKey & "'"

                    Dim cmdSqlCommand As SqlCommand = conApp.CreateCommand()
                    cmdSqlCommand.CommandType = CommandType.Text
                    cmdSqlCommand.CommandText = strSqlCommand

                    If conApp.State = ConnectionState.Closed Then conApp.Open()

                    cmdSqlCommand.ExecuteNonQuery()

                    

Open in new window

0
My Visual Studio 2015 VB.NET Website project is compiling at 8 minutes. It should be a lot faster. It also compiles everything rather than just the changed items.

Prior to VS2015, it worked fine. After updating, it started doing this.

I will be moving to VS2019, but want to get this figured out.

This is a VB.NET Website (not web application). We are using VB 12 now.

How do I get on the latest VB.NET compiler and put it on here?
How do I get it to compile only the changes, not everything?

Thanks!
0
I work with SSRS reports in VS 2015 VB.NET.
How do I make a subreport to show specific information for each section of the main report?
For instance, how do I show account details for each account ?
I know how to populate the subreport with data on the event handler, but how to populate the subreport to show different data for each account ?
I have this on the page load:
AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubreportProcessingEventHandler
The question is how to handle the parameters for each and every account to show only specific account details?
Do I neet to do it on aspx.vb form or in the report or in both places?
0
I am working in VB.NET VS 2015, SSRS
I have a main report and a subreport, both are based on the SQL Server stored procedures.
I populate both reports at form load events.
My subreport appears on the group level of the main reports.
Each appearance of the subreport should have only part of the data that is related to that particular group.
In other words, the supreport should take a parameter from the main report to display only relevant data.
 I tried to add a parameter field to the subreport and linked it to the field in the main report, but it get me an error Report cannot be shown. What do I do incorrectly?
0
In an SSRS report, I would like to create custom code using VB.NET to iterate through all controls in a report and set a value.

If the iteration finds a control that begins with a specific string e.g. "txtBlank...." the code will return a value to the textbox based on the value of a field in the dataset. Something like this:

For each control
If First(Fields!BordersOn.Value, "dataset1") = "1") then
If controlname.startswith("txtBlank") then
control.value = "string"
End if
End if
Next

Open in new window


But I'm not sure how to get the control name for each control. I'm also not sure whether I can set the value for each control that is found. How can I do this with VB.NET?

Note - there are many, many controls in this report and I know that I could make an expression within each and every appropriate control to do the above, but I think the custom code will be more efficient and flexible in terms of future edits. I guess I am basically looking for a way to avoid having to enter an expression into each of a hundred textboxes.
0
Im using this code in vb.net and it creates an error:
Invalid root in registry key "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\15.0\Excel\Security\ACB".
on vb6 it runs fine. :
 w= CreateObject("WScript.Shell")
 w.RegWrite(str1, 1, "REG_DWORD")
0

Visual Basic.NET

94K

Solutions

24K

Contributors

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,