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

Why might I getting this error. I am trying to connect to a DB from a console application and get this error.
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Imports System.Data.Entity

Module Program

    Dim people As IEnumerable(Of Person) = New List(Of Person)

    Sub Main(ByVal args As String())
        Using context = New EFDbContext() '<--- Error here
            Dim repo As ITestRepository = New EFRepository(Of EFDbContext)(context)

        End Using

    End Sub
End Module

Public Class EFDbContext
    Inherits DbContext

        Public Sub New()
        End Sub

    Public Property People As DbSet(Of Person)

End Class

Open in new window

I need to translate a column number at runtime to an excel range address in
is there any function I can use instead of writing my own?
I have two workbook.

Each workbook will have different sheets.

When both workbook sheets are the same, then it should check every individual cell of both the sheet.

let us imagine, both the sheet start range A20:KJ20

Sheet1 ==> A21 cell value is "12"

Sheet2 ==> A21 cell value is "14".

the above value is different, then it should show the difference in various color in "Sheet1"

I have done some code below.

But, worksheet not showing the range.

 Dim varSheetCurr As Object
                            Dim varSheetPrev As Object
                            Dim strRangeToCheck As String
                            Dim iRow As Long
                            Dim iCol As Long

                            strRangeToCheck = "A21:IV65536"
                            ' If you know the data will only be in a smaller range, reduce the size of the ranges above.

                            varSheetCurr = Worksheets("Sheet2").Range(strRangeToCheck) 
                            varSheetPrev = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.

                            For iRow = LBound(varSheetCurr, 1) To UBound(varSheetCurr, 1)
                                For iCol = LBound(varSheetCurr, 2) To UBound(varSheetCurr, 2)
                                    If varSheetCurr(iRow, iCol) = varSheetPrev(iRow, iCol) 

Open in new window

