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

Hi

I am using the following VB.net code to connect to the Xero API in my web page. I also want to be use the  "myxeroapi" variable on a button click

on the page. Do I use session variables? If so what would the code look like?

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myxeroapi As XeroCoreApi
        If IsPostBack = False Then
            'SO PAGE LOADS TWICE
            If Request.QueryString("oauth_verifier") Is Nothing Then
                'FIRST LOAD ALLOWS YOU TO AUTH IN
                myxeroapi = XeroAuthenticate(Me, False, "")
            Else
                'SECOND LOAD LET'S YOU DO SOMETHING
                myxeroapi = XeroAuthenticate(Me, True, "")
                If Not myxeroapi Is Nothing Then

                    Dim i As Integer = myxeroapi.Contacts.Find.Count 'Quick Test

                    Call oCreateInvoice(myxeroapi)

                End If
            End If
        End If
    End Sub

Open in new window

0
Hi,

Hi, I am using this online solution for Grideview Drag and Drop asp.net web forms (https://www.aspsnippets.com/Articles/Reorder-GridView-Rows-Drag-and-Drop-ordering-of-GridView-Rows-using-jQuery-in-ASPNet.aspx).  Everything works fine but now I need help updating the database table with additional fields.  For example:  I need to update the table of who dragged and dropped the row.  I added the "UpdateBy" field to my update statement , it works, but it updates every row with the value not the one row that was dropped.  What am i missing? Please need help asap.

  

  Private Sub BindGrid()
        Dim query As String = "SELECT [id], [DisplayOrder], [STUDY], [PATIENT],[WAIT_TIME],[USER_ID],[UpdateBy] FROM [Radio_queue4] " +
"order by DisplayOrder asc"
        Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand(query)
                Using sda As New SqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    sda.SelectCommand = cmd
                    Using dt As New DataTable()
                        sda.Fill(dt)
                        grid.DataSource = dt
                        grid.DataBind()
                    End Using
                End Using
            End Using
        End Using
    End Sub

 Protected Sub UpdatePreference(sender As Object, e As 

Open in new window

0
I am trying to get a range of cells from a sheet to populate my graph on a different sheet inside my excel workbook. When it hits the line "  chartRange = oWB.oSheet("Sheet1").Range("A1", "A136")" It throws an error "System.MissingMemberException: Public member osheet on type Workbook not found

What is wrong with that line of code?

 Dim oXL As Excel.Application
        Dim oWB As Excel.Workbook
        Dim oSheet As Excel.Worksheet
        Dim oRng As Excel.Range
        Dim ValueTemp As String
        Dim oChart As Excel.Chart
        Dim MyCharts As Excel.ChartObjects
        Dim MyCharts1 As Excel.ChartObject

        ' Start Excel and get Application object.
        oXL = CreateObject("Excel.Application")
        oXL.Visible = True

        ' Get a new workbook.
        oWB = oXL.Workbooks.Add
        oSheet = oWB.ActiveSheet

        'Add a new Sheet.
        oSheet = CType(oWB.Sheets.Add(Count:=1), Excel.Worksheet)

        'change page orientation
        oSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape


        oSheet = oWB.Worksheets.Item(2)
        Dim intRowLoc, intcurrentrow, intCurrentCol, intLoop, intOuterLoop, intInnerLoop As Integer
        Dim boolRowFound, boolNextRow As Boolean
        intcurrentrow = 1
        intCurrentCol = 1
        For intInnerLoop = 0 To 135 'Column4.Count - 1
            ValueTemp = (Column4(intInnerLoop)).ToString
            oSheet.Cells(intcurrentrow, intCurrentCol) = ValueTemp
            

Open in new window

0
Hello Experts
I have this very small desktop app developed in visual basic 2017
it works just fine in my win 10 laptop.

But when copied to another windows 10 pc simply does not work.
no error message no nothing. Simply does not react.

What could be the cause ?
I have installed the same mini app in several other win7 and works normal.
0
I am having trouble with NULL values where the single node does not exist.  I want to set the variable to a BLANK value if the node is NULL.  

I tried this and it did not work:

        '' Get Shipping Document Data
        ' Declare node variables
        Dim BOLNodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes(vBOL)

        vLineNbr = 0

        ''For Each node As XmlNode In Nodes - variables
        For Each node As XmlNode In BOLNodes

            vLineNbr = vLineNbr + 1

            pShipmentID = node.SelectSingleNode("ReferenceNumber[@type='Customer Reference Number']").InnerText
            pShipmentID = If(pShipmentID Is Nothing, "", Trim(pShipmentID))

I changed this and it did not work:

        '' Get Shipping Document Data
        ' Declare node variables
        Dim BOLNodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes(vBOL)

        vLineNbr = 0

        ''For Each node As XmlNode In Nodes - variables
        For Each node As XmlNode In BOLNodes

            vLineNbr = vLineNbr + 1

          pShipmentID = If((node.SelectSingleNode("ReferenceNumber[@type='CustomerNumber']").InnerText) Is Nothing, "", Trim(pShipmentID))

I think you can see what I am trying to accomplish.
0
Hi,
How to save arabic words in a SQL server 2012 table using vb.net code
Table structure
table [test]
Test_english  varchar(1000)
Test_arabic    nvarchar(1000)

I am reading arabic text in a winform and trying to save it in the field [test_arabic].
It is saved in the database as ??????

The targeted database is full of data and changing The database properties is not a valid option... Can some one help please. Thanks
0
Hi. The first code sample is my VB.net.  I am trying to add the ".Tracking" part which is shown in C#
in the second code set below from "Tracking = new ItemTracking"
How would that look in my VB.net code?

            Dim LineItems As New List(Of LineItem)
            Dim pLineItem As New LineItem
            With pLineItem
                .Description = "Services Rendered"
                .Quantity = 1
                .UnitAmount = "1234.56"
                .AccountCode = "4000"
                .Tracking = ????
            End With

Open in new window


                        new LineItem
                        {
                            AccountCode = "200",
                            Description = "3 copies of OS X 10.6 Snow Leopard",
                            UnitAmount = 59.00m,
                            Quantity = 3m,
                            TaxAmount = 19.97m,
                            TaxType = "OUTPUT2",
                            LineAmount = 177.00m,
                            Tracking = new ItemTracking
                            {
                                new ItemTrackingCategory
                                {
                                    Id = category,
                                    Name = name,
                                    Option = option
                                }
                            }
                        },

Open in new window

0
Hi. I am using the following VB.net code in ASP.net to create authenticate the user and then
create an invoice. The authentication works but then there is a problem with one line of code
  .Contact = pContact
The error is "Value of type 'Contact' cannot be converted into 'Contact'"

       
Imports Xero.Api.Core
Imports Xero.Api.Infrastructure.Interfaces
Imports Xero.Api.Example.Applications.Public
Imports Xero.Api.Infrastructure.OAuth
Imports System.Collections.Concurrent
Imports Xero.Api.Core.Model
Imports Xero.Api.Core.Model.Invoice





Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myxeroapi As XeroCoreApi
        If IsPostBack = False Then
            'SO PAGE LOADS TWICE
            If Request.QueryString("oauth_verifier") Is Nothing Then
           
                myxeroapi = XeroAuthenticate(Me, False, "")
            Else

                myxeroapi = XeroAuthenticate(Me, True, "")
                If Not myxeroapi Is Nothing Then

                    Dim i As Integer = myxeroapi.Contacts.Find.Count 'Quck Test
                    Call oCreateInvoice(myxeroapi)


                End If
            End If
        End If
    End Sub



    Sub oCreateInvoice(ByVal myxeroapi As XeroCoreApi)

        Dim oEx As String

        Try
            Dim pContact As New Contact
            pContact.Name = "Test Company"

            'Create the list of 

Open in new window

0
How can I add a series of 256 points to an Excel chart ? I have the code below however I can;t seem to find an add data property to the chart object?

Dim objApp As Excel.Application
        Dim objBook As Excel._Workbook
        Dim objBooks As Excel.Workbooks
        Dim objSheets As Excel.Sheets
        Dim objSheet As Excel._Worksheet
        Dim range As Excel.Range
        Dim chart As Excel.Chart

        ' Create a new instance of Excel and start a new workbook.
        objApp = New Excel.Application()
        objBooks = objApp.Workbooks
        objBook = objBooks.Add
        objSheets = objBook.Worksheets
        objSheet = objSheets(1)
        objApp.Visible = True
        objApp.UserControl = True
        'Add in Header Graph.
        objSheet.Shapes.AddPicture("C:\Header.png",
             Microsoft.Office.Core.MsoTriState.msoFalse,
             Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 0, 45)
        'Add in DataChart

Open in new window

0
Hi. In the following VB.net code use with the Xero API I get the error "Name is not a member of Contact"
Why would this be

    Sub oCreateContact()
        Dim api = New Xero.Api.Example.Applications.[Private].Core(False)
        Dim newContact As Contact = New Contact()
        newContact.Name = "Metal Fencing"
        newContact.FirstName = "John"
        newContact.LastName = "Smith"
        newContact.EmailAddress = "john@metalfencing.com"
        api.Contacts.Create(newContact)
    End Sub

Open in new window

0
Hi experts and thanks in advance for any help I will get on this one:
Im trying to show 3 different charts . my code is an upgrade from vb6 . I get only 3 dots on the chart space instead of lines. this is my code:
     
       Dim oChart As Microsoft.Office.Interop.Owc11.ChChart  
       Dim oSeries As Microsoft.Office.Interop.Owc11.ChSeriesCollection  
           

            For i = 1 To 300
                For j = 1 To 13
                    oReportForm.Spreadsheet11.ActiveSheet.Cells(i, j).value = Arr(i, j)
                Next j
            Next i

            ReDim XChart(300)
            ReDim YChart(300)
            Dim XChart1(300) As Object
            Dim YChart1(300) As Object
            minX = oReportForm.Spreadsheet11.ActiveSheet.Cells(1, 2).value
            minY = oReportForm.Spreadsheet11.ActiveSheet.Cells(1, 3).value

            maxX = oReportForm.Spreadsheet11.ActiveSheet.Cells(1, 2).value
            maxY = oReportForm.Spreadsheet11.ActiveSheet.Cells(1, 3).value
            For i = 1 To 300

                If oReportForm.Spreadsheet11.ActiveSheet.Cells(i, 2).value >= maxX And oReportForm.Spreadsheet11.ActiveSheet.Cells(i, 3).value >= maxY Then
                    maxX = oReportForm.Spreadsheet11.ActiveSheet.Cells(i, 2).value
                    XChart(i) = oReportForm.Spreadsheet11.ActiveSheet.Cells(i, 2).value * 100
                    maxY = oReportForm.Spreadsheet11.ActiveSheet.Cells(i, 3).value
                    …
0
Hi there.

I have some code suggestion made for C#, that I want to make in VB.NET. Some code is meant to be in the "IdentityConfig.cs". Where is that going in VB.NET?

Best regards

Ulrich
0
Hi. I am using the code below to connect to the Xero API and authenticate the user. The code then takes the user to the page "http://localhost:62054/AccountingXero.aspx"
where I want to then refer to the API again. How do I refer to the myxeroapi variable again on that page. I am not sure if a session variable would
work.

Imports Xero.Api.Core
Imports Xero.Api.Infrastructure.Interfaces
Imports Xero.Api.Example.Applications.Public
Imports Xero.Api.Infrastructure.OAuth
Imports System.Collections.Concurrent

Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myxeroapi As XeroCoreApi
        If IsPostBack = False Then
            If Request.QueryString("oauth_verifier") Is Nothing Then
                myxeroapi = XeroAuthenticate(Me, False, "")
            Else
                myxeroapi = XeroAuthenticate(Me, True, "")
                If Not myxeroapi Is Nothing Then
                    Response.Write(myxeroapi.organisation.name)
                End If
            End If
        End If
    End Sub



    Protected Function XeroAuthenticate(inpage As Page, authpagereturnedauthentication As Boolean, incode As String) As XeroCoreApi
        ' This procedure will return w working XeroCoreApi if successful and nothing otherwise
        ' Set client secrets for general use and then load any override ones from the web.config file
        Dim myxeroconsumer As New

Open in new window

0
Hi there.

I'm finally starting to step up to .NET. I will use a present classic asp project and redo from scratch. I want to implement two factor authentication (e-mail), but I'm unsure if it should be done in C# or VB, AND if it's only possible in one of these?
I'm used to VB from the past with classic asp, so of course I would like to use that, but two factor authentication is a must, so I'll have to deal with C# if necessary.
I look forward to your input. I found this:
https://www.hanselman.com/blog/AddingTwoFactorAuthenticationToAnASPNETApplication.aspx
It appears as C# to me. Am I wrong?
If you know of better guides/help to implement two factor authentication, please let me know. :-)

Best regards

Ulrich
0
Hi. I am using the following VB.net code in my ASP.net WebForms project to connect to the Xero accounting API.
It takes me to the Xero login and allows me to log in and then click the button to stay connected for 30  minutes
but then gives me the error in the attached image.  I have a web page called AccountingXero.aspx so I am not sure what I
have done wrong

Imports Xero.Api.Core
Imports Xero.Api.Infrastructure.Interfaces
Imports Xero.Api.Example.Applications.Public
Imports Xero.Api.Infrastructure.OAuth
Imports System.Collections.Concurrent

Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myxeroapi As XeroCoreApi
        If IsPostBack = False Then
            If Request.QueryString("oauth_verifier") Is Nothing Then
                myxeroapi = XeroAuthenticate(Me, False, "")
            Else
                myxeroapi = XeroAuthenticate(Me, True, "")
                If Not myxeroapi Is Nothing Then
                    Response.Write(myxeroapi.organisation.name)
                End If
            End If
        End If
    End Sub



    Protected Function XeroAuthenticate(inpage As Page, authpagereturnedauthentication As Boolean, incode As String) As XeroCoreApi
        ' This procedure will return w working XeroCoreApi if successful and nothing otherwise
        ' Set client secrets for general use and then load any override ones from the web.config

Open in new window

0
What's the best way to parse the following string into an object?
vbCrLf & "+COPS: (2,""O2 - UK"",,""23410"",0),(3,""vodafone UK"",,""23415"",0),(3,""EE"",,""23430"",0),,(0-4),(0,2)" & vbCrLf & vbCrLf & "OK" & vbCrLf
An example would be good!
Thanks
0
Having issues with cut off data inside my COM port buffer. I keep things open for  5 secs. but it seems like a couple times it cuts off the front end of the message.

How can I protect against that. I do not use a STX start message or any Checksum or CRC's.
0
Hi Experts,
I have to read a text file with vb.net, the file that could contain coded basic strings 64 is there a way to recognize them so that I can decode them?

Thanks

Best regards
0
I work in VS 2015 VB.Net
I creatd SSRS report with subrepot.
I read that to do that you have to populate both your main report and subreport in code, and for the subreport you create an event handler to populate.
In my case the subroutine that handles the event handler never gets invoked, and the subreport is not getting populated. Report displays only the main report, the subreport returns a message: Error: Subreport could not be shown.
Here are the references I have on the page:
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
Here is my page load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            ReportViewer1.ProcessingMode = ProcessingMode.Local
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.ReportPath = Server.MapPath(".") + "/SSRSReports/" + "PvPDOrder.rdlc"
            ReportViewer1.LocalReport.DataSources.Add(GetReportDataSource)
            AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubreportProcessingEventHandler
            Me.ReportViewer1.LocalReport.Refresh()
        End If
    End Sub

   Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
        Try
            e.e.DataSources.Add(GetSubreportDataSource)
        Catch ex As Exception
            ' MessageBox.Show(ex.Message, …
0
Hi all.

I'm trying to put a row from a datagridview back on the top after the datagridview is sorted. The row whose "Type" column is equal to "OEM" needs to always be on top even after sorting.

Below is my code. When I run it I get the following error: "Index was outside the bounds of the array"

Any idea what I'm doing wrong? Thank you in advance.
 Private Sub DataGrid_Variants_Sorted(sender As Object, e As EventArgs) Handles DataGrid_Variants.Sorted
Dim dt As New DataTable
        dt = TryCast(DataGrid_Variants.DataSource, DataTable)
        Dim result() As DataRow

 For i As Integer = 0 To dt.Rows.Count - 1
 result = dt.Select("Type = 'OEM'")
 Dim newRow As DataRow = dt.NewRow()
            newRow.ItemArray = result(i).ItemArray
            dt.Rows.Remove(result(i))
            dt.Rows.InsertAt(newRow, 0)
  Next

End Sub

Open in new window

0
Greeting,

I am putting together a little program that I want to Display and Modify a PDF file. I want to display the PDF  from within my Application before and after I modify the PDF.
I have all the code working just fine BUT only when I run the code in DEBUG mode in VS 2017. Once I create the RELEASE version and install it the embedded PDF viewer will
will not work.

I am using  the  AxAcroPDF OCX, control and I am looking  for some help in understanding why the control will not work once 'Released'.

As a side note I am using PDFSharp and iTextSharp  to manipulate the PDF files.. I will post any and all code that may be necessary to resolve the 'Release' code problem.

Thanks in advance
Rick
0
Hi

I am using the following code to edit two records via an API in ASP.net
I want to change it so that I can add a much larger variable number of edits
Can I use an array for instanceeg Dim DL(10000) as New LineEdit?

                        Dim DLs As New List(Of LineEdit)
                        Dim DL1 As New LineEdit
                        Dim DL2 As New LineEdit
                        DL1.LineID = 2
                        DL1.EmployeeID = 4727
                        DL1.Hours = 14
                        DL1.LogDate = "19 Apr 2019"
                        DL1.LogDate = lblLogDate.Text
                        DL1.EmplyeeWorkType = ddlWorkType.Text
                        DLs.Add(DL1)
                        DL2.LineID = 0
                        DL2.EmployeeID = 4720
                        DL2.Hours = 4
                        DL2.LogDate = "19 Apr 2019"
                        DL2.EmplyeeWorkType = "Work"
                        DLs.Add(DL2)

                        Dim result As String
                        result = PostEmployeeHoursEdit(DLs, DropDownList_Stores.Text)

Open in new window

0
The Microsoft Jet database engine cannot find the input table or query .
I get this error when trying to select a table from an access file.
the file was created using the fileopy command.
any suggestion will be appreciated.
0
Hi

In my ASP.net web app.  I am editing data via an API and sometimes
get the error I the image. My code is as follows. I have no idea what this error means

 Public Function PostEmployeeHoursEdit(DataLines As List(Of LineEdit), StoreID As Integer) As String

        Dim Resp As HttpWebResponse
        Try
            Dim url As String = "http://www.rxxdf.com/platform/api/"
            Dim API_Method As String = "EmployeeHours"

            Dim data As String = ""
            data = Newtonsoft.Json.JsonConvert.SerializeObject(DataLines)

            Dim Auth As String = Me.txtUsername.Text & ":" & Me.txtPassword.Text
            Dim webAddress As String = url & API_Method & "/" & StoreID & "/0"
            Dim request As HttpWebRequest = HttpWebRequest.Create(webAddress)
            request.Method = WebRequestMethods.Http.Post
            request.Headers.Add("Authorization", Auth)
            request.ContentType = "application/json"
            request.ContentLength = data.Length

            Dim writer As New StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)
            writer.Write(data)
            writer.Close()


            Resp = request.GetResponse()
            Dim stream As Stream = request.GetResponse().GetResponseStream()
            Dim reader As New StreamReader(stream)
            Dim response As String = reader.ReadToEnd()

            Return "OK"

        Catch wex As WebException
            Dim response As WebResponse = 

Open in new window

0
I need to migrate vb code to vb.net . the vb6 using DAO creates table in access data base using the database.CreateTableDef method.
is there any equivalent in ADO objects?
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,