[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Visual Basic.NET

93K

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

Hello Experts.

I'm afraid this question might be a little vague, but I'm almost certain that it is possible to do.

Basically, I want to build a LINQ query in my vb.net project that compares two object's key fields and reports back which ones in Object A are NOT in Object B, and vice versa.

More specifically, I have a non-databound DataGridView which contains a current list of member ID's (Object A). I also have a bound DataGridView that contains an older dataset (say for example last week's member ID's).

To be perfectly honest, every time I read about SQL joins, my mind turns into a pretzel, but I feel that it's time I overcome this mental block and try to get a handle on the difference between and inner-join and an outer-join.

So, if anyone has a good example of a LINQ query that might be close to what I've described above, I would be interested in seeing what that looks like.

Always Learning,
Tony G.
0
Learn Ruby Fundamentals
LVL 12
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Hi experts, need some help please

I am migrating a desktop app from vb6 to vb.net using vs2015.
when populating a listview I get the error "Cannot add or insert the item more than one place. You must first remove it from its current location or clon vs2015"
the vb6 code is:
Set myNode = TreeView1.Nodes("a" & CStr(x))
Set myNode.Parent = TreeView1.Nodes("a" & CStr(y))
since in vb.net I cannt set parent - the vb.net code:
myNode = TreeView1.Nodes.Item("a" & CStr(x)
 TreeView1.Nodes.Item("a" & CStr(y)).Nodes.Add(myNode)
0
I have these 2 functions "Add" is a test which works to add the data to the database. It works as expected but "Create" does not. Could anyone help me to figure out why.

Thanks

    Public Function Add(ByVal itemToAdd As TObject) As TObject
        Dim addedItem As TObject = DbSet.Add(itemToAdd)
        dbContext.SaveChanges()
        Return addedItem
    End Function

    Public Overridable Function Create(t As TObject) As TObject Implements IRepository(Of TObject).Create
        Dim newEntry As TObject = DbSet.Add(t)
        dbContext.Entry(t).State = EntityState.Added
        If Not shareContext Then dbContext.SaveChanges()
        Return newEntry
    End Function

Open in new window

0
the data received from the machine is as under and need to build the graph from the data received as under:-

"OBX|32|ED|15000^WBC Histogram. Binary^99MRC||^Application^Octer-stream^Base64^AAAAAAAAAAAAAAABAgQHDRcmO1Z3nMPg9P/98+HKsZl8aFdGMyUfHBwcHR8iJy02QUpLTU5PT09PTUxKSEZEQkBAPz4+PT09Pj49PDo5ODg3Nzg6PD5AQ0ZISUpMTU9RU1VWWFlZWlpaWlpaWlpbW1tbW1tcXV5fYGBhYWBgXl1bWVdVU1JQT01MSkhGREJAPj07OTg2NDMxLy0sKignJSQi"

or
"OBX|36|NM|15057^RBC Histogram. Total^99MRC||43822||||||F
OBX|37|ED|15050^RBC Histogram. Binary^99MRC||^Application^Octer-stream^Base64^AAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEBAgIDAwUGCg4TGiIuOklYaX2OoLHD1OLu+P3//vny593Sw7Snmo1/dWthWFBJQjw2Mi8sKSclIyIgHx4cHBoaGBcWFBQTExISERAQEA8PDw4MDAsKCgoJCAgIBwcGBwcGBgYGBQQEBAQDBAMDAwMDAgICAgICAgEBAQEBAQEBAQEBAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==||||||F"

or

"OBX|42|ED|15100^PLT Histogram. Binary^99MRC||^Application^Octer-stream^Base64^HR0MHQwMFB0VDAsMDxQiHRoVEAwLCwsMDg8QFBoiLB0cGhcVEhAODAsLCwsLCwwMDQ4ODw8QEhQXGh4iJywzHRwcGxoZFxYVFBIREA8ODQwMCwsLCwsLCwsLCwsLDAwMDA0NDg4ODw8PDxAQERITFBYXGRocHiAiJCcpLDAzOB0=||||||F
"


would really be thankful if you could help to create a graph from above sequence.
0
These two lines of vb6 code I am trying to translate to C#:

mskFromDate.Text = Format(Date - TimeSerial((iNumDaysBefore * 24), 0, 0), "Short Date")
    mskToDate.Text = Format(Date + TimeSerial((iNumDaysAfter * 24), 0, 0), "Short Date")

I have this so far. I know it is not right.

var dt = string.Empty;
                dt = Convert.ToString(DateTime.Now.ToOADate() - (NumDaysBefore * 24));
                this.dtFromDate.Text = Convert.ToDateTime(dt).ToShortDateString();

Anybody have thoughts? I can't believe in vb6 they let folks subtract dates and numbers.
0
I have a Web Forms application using VB

So i have a Page called TestPage.aspx and the code behind page is TestPage.aspx.vb

In TestPage.aspx.vb  on the page load event, i have a string variable which contains this value:

Dim TestVariable1 As String "This is a test string <br /> this is a test"

How do I create second variable called TestVariable2 that gets the value from TestVariable1 and if there is a < in the string replace it with a space after it.

So then the value stored in TestVariable2 would be: "This is a test string < br /> this is a test"
0
Hi Guys,
I am using asp.net mvc application with VB.net and I am trying to zip files and stream them back to the user to download.

Here is what I am doing
   Public Function DownloadFiles(attachmentsSelected As String) As ActionResult
        Dim obj As FileDownloads = New FileDownloads()
        ''get file list of files to download
        Dim filesCol = obj.GetFile(attachmentsSelected).ToList()

        Using memoryStream = New MemoryStream()
            Using ziparchive = New ZipArchive(memoryStream, ZipArchiveMode.Create, True)

                For i As Integer = 0 To filesCol.Count - 1
       //get the error here   ziparchive.CreateEntryFromFile(filesCol(i).FilePath + "\" + filesCol(i).FileName, filesCol(i).FileName, CompressionLevel.Optimal)
                Next
            End Using

            Return File(memoryStream.ToArray(), "application/zip", "Attachments.zip")
        End Using

    End Function

Open in new window


The issue with this code is when I am trying to download large file ...let's say 500mb I get an exception.

"Exception of type 'System.OutOfMemoryException' was thrown."

Any idea how can I fix this issue.

Thank you.
0
Using VB.NET 2016, After I write out a .csv file with values, how can I then format said .csv , to set a particular column to use a 2 place number format?

This is as close as I've come..and nothing happens to the worksheet afterward.

        Dim xlApp As New Microsoft.Office.Interop.Excel.Application
        Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
        Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
        'Dim xlSourceRange, xlDestRange As Microsoft.Office.Interop.Excel.Range
        xlWorkBook = xlApp.Workbooks.Open("MY_EXCEL_FILE ".csv")
        'Set the source worksheet
        xlWorkSheet = xlWorkBook.ActiveSheet
        xlWorkSheet.Columns.Cells.NumberFormat = "#,##0.00"
        xlWorkBook.Save()

Open in new window

0
Hi. I am trying to remove characters from the right side of a cell in excel using vb.net so that I will be left with a date value. Here is the cell value:
REPORT DATE:07-Sep-18

Here is the code:

        'set up initial column
        strColumn = "J"
        'set up initial row
        intRowID = 2
        'Set up range
        strRange = strColumn & intRowID
        strStringDate = ForcastWorkSheet.Cells.Range(strRange).Value
        strDate = strStringDate.TrimStart(strStringDate.Length, -12)

Open in new window


The error message is "Integer values cannot be converted to Char"

Thank you in advance for any help with this.

Valerie
0
Hi. I am trying to change the font, the font size and color of a cell in an excel worksheet from my vb.net application.

The first two lines of code run without errors but do not change anything in the cells. The third line, to change the color, gives me the following error at runtime: "System.Runtime.InteropServices.COMException: 'Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))'"

The workbook is open to not read-only and is editable, in fact, the same cells will add values.

Here is my code:

'Format formula cell to match font and size of existing cells
                ForcastWorkSheet.Cells.Range(strRange).Font.Name = "Arial"
                ForcastWorkSheet.Cells.Range(strRange).Font.Size = "9"
                ForcastWorkSheet.Cells.Range(strRange).Interior.Color = "Orange, Accent 2, Lighter 60%"

Open in new window

0
Amazon Web Services
LVL 12
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Hi. I am trying to show a message box when the user has chosen a file that already exists and then exit the sub. I am getting a red line under the word 'show'. The error says "Overload failed because no accessable 'Show' accepts this number of arguments."

The following is my code:

'Use filename chosen by user
        strFileName = lblChosenFile.Text

        strNewFileName = ForcastFileName(strFileName)
        If System.IO.File.Exists(strNewFileName) Then
            'The forcasted file exists
            MessageBox.Show = ("File has already been forcasted.", "File Forcasted", MessageBoxButtons.OK)
            Exit Sub
        End If

Open in new window


Can someone please help with this, it seems like it should be a simple thing to do and I have tried numerous variations ... what and I doing wrong?

Thanks,
Valerie
0
I need to build a graph using these points in vb.net. kindly help

"D300020C25485E6462523C2D231B16110C09070604030303030202020202020204040507090E141B22060E14310431011D7"
0
If this works

        Dim strRootNodeName As String
        Dim dt As New DataTable

        Using cn As New SqlConnection(GlobalVariables.strConn)
            Using cmd As New SqlCommand(m_strNameLookupSQL, cn)
                cmd.Parameters.Add("@ItemId", SqlDbType.Int).Value = m_RootNodeId
                Using da As New SqlDataAdapter(cmd)
                    da.Fill(dt)
                    strRootNodeName = dt.Rows(0)("ItemName")
                End Using
            End Using
        End Using

Why would this not work?

        Dim strRootNodeName As String

        Using cn As New SqlConnection(GlobalVariables.strConn)
            Using cmd As New SqlCommand(m_strNameLookupSQL, cn)
                cmd.Parameters.Add("@ItemId", SqlDbType.Int).Value = m_RootNodeId
                Using rdr = cmd.ExecuteReader
                    rdr.Read()
                    strRootNodeName = rdr("ItemName")
                End Using
            End Using
        End Using
0
Return ValuesI am capture the signed integer values from a device. I need to be able to convert them to their respected char but the code below returns them in an integer value. How can I return the LO byte HI byte representation?

 Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
        Dim lReturnValue As Integer 'Return value
        Dim szDeviceName As String 'Device name
        Dim lSize As Integer 'Size
        Dim lData() As Integer 'Device Value
        Dim szList As String 'Data for ListBox
        Dim lMod As Integer 'Surplus
        Dim lCount As Integer 'Counter

        'The device name is set in szDeviceName.
        szDeviceName = Text_DeviceName.Text
        'The size is set in lSize.
        lSize = CInt(Text_Size.Text)
        'The array for the read device value for the size is secured.
        ReDim lData(lSize)


        'The content of ListBox is cleared.
        List1.Items.Clear()
        'The first line is displayed.
        List1.Items.Add((Chr(9) & "+0" & Chr(9) & "+1" & Chr(9) & "+2" & Chr(9) & "+3" & Chr(9) & "+4" & Chr(9) & "+5" & Chr(9) & "+6" & Chr(9) & "+7"))
        'The second line is displayed.
        List1.Items.Add(("---------------------------------------------------------------------------------------"))
        'ReadDeviceBlock is executed.
        lReturnValue = AxActUtlType1.ReadDeviceBlock(szDeviceName, lSize, lData(0))

        'Whether 

Open in new window

0
Hi All,

I have many SP that have to create on the fly.

How could I :

1. Call the SP function by just passing its function name in string.

     Public Shared Sub Create_Stored_Procedure(strFunctionName As String)

       ' strFunctionName  = Create_ERV_SP_Get_Kas_Voucher

         call strFunctionName

    End Sub

    Public Shared Sub Create_ERV_SP_Get_Kas_Voucher()
   End Sub

2. Call all Create procedure exist in the class.

Thank you.
1
Hi All,

I have a sub/function like below.

Public Class clsCreateInventoryStoredProcedure

    Private sbdSQLCommand As New System.Text.StringBuilder

    Public Shared Sub Create_ERV_SP_Get_Kas_Voucher()
    End Sub

End Class

Open in new window


How could variable sbdSQLCommand  visible to Create_ERV_SP_Get_Kas_Voucher ?

Thank you.
0
Hi

I have created an application that adds permissions to a Shared Folder on a Window server (this is important as I'm setting permissions on a share and NOT NTFS).

I now need to do the opposite and remove the group 'Everyone' from the Share permission.  I have a piece of code that gets the existing permissions as follows:

 Dim securityDescriptor As ManagementBaseObject = TryCast(securityDescriptorObject.Properties("Descriptor").Value, ManagementBaseObject)
        Dim existingAcessControlEntriesCount As Integer = 0
        Dim accessControlList As ManagementBaseObject() = TryCast(securityDescriptor.Properties("DACL").Value, ManagementBaseObject())

        If accessControlList Is Nothing Then
            accessControlList = New ManagementBaseObject(0) {}
        Else
            existingAcessControlEntriesCount = accessControlList.Length
            Array.Resize(accessControlList, accessControlList.Length + 1)
        End If

As you can see above, I am using an ACL list and I extend it  so that I can then add the new ACL for the group I want to give permissions to.  I now wish to do the opposite and remove an entry from the accessControlList.

Now, I am convinced that if I were to remove one of the existing entries from this accessControlList before committing it back, that would remove a permission for an existing object but I don't know how to enumerate the accessControlList to find the entry I want to remove.

In pseudo-code, this is what I …
0
I'm looping through 4000 rows to update the Access Database, but I keep getting "System Resources Exceeded" Error:

                Dim sSQL_UpdateStatement As OleDb.OleDbCommand
                Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnectionString)

                sSQL_UpdateStatement = New OleDb.OleDbCommand
                sSQL_UpdateStatement.Connection = conn
                sSQL_UpdateStatement.CommandTimeout = 0
                sSQL_UpdateStatement.CommandType = CommandType.Text
                conn.Open()

                For Each drRow As DataRow In dtDepotData.Rows
                    sSQL_UpdateStatement.CommandText = "UPDATE tbl_Receivables SET exported = " & CType(sBatchNumber, Long) & _
                        " WHERE ClientID = " & ClientID & " AND ReceiveDate = #" & ReceiveDate.ToShortDateString & "# AND Acct1 = @acctnum1" & _
                        " AND Acct2 = @acctnum2 AND Acct3 = @acctnum3 AND Acct4 = @acctnum4 AND Acct5 = @acctnum5 " & _
                        " AND AmountPaid = " & drRow.Item("AmountPaid") & " AND Exported = 0"

                    sSQL_UpdateStatement.Parameters.AddWithValue("@acctnum1", drRow.Item("Acct1"))
                    sSQL_UpdateStatement.Parameters.AddWithValue("@acctnum2", drRow.Item("Acct2"))
                    sSQL_UpdateStatement.Parameters.AddWithValue("@acctnum3", drRow.Item("Acct3"))
                    sSQL_UpdateStatement.Parameters.AddWithValue("@acctnum4", …
1
I'm using VB and ASP.NET Web Forms.

On my page i'm binding a DataGrid to a Sql Server Stored procedure.

Yest, I know GridView is the newer ASP.NET grid.
This is a model based on a old legacy web application.
That's why I need to use DataGrid.

The sql server table I'm using is a copy of the Employees table from the Northwind database.

This is the script to create the table:

USE [Northwind]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NWEmployees](
	[EmployeeID] [int] NOT NULL,
	[LastName] [nvarchar](20) NOT NULL,
	[FirstName] [nvarchar](10) NOT NULL,
	[Title] [nvarchar](30) NULL,
	[TitleOfCourtesy] [nvarchar](25) NULL,
	[BirthDate] [datetime] NULL,
	[HireDate] [datetime] NULL,
	[Address] [nvarchar](60) NULL,
	[City] [nvarchar](15) NULL,
	[Region] [nvarchar](15) NULL,
	[PostalCode] [int] NULL,
	[Country] [nvarchar](15) NULL,
 CONSTRAINT [PK_Employees_NWEmployees] PRIMARY KEY CLUSTERED 
(
	[EmployeeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
INSERT [dbo].[NWEmployees] ([EmployeeID], [LastName], [FirstName], [Title], [TitleOfCourtesy], [BirthDate], [HireDate], [Address], [City], [Region], [PostalCode], [Country]) VALUES (1, N'Davolio', N'Nancy', N'Sales Representative', N'Ms.', CAST(N'1948-12-08T00:00:00.000' AS DateTime), CAST(N'1992-05-01T00:00:00.000' AS DateTime), N'507 - 20th Ave. E.
Apt. 2A', N'Seattle', 

Open in new window

0
CompTIA Network+
LVL 12
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

I have a VB.net windows form with a splitter control on it. I would like to hide one of the panels of the splitter control. From what I have read this needs to be done in the code behind for the form containing the control(I think ?). So my question is where at in the code behind should I place the code to hide the control? Below is an example of the code.

splitContainer1.Panel2.Collapsed = true;
splitContainer1.Panel2.Hide();
0
Hello Experts.

This little head scratcher is a bit more complicated that the other questions I've submitted, so it's definitely not for the faint of heart.

The primary objective is for me to learn the correct method for writing data from a non-databound DataGridView to a databound table.

Background:
I have a databound table called "Roster" which contains sports player names, and other statistical data. This constantly changing data is maintained by an international organized sports organization. My Roster table is used to retain a recent snap-shot of that data specific to my local division teams. To accomplish that, I have created a subroutine which accepts data directly from the clipboard. The user populates the CB by logging into the organization's website and manually selecting the data on the screen.  Another subroutine converts the stream to a usable format. The next subroutine retrieves the new data and compares it with the currently stored values. Finally, all identified changes are presented to the user in a non-databound DataGridView object such as this:
A dialog box containing a non-databound (in memory) DataGridView.
Accepting this dialog initiates the table updating process for all rows which are checked as accepted. For now, I would just like to read the first row on the DGV and write the one change to the Roster table (in this case, changing David Rowe's Skill Level from 5 to 6).

Here is the code I put together, but it doesn't seem to be updating the database.
    Private 

Open in new window

0
ASP.Net and VB.Net backend code (2013 ) - Web forms app.
I cannot figure out how to get rid of the unneeded horizontal scroll bar on my Engineering panel and why my Manufacturing panel completely disappears.

Here you see everything displaying normal when there is no Engineer activity, but there is manufacturing activity:
EngNoActMfgAct.PNG
Here you see when there is Engineer activity, but no Manufacturing activity the Engineer panel has an unneeded horizontal scroll bar (that I can live with if need be) and the Manufacturing panel completely disappears:
EngActMfgNoAct.PNG
And here you see when there is no activity on any category, I get an annoying horizontal scroll bar on the Engineer activity panel and the Manufacturing panel completely disappears:
NoAct.PNG
Here is the ASP.net code of the pertaining panels:
        <asp:Panel ID="panNoActivity" runat="server" style="top: 25px; left: 10px; position: relative; height: 25px; width: 1137px" Visible="False">
             <asp:Label ID="lblNoActivity" runat="server" Font-Bold="True" style="height: 19px; width: 150px; top: 5px; left: 15px; position: relative" Text="There is no activity to display on this order at this time." Font-Names="Arial" ForeColor="#009530" Font-Size="Large"></asp:Label>
        </asp:Panel>


        <asp:Panel ID="panEngDrawings" runat="server" style="top: 40px; left: 10px; position: relative; height: 150px; width: 1132px; overflow:auto">

            <asp:Label 

Open in new window

0
Hi all.

I have a Windows form in vb.net that allows the end user to drag an Outlook email and drop it into a datagridview control, it save the recipients, subject line, email body into a SQL Server table and if the email has any attachments it imports the attachments into a shared network folder. We've been testing it for a couple of days now and it's working great but we're running into an issue where it'll download/import the attachments in the email but if the email has a company logo in the email signature it also brings it in. Is there a way to skip these type of email signature files? So far, they've been jpeg and png files sometimes 2KB, 11KB, 64KB not big files but don't want them to be imported.

I was thinking maybe not importing jpeg, png files less than 100K or something, but maybe there is an image file that we need to download/import that would otherwise be skipped.

Any advise is greatly appreciated. Thank you in advance.
0
I have a VB.net windows form. The form has a panel control on the top of the form, and a panel control on the bottom of the form. In the middle part of the form is a split container. The upper container and lower container both contain DataGridView controls. Everything works fine. Now if I resize the form to a very small form, the scroll bars will display in my grids as desired.
However when I scroll the bottom grid's vertical scroll bar down all of the way, there is a small gap of the bottom of the DataGridView which is showing. This isn't the last row of the grid, but I guess it is the default footer?

How can I get the scroll bar to scroll all the way down to show the last pseudo footer row? Attached are the screen snapshots of before and after the Grid is resized. I drew a red arrow to point to the pseudo footer which I am talking about.
Attached are my GridView files, and I renamed them as text files, in case someone wants to rename them correctly and inspect the code.

Before Grid is resizedAfterResizing.png
Form1.Designer.txt
Form1.Designer.txt
Form1.resx
0
Hi Experts,
I have the following code reading a CSV file line by line, parsing the columns and executing some commands...
Do While Not EOF(1)
                Line Input #1, lineOfFile
                columns = SplitRe(lineOfFile, ",(?=(?:[^""]*""[^""]*"")*(?![^""]*""))")
                pk = columns(iPKColumnNum)...
Loop

Public Function SplitRe(Text As String, Pattern As String, Optional IgnoreCase As Boolean) As String()
    Static re As Object

    If re Is Nothing Then
        Set re = CreateObject("VBScript.RegExp")
        re.Global = True
        re.MultiLine = True
    End If

    re.IgnoreCase = IgnoreCase
    re.Pattern = Pattern
    SplitRe = Strings.Split(re.Replace(Text, ChrW(-1)), ChrW(-1))
End Function

Open in new window

Now I realized that some times there are 2 carriage return characters between the lines and this causes the code above to render an error, see attached.
How do I handle this?
Untitled.png
0

Visual Basic.NET

93K

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,