We help IT Professionals succeed at work.

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,

Greetings;

I have a multi page PDF file that is a String of Shipping Labels, The labels have Line Items that reflect the items purchased by our customers, Each line item contains our 'ItemSKU', 'ItemDescription' and 'ItemQuantity'.

The ItemSKU is a 'Parent SKU' which I need to replace with a substitute SKU if a give product is out of stock. The Labels are generated via a separate process where a PDF file with multiple labels/pages. I process this PDF file with a completely different process which determines whether or not the 'Parent SKU' needs to be replaced with a Substitute SKU,

I have gone through many iterations but have not been successful in creating a working program. The following Code is what i tried last and seem to hold much promise but it fails after the First page/label has been processed. I believe that a better set of eyes might be able to spot my mistakes.. Any and All help is appreciated. Thanks in advance,

Public Function MyReplacePDFText() As Integer

        Dim psStamp As PdfStamper = Nothing 'PDF Stamper Object
        Dim pcbContent As PdfContentByte = Nothing 'Read PDF Content

        Dim strSource As String
        Dim strDest As String

        Dim strSearch As String
        Dim scCase As StringComparison

        scCase = StringComparison.OrdinalIgnoreCase

        strSource = MultiQuantManagerForm.txtPDFFileName.Text
        strDest = TempDataStorageFolder + "\TestTextReplacement.pdf"


        If File.Exists(strSource) Then 

Open in new window

0
In Visual Studio 2019 I am trying to select the text in a textbox programmatically. But neither intellisense gives the option of selectionstart or selectionlength nor can I see it in the properties pane. Even if I type it out manually it gives an error.

In the object browser the only items show for selectionstart are shown. Textbox is not part of it.
selectionstart.PNG
How can I select the text inside the textbox programatically?
0
Hi Experts,
I have a question about checkbox in vb.net visual studio 2019.  I notice if I have a checkbox on a form with Bndingsource, the checkbox is black, I have to click on it able to check, attached is the screen shot that I place two checkboxes, one with the black dot is bind with the bindingsource, the other one is the regular checkbox is not use the bindingsource.  How do I fix the one with the bindingsource like the regular one or the checkbox will be has the black dot if it's bind with the bindingsource?

Thanks
CheckBox.png
0
Hi

I am getting the following error when running a VB.net Excel Add-in  that was built on another machine where I had Excel 2007 and Visual Studio 2017.
I now have Visual Studio 2019 and Excel 2019 on my current machine.
How do I fix this?

Thanks

1
0
I have an Excel VB.net add in that I built in a previous version of Visual Studio. In Visual Studio 2019 where do I reference
Microsoft.Office.Interop.Word.Application?

Thanks
0
Hello, i'm trying to learn the basics of VB.
I have installed Visual Studio 2019
I have installed MySQL server and created a test db with a table and column.
I have connected the studio to MySQL successfully
I'd like to master creating a form and inserting, updating and displaying the contents of the db table.

I'm struggling to find a decent video tutorial of this. like how to program the save button and insert it into the db.

All the videos i find are either in very bad English or they describe very different methods from each other so i'm not sure which one i should be following.

can someone point me towards some good material please?
thanks
zac
0
I am trying to populate a datagridview from a datatable but I don't want to bind it to the datatable. With the below code it's only displaying data in the last row (see attached picture). There are 5 records in the table. When I single step through the code and watch the row count is changing and the data is changing.

        Dim CheckUser As DataTable, intRow As Integer = 0

        CheckUser = ReadDataFromDB("SELECT * FROM users;", False)

        For Each row In CheckUser.Rows

            If Not String.IsNullOrEmpty(row("UserID").ToString) Then
                'DGridVUsers.CurrentRow.Cells(0).Value = row("UserID").ToString
                ' DGridVUsers.Rows(intRow).Cells(0).Value = row("UserID").ToString
                With DGridVUsers
                    .Rows(.Rows.Count - 1).Cells("UserID").Value = row("UserID").ToString
                    .Rows.Add()
                End With
            End If
            intRow += 1
        NextDatgridview Last Row Only
0
Hello All:

I have a classic web forms asp (vb) web application that I am working with.  I have one page that I would like to embed a value from my web.config's app.settings.  this page references an external js file.  What I am ultimately trying to do is pass the value from app.settings to the js file on an onclick event.  The app.settings key holds the value of the current server, so I have transforms set to update the web.config with the correct server name when the application runs.

So in my app.settings I have:
<add key="CurrentServer" value="ProductionServer"/>

