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 have a home grown vb.net desktop application I built years ago for my Windows 7 environment.  This application connect to a MSSQL database.  Now I am trying this out on a Windows 10 machine (1803 build) and I am getting this error.  
2019-06-21_9-17-12.png
When I open Visual Studio to see if I can address this by playing around with the connection string, but still no luck.  

Any advise :)
0
Hello Experts,
When my following code is executed, the database connection remains open for a long time even after the processing work is done.  If I execute the following code  N number of times, there are N number of connections opened, and they is remain open for a while, which causes our db server to perform slow.

        int returnId = 0;
        SqlParameter[] parm;
            
        try
        {
           parm = new SqlParameter[2];
           parm[0] = SqlHelper.CreatePerameter("@EMP_CODE", SqlDbType.VarChar, strEmpCode, ParameterDirection.Input, 50, false);
           parm[1] = SqlHelper.CreatePerameter("@UPDATED_BY", SqlDbType.VarChar, strUpdatedBy, ParameterDirection.Input, 10, false);
           returnId = SqlHelper.ExecuteNonQuery(SqlHelper.GetConnection(), CommandType.StoredProcedure, "usp_deleteTran", parm);
        }
        catch (Exception ex)
        {
        }

Open in new window


I have a SqlHelper class where I have the GetConnection method, which is used quite often through out the solution.  The question is how can I close the connection automatically once the DB work is done?  If I try to close it in every program, it would be lots of work.  Please see below the GetConnection() method inside the SqlHelper class.  Please let me know.

Thank you very much in advance.


SqlHelper Class
	public static SqlConnection GetConnection()
	{
	    string strConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();
	    if (strConnectionString.ToLower().IndexOf("database=") == -1)
	    {
		strConnectionString += "Database=sbmwonder" + System.Web.HttpContext.Current.Session["sbm"].ToString();
	    }
	    
	    SqlConnection sqlCon = new SqlConnection(strConnectionString);	
	    return sqlCon;
	}

Open in new window

0
Hi. I have an exl file with extension .xls and I need to convert it to .xlsx. My code will change the file name in the Explorer window but when I try an open it in Excel it gives me error "Excel cannot open the file because the file format or extension is not valid.


Here is my code:

        'Open Excel file chosen by user
        ForcastWorkBook = ForcastApp.Workbooks.Open(strFileName)
        'Name worksheet to use in workbook
        ForcastWorkSheet = ForcastWorkBook.Worksheets("Michelin_PA___Project_Cost_Sum_")
        ForcastWorkBook = ForcastApp.Workbooks.Open(strFileName, Editable:=True, ReadOnly:=False)


        'Save new workbook with new name
        strNewFileName = strNewFileName & "x"

        ForcastWorkBook.SaveAs(strNewFileName)
0
Hello,

I'm using below code to extracting my datagridviews to Excel sheet via ClosedXML. Some of my columns are invisible and i dont want to extract it.

How can i apply this to my code? Any help would be grateful.

Thank you.

        Public Shared Function WriteCheckSheetDgvToExcel(ByVal objSheet As Excel.IXLWorksheet, ByVal dgv As DataGridView) As Boolean
            Try
                For colHeader As Integer = 1 To dgv.ColumnCount Step 1
                    If dgv.Columns(colHeader - 1).Visible = True Then
                        objSheet.Cell(1, colHeader).Value = dgv.Columns(colHeader - 1).HeaderText
                    End If

                Next
                For col As Integer = 0 To dgv.ColumnCount - 1 Step 1
                    For row = 0 To dgv.Rows.Count - 1
                        objSheet.Cell(row + 2, col + 1).SetValue(Convert.ToString(dgv.Rows(row).Cells(col).Value)).SetDataType(Excel.XLDataType.Text)
                        If dgv.Rows(row).Cells(col).GetType = GetType(DataGridViewComboBoxCell) Then
                            Dim cboCell As New DataGridViewComboBoxCell
                            cboCell = CType(dgv.Rows(row).Cells(col), DataGridViewComboBoxCell)
                            If cboCell.Items.Count > 1 Then
                                objSheet.Cell(row + 2, col + 1).DataValidation.List(ComboboxItemsToList(cboCell), True)
                            End If
                        End If
                    Next
      

Open in new window

0
Hello, All.

OK, In ASP Classic we use this.

' Insert into database
Response.CodePage = 28591
Response.CharSet = "ISO-8859.1"

Open in new window

And then
' Read back to the page from the database
Response.CodePage = 65001    
Response.CharSet = "utf-8"

Open in new window


Now, I am coding VB.net and am wondering, how to do this in VB.net?
And where to place it at in the code that exist?

In the insert page. I have everything sitting inside of the
   Partial Class _Default

Wayne
0
Hi all,

I have created Visual Basic code to write errors and information to the Windows Event log. That works fine but I am looking for code to add attributes to the event like the event property User.