Hi Everyone,
I'm facing a problem says "There is no row at position 0." ..... I got this code from this site  How To Perform Paging with the DataGrid Windows Control by Using Visual Basic .NET
Really it's so helpful and with some few modifications , i got rid of some problems like 'There is no row at position 0.' but it appears randomly ....
I will have to display all my code to facilitate the sight  
Public Function GetData() As DataView
        'Cartons > 0 And
        Dim SelectQry = "SELECT BillInfo.InvoiceNo as [رقم الايصال],
                                    ProductSold.SoldDate as [تاريخ البيع],                                    
                                    BillInfo.CustomerName as [اسم العميل],
                                    ProductSold.ProductCode as [كود الصنف], 
                                    ProductSold.ProductName as [اسم الصنف],
                                    ProductSold.Price as [سعر التكلفة],
                                    ProductSold.Category as [اسم الباكية], 
                                    ProductSold.AVP as [الكمية المتاحة عند البيع], 
                                    ProductSold.SellPrice as [سعر البيع],
                                    ProductSold.SoldPackets as [الكمية المباعة], 
                                    ProductSold.TotalAmount as [الاجمالى المبيعات من 

Open in new window

Hi experts
I have a listview in its multiselect and checkbox selection. How do I get the selected item without looping through the selecteditems collection?
I need the last checked item

I've done some refactoring a database, separating billable (claim entries) from non-billable (time/expense entries). Initially all these records were in a single table . No surprise a lot of regressions have occurred in part because of these combined entries.
What I need assistance with is with an approach for the payroll report stored procedure. Currently it gathers all the information from the tbl_claims table. I now have 3 tables, tbl_claims, tbl_expenses and tbl_hours. I'm needing to get this information back out of the database and not sure of an approach that would be decent as well as not hindering performance. Users will run these reports for up to 12 months in which there could be 100k rows returned.
My thoughts were to create temporary tables and 3 separate stored procedures and then from VB.NET code make a call to each stored proc as needed to obtain all the results. I'm not really sure how to approach this as mentioned. I've attached the stored procedure as well as the CREATE TO T-SQL code. I'm using MS SQL Server 2016 Enterprise edition.

Hello Experts.

I'm looking for some creative ideas on how I might go about adding drill-down capability to my databound forms. Allow me to explain...

Let's say that my hypothetical project is for managing a local sports league, and includes three databound tables and corresponding forms for entering / updating records:
  • Players
  • Teams
  • Schedule

As you can imagine, some of the data in these tables are related. So, the Players table would have a field to specify which team they are on. The Teams table would have a field to specify the Captain and their Player ID. The Schedule table would have the two Team IDs that are competing each week.

I would like to be able to make the TextBoxes which have a direct relationship clickable, with the action being to display the correct Form and record. So, if I'm working within my Players Form, and I want to have a look at the details about their Team, I could just click that field and the Teams form would be shown for that player's team.

Hopefully, that's fairly clear. Any thoughts how I might go about making this a reality?


I have three tables that I need to compare and use a checkbox

Table one - list of all the stores
Table two - list of managers
Table three - list of store assignments

Table three is the one that needs to be able to update / add / delete

I would like a list of all the stores when a manager is picked (dropdown list) in one gridview, and the ability to check (assign a store to) and uncheck (remove an assigned store).  Table one and two are static and will never change.

Any help would be great!  I am stuck on how to do the SQL statement and the code for the gridview
Using Visual Studio 2015 on Server 2008R2, coding in VB.Net.
Any of my existing projects now give the message
"Error while trying to run project. The Visual Studio Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer. "
The projects still compile, and I can run the .exe, but I can't debug or step though code.
Any ideas?

VS2015 Error
I have images saved in different Idproduct folder. Each image will be linked to a third-party website with the same image. I followed  the expert Snarf0001's  example. But has error saying 'i' is not declared. It may be inaccessible due to its protection level.
Below is the coding:
 <a href="<%=productsku%>&imagelocation=images/600x600/<%=idProduct%>/<%= System.IO.Path.GetFileName(imageList(i)) %>"><img width="60px" height="60px" src="images/600x600/<%=idProduct%>/<%= System.IO.Path.GetFileName(imageList(i)) %></a> 

Open in new window

Please advise! Thank you!

I have found the following code to render an SSRS via a SSIS script. This script works as it is intended, e.g. saves the rendered report to disk.

But I would like to send the rendered report as an email attachment, without saving it to disk. Please could someone help? I have tried to render it to a memory stream but I can't quite get it to work.

Thanks, Greg

 Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
        Dim loRequest As System.Net.HttpWebRequest
        Dim loResponse As System.Net.HttpWebResponse
        Dim loResponseStream As System.IO.Stream
        Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
        Dim laBytes(256) As Byte
        Dim liCount As Integer = 1
            loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
            loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
            loRequest.Timeout = 600000
            loRequest.Method = "GET"
            loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
            loResponseStream = loResponse.GetResponseStream
            Do While liCount > 0
                liCount = loResponseStream.Read(laBytes, 0, 256)
                loFileStream.Write(laBytes, 0, liCount)
        Catch ex As Exception
        End Try
    End Sub

Open in new window

Hi All,

I want toggle show selected data.
Please see below code.

  Private Sub btnInvoiceYangDibayar_Click(sender As Object, e As EventArgs) Handles btnInvoiceYangDibayar.Click

        Static blnFilerInvoice As Boolean = False

        Dim dataView As DataView = dtTDFAKTUR.DefaultView

        If Not blnFilerInvoice Then
            dataView.RowFilter = "Pilih = 1"

            dgvFaktur.DataSource = dataView
            dgvFaktur.DataSource = dtTDFAKTUR            
        End If

        blnFilerInvoice = Not blnFilerInvoice

    End Sub

Open in new window

It works when blnFilerInvoice  = false, but not when blnFilerInvoice = true

Scenario, there are 10 rows, I selected 1 rows, when the first time press the button, it should just show just 1 row selected.
And I press again, the it should show 10 rows again.

What is wrong with my code ?

Thank you.
Hello.  I want to use SQLite in my VB.NET application.  In my application, the user opens a file and the database connection is kept open until the program is shut down, or another file is opened.  A major requirement I have, however, is that these files should be password protected so that they can only be opened by my application.  I have found some options for encrypting SQLite files (e.g. SQLiteCypher), but they are a bit pricey so I'm looking for other methods to get what I need.

One alternative I thought of would just be for me to manually encrypt and decrypt files using Rijndael (I found an example on CodeProject).  That is, when the file is created within my application, it is encrypted so that it cannot be opened by any normal SQLite viewer application.  However, when the file is opened in my program, it would first be decrypted, then connected to normally.  When the connection is closed, the application would then encrypt it again.  I have done a quick test on this and it seems to work, but I am wondering if I am missing, or not considering, something.  Is there any reason why this idea would be ill-advised?  Thank you.

How do I convert these properties and such from vb6 to or c# prefably. Thank you.

Public Property Let Confirmed(Index As Integer, bConfirmed As Boolean)
    If bConfirmed Then
        sTransferOrder_Items(Index, GI_CONF_TO_ITEM_CONFIRMED) = vbChecked
        sTransferOrder_Items(Index, GI_CONF_TO_ITEM_CONFIRMED) = vbUnchecked
    End If
End Property
Public Property Get Confirmed(Index As Integer) As Boolean
    Confirmed = (sTransferOrder_Items(Index, GI_CONF_TO_ITEM_CONFIRMED) = vbChecked)
End Property
I need to validate my invisible recaptcha in server side

I have an  native .asp file to get user data and email it,
how to validate the recaptcha in there?

<!DOCTYPE html>
	<meta charset="utf-8" />


set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;data;packet size=4096;user id=xxxx;pwd=xxxx;persist security info=False;initial catalog=xxxx"

sql="INSERT INTO comentarios (nombre, email,telefono, producto, comentario)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("fname") & "',"
sql=sql & "'" & Request.Form("email") & "',"
sql=sql & "'" & Request.Form("telefono") & "',"
sql=sql & "'" & Request.Form("consultorio") & "',"
sql=sql & "'" & Request.Form("message") & "')"

on error resume next
conn.Execute sql,recaffected
if err<>0 then
  Response.Write("Error, Intente otro metodo de contacto!")
 Response.Write("<a href=''><h3>Regresar a página de contacto.</h3></a>")
 Response.Write("<h3>Nos pondremos en contacto lo antes posible.</h3>")
 Response.Write("<a href=''><h3>Regresar a Oncolosdsddsdsío.</h3></a>")
end if
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Tel,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError

smtpserver = ""
youremail = 

Open in new window

Hi All,

I want to check if Customer name or address has exists in database,
How could I check it?

May be I should list that has almost the same name of Customer or Address?

Thank you.
I open reports of my project in internet explorer which are being made from string. Now i need to bifurcate my reports by detecting the new page so that margin could be set for each and every page.

In other words i wish to add multiple pages in a report but if my page has less data then i need to start the next page.

I am using windows application.

Thanks a ton in advance.
How do I do EagerLoading of this object
Public Class Person 
    Public Overridable Property personId As Integer
    Public Overridable Property nameType As String

   Public Overridable Property Names As IList(Of PersonNameType)

End Class

Public MustInherit Class PersonNameType
    Public Overridable Property personId As Integer
    Public Overridable Property nameId As Integer

    Public Overridable Property Person As Person
    Public Overridable Property Name As Name

End Class

Open in new window

I tried doing this but the navigation properties (Person/Name) of "Person.Names" is not getting filled. I mean when I drill into the Person.Names and one of the collection item the personId/NameId has data but the Person/Name properties has nothing. How do I fill that data in?
Right now I have an export file being saved with a unique barcode that is attached to the export file. I would like to know how I can add a unique month and year to the file but if I have multiple data collected in the same month I would append that data until a new month.

For Each export In pFile.Exports
If newDir = String.Empty Then
If export.addVariableExportUniqueVIN Then
exportFile = New FileInfo(newDir & "\" & export.ExportName & ScannedBarCode & export.ExportExtension)
exportFile = New FileInfo(newDir & "\" & export.ExportName & export.ExportExtension)
End If
end if

Open in new window

My web page has the function to create 40 different pie charts for 40 different machines and their activity and display them after loading. However, I noticed that by doing so the page loading is much longer, takes about 30 seconds to finish loading.

At first I thought it was my SQL to get the data for 40 machines was the cause. But after copying it from the code and testing it, that was not true. Also, the page loads faster when I set my page to create a single pie chart, so I'm likely to assume that the large sum of pie charts to create is the cause for the slowdown.

 Sub draw_chart1() 'All Machines

        Dim check1, check2, fi, cnt

        Dim sql
        Dim myConnectionString As String = "Provider=SQLOLEDB;" & SQLDB_pp.ConnectionString
        fi = 0
        cnt = 0

        'Get all model
        Dim query1 As String = String.Format("SELECT DISTINCT A.MacID FROM dbo.tblMachine A LEFT JOIN  dbo.tblDataHdr b on a.MacID = b.MacID where DayID between '" & TextBox1.Text & "' AND '" & TextBox3.Text & "' ORDER BY A.MACID")
        Dim dt1 As DataTable = GetData(query1)
        For Q As Integer = 0 To dt1.Rows.Count - 1
            'For Q As Integer = 0 To 1
            check1 = dt1.Rows(Q)(0).ToString()

            Dim query As String = String.Format("SELECT Z.MacID, Z.EventName, ISNULL(DIFF,0) AS DIFF FROM (select distinct MacID, EventName from dbo.tblMachine a  join (SELECT DISTINCT EVENTNAME FROM

Open in new window

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.


    Public Function Add(ByVal itemToAdd As TObject) As TObject
        Dim addedItem As TObject = DbSet.Add(itemToAdd)
        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

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.
3. What function/process could you use to combine two datasets/tables together (assume
the tables have the same number of columns and data types?

I need to upload a file with a webrequest and combine it with some other form data in the request. Today my post request looks like this:

  Protected Function PostData(ByRef url As String, ByRef POST As String, ByRef Cookie As System.Net.CookieContainer) As String
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse
        request = CType(WebRequest.Create(url), HttpWebRequest)
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = POST.Length
        request.Method = "POST"
        request.AllowAutoRedirect = False

        Dim requestStream As Stream = request.GetRequestStream()
        Dim postBytes As Byte() = Encoding.ASCII.GetBytes(POST)
        requestStream.Write(postBytes, 0, postBytes.Length)
        response = CType(request.GetResponse, HttpWebResponse)
        Return New StreamReader(response.GetResponseStream()).ReadToEnd()
    End Function

Open in new window

The string post (in request.ContentLength)  now contains this form-data:

Open in new window

Now I want also to add this form data parameters:
file (a pdf file to upload)
recipient_email (string value)
recipient_name (string value)

How do I need to alter the PostData function to be able to post both the file and the string data in the webrequest?

Thanks for help!

(Object reference not set to an instance of an object)

The following code (sometimes) give the above error only if the file is a (multi page tiff file with a large number of pages)  e.g.  400 pages or 500 pages. Not on a specific page.
and when I check     PictureBox1.Image     I find it = null!
If I reRun my software it works fine on the same page that it stopped on.
I feel it is something related to memory   (e.g.   executing the next line before full load .....)
Any help is appreciated.

PictureBox1.Image = Image.FromFile("C:\ImgFolder\ImageName.tif")
Dim NoOfPages As Long = PictureBox1.Image.GetFrameCount(Imaging.FrameDimension.Page)

For J = ImagePageFrom - 1 To ImagePageTO - 1
       PictureBox1.Image.SelectActiveFrame(Imaging.FrameDimension.Page, J)    'the error is on this line
       PictureBox1.Image.Save("C:\ImgFolder\ImageName.Gif", Imaging.ImageFormat.Gif)
PictureBox1.Image = Nothing

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,