What I was trying to do was something like this:
<input type="hidden" id ="CurrentServer" value="<%$ AppSettings: CurrentServer %>" />

My reasoning behind this approach is then in the external file, I could target this input by doing something like:

let currentServer = document.getElementById('CurrentServer').value

When I run the page, I receive the following error:
Literal expressions like '<%$ AppSettings: CurrentServer %>' are not allowed. Use <asp:Literal runat="server" Text="<%$ AppSettings: CurrentServer%>" /> instead.

Can someone please steer me in the right direction?  Would a server control be more appropriate?  If so, how would I interrogate the rendered control using JavaScript once the onclick even is fired that triggers the javascript code?

Many thanks for any assistance!

Juan
0
Hi
In my ASP.net Site Master whose markup code is shown below I have the following button
     <button class="btn btn-primary" ID="btnGetStarted">Get started</button>
I want to run VB.net code behind this but when I double click on it it does not create a VB.net click event



<%@ Master Language="VB" AutoEventWireup="true" CodeBehind="Site.master.vb" Inherits="Office2Web.SiteMaster" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><%: Page.Title %> Office2Web Microsoft Office and Web Solutions</title>

    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>

    <webopt:bundlereference runat="server" path="~/Content/css" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap" rel="stylesheet">
</head>
<body>
    <form runat="server">
        <asp:ScriptManager runat="server">
            <Scripts>
                <%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%>
                <%--Framework Scripts--%>
                <asp:ScriptReference Name="MsAjaxBundle" />
                <asp:ScriptReference Name="jquery" />
                <asp:ScriptReference Name="bootstrap" />
              …
0
Hi

In ASP.net I have a web form where the user can fill out their email address and some other details then hit a button that sends me an enquiry. I usually just use VB.net code to send an email to me. Unfortunately the emailing isn't work properly so was looking for other ways to be notified of the enquiry. Is there something that I can build in or perhaps a service that I can use? Any suggestions would be welcome.

Thanks
Murray
0
Hello All;

I have a file move issue that only started because I had to take a sub-folder on my site, and [convert to Application]

Here is a portion of the code I am using.
            For Each postedFile As HttpPostedFile In filMyFile.PostedFiles
                Dim getfile As String = System.IO.Path.GetFileName(postedFile.FileName)
                Dim FileToMove As String
                Dim MoveLocation As String

                           GlobalVariables.savepath = Context.Server.MapPath("../Media/Temp/")
                           GlobalVariables.MovePath = Context.Server.MapPath("../Media/")


                            FileToMove = (GlobalVariables.savepath & getfile & ".mp3")
                            MoveLocation = (GlobalVariables.MovePath & strPath & "/" & getfile & ".mp3")


                            If System.IO.File.Exists(FileToMove) = True Then
                                My.Computer.FileSystem.MoveFile(FileToMove, MoveLocation) ' <<<< ERROR POINTS HERE
                            End If

Open in new window


The code was working correctly until I changed the sub-folder to [convert to Application]
Once I did that, I received this error.

Permissions are correctly given for the folder, so it does not seem to be a permissions issue.
I used Windows Resource Monitor.
Chose the CPU tab.
Searched for mp3 in the [Associated Handles]
Here is one line from the results of the search


Image                PID      Type      Handle Name
w3wp.exe      12272      File             G:\InetPub\wwwroot\mysite\Media\Temp\03112020223702438.mp3

I read that I needed to close the opened file.
I tried to do.
mp3.Dispose() ' did nothing
filMyFile.Dispose() ' did nothing

Open in new window


Any other suggestions to help get past this issue, so it will go back to working correctly?
Thanks.

Wayne
0
I have a form on web application, I load the field values on the form and click the save button and it doesn't save the record on the database at first click but if I press the button again it saves it. I put the breakpoint on my Page_Load()event and tried debugging it so what happens is as I run the application, Page_Load() gets executed populates the data on the grid. Now, if I enter field values and click save, it again goes to Page_Load() event but it doesn't go to button_save() event. But if I click it again then it goes to Page_Load() and then goes to button_Save() and saves the record.

I want to click the mouse button once and save the record, how could I be able to do that? I am using VB.NET. Thank you.
0
Hello All;

I am trying to get the duration of an mp3 file.
The two components I have been using, both give the wrong values.
(ID3TagLibrary.dll and TagLibSharp.dll)

After doing some more checking on other ways of getting the duration.
I found this.

' Install from NuGet NAudio
Imports NAudio.Wave
'...
Private Shared Function GetMp3Duration(filename As String) As Double
    Dim reader As New Mp3FileReader(filename)
    Dim duration As Double = reader.TotalTime.TotalSeconds
    reader.Dispose()
    Return duration