Anyone any suggestions? This is my current code:

    Sub log_event(ByRef sEvent As String, ByRef LogItem As Long)

        Dim myLog As New EventLog

        Dim sSource As String
        Dim sLog As String
        Dim sMachine As String

        sSource = "Werkvergunning"
        sLog = "Application"
        sMachine = Environment.MachineName.ToString

        If Not EventLog.SourceExists(sSource) Then

            EventLog.CreateEventSource(sSource, sLog)

        End If

        With myLog

            .Source = sSource
            .Log = sLog
            .EnableRaisingEvents = True

            Select Case LogItem

                Case 1
                    .WriteEntry(sEvent, EventLogEntryType.Error)

                Case 2
                    .WriteEntry(sEvent, EventLogEntryType.Information)

                Case 3
                    .WriteEntry(sEvent, EventLogEntryType.Warning)

            End Select

        End With

    End Sub

Open in new window

0
Hi,
I tried to create report using form, after finishing I fount out that when I select some items that have fewer specs it show empty value which makes the report missed up.
How can I create report that only display only the specs related to certain items and hide lables and empty speces

Thank you
0
Hi
I have this code:
 chkdis.Text = selectedRow.Cells(19).Value.ToString
but it's not populate the check box when I select record in datagrid, it populate the textbox only. Please provide me with code that will check the check box when I select a record in datagrid because i only able to add item in check box but I can not delete any.

Thank you
0
Hi,

I have written a payroll / job costing app in vb.net. They now want to have a wall mounted timeclock preferably one with rfid card reader integrated into it. Does anyone know of one that has a .net api.

Thanks

Nick Steele
0
Hello,
I have vb.net form with datagrid, how can i change the color of the cell containing numeric value when the value changes or updated.
0
Hi All,

I have cerated a VS project.
Unfortunately the project files are inside same name folder like D:\APPS\APPS\APPS.

How could I move to D:\APPS ?

Thank you.
0
Using vs2010 c++. Net class library project, how to fix unresolved external symbol when calling static class method which coming from static c++. Lib compiled in vs2003?
Doing a dotnet c++ \CLI wrapper on old static mfc c++. Lib.

More info:
1. I got these c++ header files and the associate compiled static *.lib files (Hidden method implementation) from 3rd party vendor software. These files were compiled with old vs2003 which I don't have the source files.
2. These header files show us the method signature that we can invoke in our own project once included them in the MFC C++ project setting (Include Additional Directories/Dependencies).
3. Among the methods provided, one of the method was declared as static method.
4. Now, I'm trying to make C++ .net wrapper class to wrap all the methods provided so that it can be turned out as .net class library and used on other CLR .net projects.
5. I've tried to make it as native C++ dll, but seems too complicated and involves a lot of data types marshalling / and unforeseen memory corruption / crashes.
6. While doing the .net wrapper class and try to invoke the static method, the vs2010 that I use now, said unresolved external symbol for this static method.
1
i want to read the Header of mail  through windows application in vb.net . How to do that
0
How to get the second value of a query

 Dim nusa2 As String = "select top 1 mv,ml  from mlbscores where (pv='" & pl.Text & "' and  ev='" & el.Text & "' ) order by ident desc"
        Dim cmdd2 As New OleDbCommand(nusa2, cns)
        marca5 = cmdd2.ExecuteScalar()

Open in new window


with this i got the value of mv
how do i got the value of ml?

regards you experts
0
Hi,

I want to get "complete" page source from webpage but the "view source" option shows only HTML.  The code I want to access is only viewed using "Inspect Element" in Chrome/Firefox. Is there anyway, in C# or VB.NET to get the contents of Inspect element of the page ?
0
I've got an app that I serve using ASP.NET MVC. It calls APIs in the same application.  The API controllers have the [Authorize] attribute assigned. The app uses Azure AD and has an OwinStartup class which authenticates. See below. This all works fine.