End Function

Open in new window


I am using it like this in my sub page_load.

        Dim filename As String
        filename = "G:\VS_Lessons\Media\Read\01. Got to Choose.mp3"
        Dim reader As New Mp3FileReader(filename)
        Dim duration As Double = reader.TotalTime.TotalSeconds
        reader.Dispose()
        Dim s As String = TimeSerial(0, 0, 0).AddMinutes(duration).ToString("mm:ss")
        Label1.Text = s

Open in new window


I do not think this is the proper way of getting the duration.
As it is giving me ( 54:36 )
When it should be: ( 3:54 )

Could someone please assist me in getting the proper time back from an mp3 file?
Thank you.
Wayne
0
Hi

I want to learn how to use Microsoft Power Apps. I code Excel and Access solutions in VBA and VSTO
and ASP.net web solutions in VB.net. Where will I find parallels and tutorials?

Thanks
0
Hi. I am trying to use VB.net to hide the following part of my page. I can't see an ID so not sure what to do. A css designer modified this part of the page

<div class="card filter-card mb-4">
    <div class="card-body">
        <div class="dropdown-button-wrapper">
            <a class="btn-dropdown dropdown-toggle d-block" data-toggle="collapse" href="#widthCollapse" role="button" aria-expanded="false" aria-controls="widthCollapse">
                                            Width
            </a>
        </div>
        <div class="collapse filter-body w-100" id="widthCollapse">
            <input class="form-control mb-3" id="Width1" runat="server" type="text" placeholder="From" />
            <input class="form-control" id="Width2" runat="server" type="text" placeholder="To" />
        </div>
    </div>
    <div class="card-body">
        <div class="dropdown-button-wrapper">
            <a class="btn-dropdown dropdown-toggle d-block" data-toggle="collapse" href="#lengthCollapse" role="button" aria-expanded="false" aria-controls="lengthCollapse">
                                            Length
            </a>
        </div>
        <div class="collapse filter-body w-100" id="lengthCollapse">
            <input class="form-control mb-3" id="Length1" runat="server" type="text" placeholder="From" />
            <input class="form-control" id="Length2" runat="server" type="text" placeholder="To"/>
        </div>
    </div>
    <div class="card-body">
        

Open in new window

0
Hi Experts,
how to display a pdf file in picturebox using vb.net?. Thanks for the help
0
I have a program that uploads a folder that a user selects, but I want to make sure the folder does not contain sub folders (otherwise they might upload their entire hard drive!). I have the path to the folder and just need to know if there are sub folders. I'm thinking there should be a way to do this with just a couple lines of code, but I can't find anything.  I found the below code, but it's in C# and I can't figure out how to get it to work in VB.  I don't need to use this code... if there is a better way to do this, I rather go with the better solution.

Please do not post links... I'm looking for code. Thanks!

DirectoryInfo directory = new DirectoryInfo(SubFolderFullPath);
DirectoryInfo[] subdirs = directory.GetDirectories();
                       
if (subdirs.Length == 0) hasSubfolders = false;

Open in new window

0
Hello, All.
(On server farm. The script will run from either 4-servers.
However, they upload to a SINGLE server, which copies files to two other servers)

I have run into an issue.
My script is enormous and writes a lot of information into the database for each media file uploaded.
If I upload a few files, say, up to 10. They usually do not have an issue.
However, when I upload more than 10, say, 15 and above, it will send me over to
HTTP Error 502.3 - Bad Gateway
Even though the page shows, it will continue writing to the database until it finished with the script.
Except some of the data is incorrect. So, this error does cause issues with some of the written data, but will not stop it.

Which for what I have read, it is timing out.
I have this in my web.config file.
<httpRuntime executionTimeout="9999" maxRequestLength="2097151"/>

Open in new window

But still, it will resolve to the 502.3 error page.

Any help on this would be great.
Thanks.
Wayne
0
Hello All;

I am having a cookie issue.
(This is in a server farm, I am not sure if that makes to much of a difference, as the Cookie is saved on the client's system and not on the server(s).)
And the screenshot below, you can see the value is (3)
However, when I try to read it into the SQL Query from a vb.net script, it inserts the number (2)
The Cookie is created with this.
Response.Cookies.Set(New HttpCookie("theAlbumCookie", rsAlbum("AlbumID")))

Open in new window

The Cookie is then read with this.
Request.Cookies("theFArtistCookie").Value)

Open in new window


A response.write, gives the correct value. (Sometimes, as I found out a little later on after posting this)
                
Response.Write(Request.Cookies("theAlbumCookie").Value)
Response.End()

Open in new window


I ran a test real quick and it inserted the correct number.
Then I uploaded another song from another album, and it inserted the number from the previous album, even though the cookie Value is for the current album, which in this case, will be a (4)

Can someone please let me know what is causing it to read the Cookie as a different value, when, as seen in the screenshot, it is a (3)
Cookie Properties
Thanks.
Wayne
0
Hi all, hope you can help. I am having a problem that I was not expecting (based on my readings), so it seems clear that I have missed something.

I have a main form in an application that displays a Work Schedule for a machine. Periodically a legacy application (that I cannot change) updates the machine schedules meaning that the display on the screens needs to update. The application running on the machine screens has a Timer that fires every 10 minutes to query the schedule database to get the current Work Schedule for the particular machine.

The code on the Timer Tick event is simplicity itself:

Private Sub tmrRefreshJobs_Tick(sender As Object, e As EventArgs) Handles tmrRefreshJobs.Tick
    
    bgwRefreshJobs.RunWorkerAsync()

End Sub

Open in new window


It just fires up a BackgroundWorker that goes off and queries the database for the current Work Schedule for the machine. The DoWork event is no more complicated, simply calling a routine to query the database and return a list of jobs. All of the work is done in that routine, and even that is straight-forward - it uses a DataTable and DataAdapter to query data from a SQL database and load it to the list.

Private Sub bgwRefreshJobs_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgwRefreshJobs.DoWork

    Dim newPlannedJobs As List(Of MachineJob) = PlannedJobsForMachine()

End Sub

Open in new window


I was expecting the Main UI to remain responsive, but I have had reports of the screen "freezing" for a few …
0
I am using visual studio 2019; ASP.Net and VB.Net.  I am trying to open an older project (Web Site) that was developed on an earlier version of Visual Studio (2010).  I have several projects on this and they work.  However, I am trying to use this older version project in this VS 2019 environment and it contains Report Viewer.

Although the Report Viewer has been installed I cannot see the reference for it and I can't see it in the Toolbox nor is it available I the choose items list.

When loading the old folder into the vs environment I get errors - Could not load file and assembly 'Microsoft.ReportViewer.WebForms, Version:15.0.0....

How can I get this to work.  Below is my web config code snippet and you can see the report viewer is installed.

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>
  
    <httpHandlers>
      
      <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </httpHandlers>
    <compilation debug="true" strict="false" explicit="true" 

Open in new window

0
I am trying to upload a file using HttpWebRequest.

The file does not seem to get uploaded.

I don't get any errors.

  Try


            Dim FTPaddress As String = "https://<server>/test/Khaosrs.exe/soap/IKosWeb/" + FileInfo.Name

            Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(FTPaddress), System.Net.HttpWebRequest)
            request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            Dim file() As Byte = System.IO.File.ReadAllBytes(Filelocation)

            Dim strz As System.IO.Stream = request.GetRequestStream()
            strz.Write(file, 0, file.Length)
            strz.Close()
            strz.Dispose()

        Catch ex As Exception
            WritetoEventViewer("CPS - SL Update - UploadFiletoKhaosFTPsite() - " + ex.Message, True)
        End Try
0
Hi,

Convert a format of string from fromat MM-dd-yyyy to dd-MM-yyyy

Thanks
1
I have an Excel add-in firing an HRESULT 0x800401A8 error, when calling the getter of Worksheet.Parent.

I would be glad if anyone could let me know what the error might be, but more importantly and more generally, I would like to know how I can understand these HResult codes?

I did the following but am still confused:

Read the Microsoft's documentation on the Structure of COM error Codes.
Checked this SO thread.
Tried my chances with Magnum DB.

Thanks!
0
We currently have a vb.net application that is connected to a SQL server database through LINQ, table adapters and stored procedures.
For a while now we have been getting a lot of problems with things like double adjustments sale not processing etc - (When a sale is processed for example the stored procedure for the sale are run twice, other times is does not run at all and most of the time the sale is processed correctly, we think this could be caused by deadlocks but we are unsure. When a sale is processed, we sometimes get that the stock has been adjusted incorrectly – double adjustments. These problems are currently occurring at our bigger clients).
Someone has mentioned making use of a transaction manger. The only one that I could find that is compactable with SQL server was Java database Connectivity (JDBC). Are there other transaction manager options we can use?
Or must we fix all the SQL in our application using SQL transactions?
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,