We now have a request to make the APIs visible to other applications. Is it possible to somehow make the APIs allow authorization if we send a bearer token which we get from Azure?

 public class Startup
    {
       string clientId = System.Configuration.ConfigurationManager.AppSettings["Azure.ClientId"];

        string redirectUrl = System.Configuration.ConfigurationManager.AppSettings["Azure.redirectUrl"];

       static string tenant = System.Configuration.ConfigurationManager.AppSettings["Azure.Tenant"];

        string authority = String.Format(System.Configuration.ConfigurationManager.AppSettings["Azure.Authority"], tenant);

        /// <summary>
        /// Configure OWIN to use OpenIdConnect 
        /// </summary>
        /// <param name="app"></param>
        public void Configuration(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    AuthenticationMode = AuthenticationMode.Passive,
                    // Sets 

Open in new window

0
vb.net  linkbutton.  How to allow  a site visitor to click a linkbutton on aspx page and download mp3 file to their machine or device.

problems encountered:
music plays or thread aborted encountered or nothing happens

need help
0
Hello EE,

I have in vb.net a dictionary of (Date, String) that looks like this :

"01/01/1980" ; "a,b,r,e,t,b,g,x,y,z"
"02/01/1980" ; "k,w,q,z,c,u,i,o,p"
"03/01/1980" ; "n,w,q,y,h,v,r"
.....
"04/28/2019" ; "b,c,r,y,z"


actually, the "string" part has always 20 letters. i did not write them all, but you understand.
My problem is, If I tell my software to look for all combination of 5 letters or let's say 6 letters... and to tell me :

for "a,b,c,d,e,f" when is the last time it was in ?
then for "a,b,c,d,e,g" when is the last time it was in ?
then for .....
then for "u,v,w,y,z,x" when is the last time it was in ?

by doing 2 FOR LOOP is long.

My main question is, is there any Functions, or special classes, or LINQ methods that are more efficient in terms of speed?

my code today is doing this :

        For x As Integer = 0 To combinaisonList.Count - 1
            Dim arrString As String() = combinaisonList(x).Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)

            For Each kvp As KeyValuePair(Of Date, String) In MyItems.Reverse
                If arrString.All(Function(v) kvp.Value.Contains(v)) Then
                    finalLoop.Add(combinaisonList(x), Math.Abs(DateDiff(DateInterval.Day, Now, kvp.Key)))
                    Exit For
                End If
            Next
        Next

Open in new window



so combinaisonList is the (List Of String) of all combinaison that I deceided lets say (6 letters)
and "MyItems" is the dictionary(of date, string) that I was talking about

My code works, but its not fast enough.
1
I've COM based application. My tool is connecting a third part tool with COM interface but it gives an error sometimes like below;

"The RPC server is unavailable . (Exception from HRESULT: 0x800706BA)

Could anyone have an idea what is causing to it ?

.NET Framework: 4.7.2
OS: Windows 7 Enterprise

Also There's an Debug  output when i debug it on error

'_simpack-com-slv.exe' (Win32): Loaded 'C:\Program Files\Simpack-2018x\run\bin\win64\_simpack-com-slv.exe'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Program Files\Simpack-2018x\run\bin\win64\MainSupport.dll'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Program Files\Simpack-2018x\run\bin\win64\IO.dll'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Program Files\Simpack-2018x\run\bin\win64\crg.dll'. Cannot find or open the PDB file.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Program Files\Simpack-2018x\run\bin\win64\libmmd.dll'. Module was built without symbols.
'_simpack-com-slv.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140.dll'. Cannot find or open the PDB file.

Open in new window

0
I'd like to show a dialog like below when some procedures(sub or func) actively running on application? Probably it needs AddressOf but i don't know how to apply such a feature. I'll be glad if anyone has an experience about it.

2019-04-26-00_47_39-Window.png
0
I have a chart control in asp.net that I am trying to display annotation in the chart area - topcenter of 'ChartArea1'.  It does not display on the chart.

Why?

Below is my asp.net code

<Annotations>
                                        
<asp:TextAnnotation Alignment="TopCenter" Font="Arial, 10pt" ForeColor="#00FFCC"
Name="Chart1Annotation" Text="Nominal" TextStyle="Default" ClipToChartArea="ChartArea1">
</asp:TextAnnotation>
</Annotations>

Open in new window

0
Hi all
this one put me the date with hour

SELECT max(CONVERT(datetime, fecha, 103))

i want it whitout hour
is any way
tsm you experts
regards
0
I have a crystal report, develop in VB.  In the details section you would see rows of records like the following.

TIme In  2:00 AM  Time Out  3:00 AM  Elapsed  0.00
Time In 3:05 AM  Time Out 4:00 AM  Elapsed 5 minutes

etc.

I want to calculate the elapsed time between the current record and the one sitting above it.  Records will be sorted by time out
0
I am making my first attempt to use Google.Cloud.Translation.V2 in a VB.Net app.

I have installed the appropriate library using NuGet.

My code is:

Imports Google.Cloud.Translation.V2

Public Class Form1

  Private Sub Translate()

    Dim GClient As TranslationClient
    Dim GResult As TranslationResult

    GClient = TranslationClient.Create()
    GResult = GClient.TranslateText("This is some text to translate.", LanguageCodes.German)
    MsgBox(GResult.TranslatedText)

  End Sub

  Private Sub butTranslate_Click(sender As Object, e As EventArgs) Handles butTranslate.Click

    Translate()

  End Sub
End Class

Open in new window


I have created a service account key and downloaded the JSON file to the root of my C: drive, then I added the following environment variable:

GOOGLE_APPLICATION_CREDENTIALS=C:\My First Project-fcf4f0971c53.json

Open in new window


When I run the above app, I get:

Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.'
What am I doing wrong?
0
Dear Experts,

My application doesn't  detect and replace old versions during re-installation/update I am using VB.NET
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,