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

OK Greetings..

I have done some searching and I have not quite found the answer to my issue so I guess I will ask the question here. (I'll include code snippets)

(1) I use Visual Studio 2017 express
(2) I Use Visual Basic .NET
(3) I am creating a Windows Application

OK.. I have a ListView Control  contained with a TabControl on a Form... The ListView has a Header of 40 fields and I can populate as many rows as I desire each with 40 fields of data.. (all working).

I need to get each row from the list and output that row data to a .TXT file but NOT All of the fields of data and NOT in the same order as represented in the ListView Header.

I actually have most all of this working EXCEPT my code will output a Duplicate record for the number of records within the ListView control..  Example if I have 3 rows of data and a header record  it will successfully output the desired number of data fields in the desired order for the first row of data then it will REPEAT/DUPLICATE that row of data for the number of rows in the ListView Control and then one more for the Header row.. ie 4 in the current example..

The following code snippet  is what I currently have and need a bit of help. Please note that I load the Header field names into an Array and then use that array
to INDEX into the ROW Item data.

BTW I hope that this is the right way to ask and or present questions to EE.. If not please let me know.
Thanks in advance.

Rick
0
I have this date string:
2018/05/23 22:15:14

I want to subtract 5 hours and return the date time in AM/PM format. But when I do, I get the message:
String was not recognized as a valid DateTime.

I've tried:

                  Dim newdate As DateTime = Now()
                    Dim getDate2 As String = "2018/05/23 22:15:14"

 newdate = DateTime.ParseExact(getDate2, "MM/dd/yyyy HH:mm:ss", Nothing)
and this:
newdate = DateTime.Parse(getDate2)

I was going to do this afterwards to deduct the 5 hours, but I never get that far:
newdate = newdate.Date().AddHours(-5)

I saw a webpage with an example and it has this:
' From w3.org
        time = DateTime.Parse("2009/02/26 18:37:58")

So why is this not a valid datetime?
2018/05/23 22:15:14

thanks!
0
Hi Experts,

I have a report exported to Excel that contains info with headers and details.

looking to write a script that will just obtain all details along with the name portion of the header.

Purpose of this, to export all this into a SQL table.

See example attached.
Untitled.png
0
In vb.net, I have a combobox's "SelectedValue" property bound to a field of a datatable.  When I select an item from the combobox, the SelectedValue gets saved and the ColumnChanged event of the DataTable is triggered; however, when I clear the combobox, neither the SelectValue gets saved to the DataTable nor does the ColumnChanged event get triggered.  How can I get a Null value to be saved to the bound field of the DataTable when the combobox is cleared?
0
Hi. I am using the following VB.net code to convert html in my ASP.net Panel to  a string.
 I then email the result in the body of an email. The problem is that this can be edited.
Can someone suggest a way to make it UNEDITABLE

1:    Protected Sub btnConvertHTML_Click(sender As Object, e As EventArgs) Handles btnConvertHTML.Click
2:        Dim H As String = ""
3:        H = ConvertToHTML()
4:        Me.Label_UsedToTestHtml.Text = H
5:    End Sub
6:
7:    Private Function ConvertToHTML() As String
8:        Dim sb As StringBuilder = New StringBuilder()
9:        Dim tw As StringWriter = New StringWriter(sb)
10:        Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
11:        Panel1.RenderControl(hw)
12:        Dim html = sb.ToString()
13:        Return html
14:    End Function



Select all
 
Open in new window

1:    Public Function xSendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String,
2:                             ByVal cc As String, ByVal subject As String, ByVal body As String,
3:                             ByVal blnUseHTML As Boolean) As String
4:        Try
5:
6:            ' Instantiate a new instance of MailMessage
7:            Dim mMailMessage As New MailMessage()
8:
9:            ' Set the sender address of the mail message
10:            mMailMessage.From = New MailAddress(from)
11:            ' Set the recepient address of the mail message
12:            mMailMessage.To.Add(New …
0
Hi. I am using the following VB.net code to convert html in my ASP.net Panel to  a string.
I then email the result in the body of an email. The problem is that this can be edited.
Is it possibe to rather convert the html into an image and rather email that as the body of the email?

    Protected Sub btnConvertHTML_Click(sender As Object, e As EventArgs) Handles btnConvertHTML.Click
        Dim H As String = ""
        H = ConvertToHTML()
        Me.Label_UsedToTestHtml.Text = H
    End Sub

    Private Function ConvertToHTML() As String
        Dim sb As StringBuilder = New StringBuilder()
        Dim tw As StringWriter = New StringWriter(sb)
        Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
        Panel1.RenderControl(hw)
        Dim html = sb.ToString()
        Return html
    End Function

Open in new window


    Public Function xSendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String,
                             ByVal cc As String, ByVal subject As String, ByVal body As String,
                             ByVal blnUseHTML As Boolean) As String
        Try

            ' Instantiate a new instance of MailMessage
            Dim mMailMessage As New MailMessage()

            ' Set the sender address of the mail message
            mMailMessage.From = New MailAddress(from)
            ' Set the recepient address of the mail message
            mMailMessage.To.Add(New MailAddress(recepient))

            ' Check if the bcc value 

Open in new window

0
In vb.net, I have a multiple user defined classes.  One is named "actextbox" and inherits the windows forms textbox.  Another is a user defined control named "opgTriState".  I want all of these classes to have a property called "acControlSource" that simply Sets and Gets the value of a private string variable.  All of the classes will have the same implementation for this property.  Also, I want all of the classes to have a method called "acBindControl".  In this case, each class needs to have its own implementation.  My questions are:

1.) Is there a way to define the implementation (i.e. set and get) and associated variable for the "acControlSource" property only once for all these classes and somehow have each class inherit the property even though some of the classes are already derived from another class?
2.) How can I define an upper level class that I could CType to it in code to get intellisense for the "acBindControl" method but that would call the appropriate implementation for the specific (derived) class when invoked even though some of the classes are already derived from another class?

Here is my code so far so you get the idea of what I'm trying to accomplish (note: there will eventually be more classes.  I'm trying to get rid of the case statement and put the specific data binding implementation within the classes:

        Dim cntrlType As Type
        Dim strControlSource As String
        Dim propInfo As PropertyInfo

        For Each cntrl As

Open in new window

0
Hi

Really scratching my head over this...I run the code below using the sql in the routine and I get a different recordset than if I run it directly on the database. The database and path is correct so how can this be?


Dim MDBConnString_ As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\ADATABASE.accdb;"
        Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_)
        cnn.Open()

 'run delivery charges summary - Daily D Charges 2
        Dim query10 As String = "SELECT [Daily Charges 1].chargec, Sum([Daily Charges 1].tot) AS SumOftot FROM [Daily Charges 1] GROUP BY [Daily Charges 1].chargec ORDER BY [Daily Charges 1].chargec;"


        Dim cmd10 As New OleDbCommand(query10, cnn)
        Dim TheDataReader10 As OleDbDataReader = cmd10.ExecuteReader()
        Dim dtot As Double = 0
        While TheDataReader10.Read()
            theBody = theBody & " <tr>"
            theBody = theBody & " <td style=""background-color: #7FFFD4;"">" & TheDataReader10("chargec") & " </td>"
            theBody = theBody & " <td style=""text-align: center;background-color: #AFEEEE;"">£" & TheDataReader10("SumOftot") & " </td>"
            dtot = dtot + TheDataReader10("SumOftot")
            theBody = theBody & " <td><br>"
            theBody = theBody & " </tr>"
        End While
        TheDataReader10.Close()

Open in new window



Result from above

Del 	                £0 
MWAVE 10p 	£0 
MWAVE14.5 	£0 
PALLET 	        £65.25 
PICK 	        £349.38 
Slip_Sheet 	£0 
SWRAP 	        £65.24 

Open in new window



Result from Query run directly on the MSAccess database.

chargec	SumOftot
Del	                     0
HBALL	             552.3
Label	             394.5
MVAVE	             1242.766
MW+UP .106p    4345.3803519
MWAVE 10p	     127.5
MWAVE 11p	     2906.77630397
MWAVE 12p	     2700
MWAVE 13.5p    3977.1
MWAVE14.5	     0
PALLET	             3798.75
PICK	             9810.11
Slip_Sheet	     0
SWRAP	             2076.95
TEMP	             72
TEMP_KG	     242

Open in new window


Many Thanks

Robert Bee
0
Hi

In ASP.net VB.net I am sending an email with html embedded in the body.
Is it possible to include something in that html that if clicked on will print the
body of the message?
0
Hi

In my ASP.net web app I am using the following code to convert all the html in a panel
into a string that I then email. It works well  except for the image. How do I include an image in this sort of convdersion?
I have put the markup for the panel below

    Private Function ConvertToHTML() As String
        Dim sb As StringBuilder = New StringBuilder()
        Dim tw As StringWriter = New StringWriter(sb)
        Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
        Panel1.RenderControl(hw)
        Dim html = sb.ToString()
        Return html
    End Function

Open in new window


        <asp:Panel ID="Panel1" runat="server" Height="520px">
            
                <table>
                    <tr>
                        <td><asp:Label ID="lblBuyerCompanyName" runat="server" Font-Size="X-Large"></asp:Label></td>
                        <td></td>
                        <td><asp:Label ID="lblSpacer" runat="server" Width="100px"></asp:Label></td>
                        <td><asp:Label ID="Label21" runat="server" Font-Bold="True" Text="PURCHASE ORDER" Font-Size="X-Large"></asp:Label></td>           
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td><asp:Image ID="Image1" runat="server" Height="110px" Width="209px" /></td>
                        <td></td>
                        <td></td>
                        <td></td>
        

Open in new window

0
Hi. I want to use the type of VB.net code below to contruct the Purchase Order shown further on. This is for the body of an email.
As you can see I have used an html table for spacing. How should I approach this? Is there perhaps a better way to do this without a table?

            Dim oHBody As String = ""
            oHBody = oHBody & "<html><body><font size=3  color=" & sColor1 & " name = 'Calibri'>" & oIntro & "</font></body></html>"
            oHBody = oHBody & "<br>"
            oHBody = oHBody & "<html><body><font size=3  color=" & sColor2 & " name = 'Calibri'>" & sDate & "</font></body></html>"
            oHBody = oHBody & "<br>"

Open in new window


Design View
   <table>
                    <tr>
                        <td>
                            <asp:Label ID="lblBuyerCompanyName" runat="server" Font-Size="X-Large"></asp:Label>
                        </td>
                        <td></td>
                         <td>
                             <asp:Label ID="lblSpacer" runat="server" Width="100px"></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="Label21" runat="server" Font-Bold="True" Text="PURCHASE ORDER" Font-Size="X-Large"></asp:Label>
                        </td>
                   
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                       <tr>
                        <td>

Open in new window

0
Hi

In my ASP.net VB.net code the third line causes an error "Thread was being aborted". What does this mean?

               Session("oMessageFromEmail") = oUsername
               Session("oMessageToEmail") = xSellerUsername
               Response.Redirect("Message")

Open in new window

0
Hi

In Visual Studio ASP.net what is the difference between Debug and Release mode?

Thanks
0
Hi

I have the following ASP.net GridView button. On other pages it work but for some reason it isn't firing on this one page
I have included my markup and VB.net below

           <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False">
                    
                     
                     <Columns>
             
                 <asp:TemplateField HeaderText="?" ControlStyle-Forecolor ="Gray">
                    <ItemTemplate>
                        <asp:Button ID="ButtonQuestion" OnClientClick="showLoading();" runat="server" 
                        CommandName="btnQuestion" 
                        CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>"
                        Text="?" />
                    </ItemTemplate>
                    <ControlStyle ForeColor="#468499" />
                </asp:TemplateField>

Open in new window


            ElseIf (e.CommandName = "btnQuestion") Then

                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                ' Retrieve the row that contains the button 
                ' from the Rows collection.
                Dim row As GridViewRow = GridView1.Rows(index)

                If IsPostBack Then

                    Dim lblItemID As Label = CType(row.FindControl("lblItemID"), Label)
                    Dim lblOrderQty As Label = 

Open in new window

0
I am looking for VB.NET function to check if a string is starting with anything between 500 to 599
 

Example strings
   523 Doc1
   Doc1
   5002Doc2
   Document523SubDoc
   522-Doc3

The valid strings from the above are
   523 Doc1
   522-Doc3
0
Dealing with Locked Tables during debugging

I am tracking down an obscure bug which MAY be in the VB code or MAY be in any number of stored procedures and PROBABLYinvolves the delicate inter-dependency each has on the other.

So, while I am stepping through the VB code, I query the database and see the values before and after each step. But, just when I REALLY need to run the query, the table is locked (by the executing code). After the table is closed and the transactions are committed, only then can I run the query, but by then, it's too late. The error reveals itself and I had no way to see what was on the  database.

Suggestions?

It would be awesome if I could set up a mirrored database that I could query to my heart's content. Is that an extreme idea?

I think I am going to need just such an extreme idea to do this...

Does SQL Server 2017 provide me anything I could do here? Ae there any kind of log files where these transactions can be viewed, even when the table is locked?

Maybe Visual Studio is the problem and I could benefit from getting a log of all data tables changes without even stepping through the code. Is there an SSIS feature or SQL Server feature that could output all DB changes for each table into a text file, for example? Then, I could scan it and see when the error showed up in the data.

Thanks
0
Hi

In ASP.net I want a user to push a button on a website that runs code that sends the
web page as a pdf attachment, What VB.net code would I use to do this?
0
How do you open an audio file (mp3, wav, etc.) and get the length of the file in seconds using WMPLib.WindowsMediaPlayer with Visual Basic 2015?
0
Trying to take a json file and upload into a database. First I'm setting up properties to capture the data. This is where I'm stuck at the moment. I have property arrays within property arrays that is returning nothing. not sure what I'm doing wrong. Never worked with a json file before. If you look at the attached text file, Precautions is returning nothing. the file is much larger just working with a chunk at a time. Can someone show me why Precautions data is not returning?
Here is the code so far. Got the form load code from searching. Forgot where to give credit.

Public Class Form2
    Private _desktop As String =
        Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim filePath As String =
            IO.Path.Combine(_desktop, "UploadFile.txt")

        Dim data As Upload =
            JsonConvert.DeserializeObject(Of Upload)(IO.File.ReadAllText(filePath))

        Stop

    End Sub

    Public Class Upload
        Public Property Item As String
        Public Property norm As String
        Public Property primaryimage As PrimaryImage()
        Public Property Secondaryimages As secondaryImages()
        Public Property description As String
        Public Property notes As Notes()
        Public Property Precaution As Precautions()
    End Class

    Public Class Precautions
        Public Property Warnings As Warnings()
        Public Property 

Open in new window

0
Hi,

I have this rest api request that returns a boolean value. Initially this value is always set to false but will turn to true within seconds (or up to a minute) . I need to do re-do or poll the request until the status of the value has changed from false to true and then, of course, stop the request(s) and continue.

What kind of methods can I use to make this happen.

Grateful for help and example code.

Peter
0
Hi Experts,

I have a function that does as follows.

Opens a given CSV file, reads in a loop each line of the file and uploads data to a web site.

I have an error procedure that whenever it returns in error (usually from that web site) it keeps a log of that error and moves on to process the next line.

Error procedure below.
ExitImportDataToCaspio:
    Close #1
    Set db = Nothing

    Exit Function
Err_Proc:
    s = "Insert into API_Errors(ErrorMessage,TableName, [TableID],FileName, ValuesSent) Values ('" & Err.Number & "--" & Err.Description & "','" & sTable & "'," & Nz(pk, "") & ",'" & sFile & "','') "
    CurrentDb.Execute s
    Select Case Err.Number
        Case 9
            '' display a message if you want
           Resume Next  '''' assuming you want to just pick up at the statement after the error
        Case Else
'            MsgBox Err.Number & "--" & Err.Description, vbOKOnly
'            Resume ExitImportDataToCaspio
            Resume Next
    End Select
End Function

Open in new window


Now would like to modify that as follows.

Have a table store some errors, in case this error is one of those, it should (instead of processing the next line) try one more time to process the current line.

For detailed description of the function see this..

Thanks
0
In vb.net, I have a procedure declaration ...

        Private Sub SetSqlDataAdapter(ByRef da As SqlDataAdapter, strTableName As String)

And a call to it ...

        dap1 = New SqlDataAdapter(cmd1)
        Call SetSqlDataAdapter(dap1, "Returns")

dap1 is declared globally in the Form Class  ...

        Dim dap1 As New SqlDataAdapter

Why am I getting the exception "Object reference not set to an instance of an object" on the line that calls the procedure?
0
In vb.net, I'm utilizing the SQLDataReader's GetSchemaTable method to get column names and other properties of each column in order to define a custom function to add parameters for the Update, Insert and Delete commands of a SQLDataAdapter so I don't have to manually write a line of code to create a parameter for each column.  The schema table's "DataTypeName" column tells me the datatype, but how do I convert a string such as "int" to an enumeration such as "SqlDbType.Int".  Suppose I have a string variable strDataType = "int" and I have a line of code ...
Dim prm1 As SqlParameter = dap1.UpdateCommand.Parameters.Add("@ReturnId", SqlDbType.Int)

How do I convert "int" to the value of SqlDbType.int?    Parameters.Add("@ReturnId", SqlDbType(strDataType)) doesn't work.
0
Hi,

I need some help with a request in vb.net. In postman I've succeded to get it to work and I've added the screenshots below
Postman 1Postman 2Postman 3

Now I've used Restsharp (but any request will do) to try and connect through code:

 Dim username As String = "xxx"
        Dim password As String = "xxx"
        Dim client As RestClient = New RestClient("https://url")
        client.Authenticator = New HttpBasicAuthenticator(username, password)
        Dim request = New RestRequest(Method.POST)
        request.AddHeader("Postman-Token", "fa4aa5a9-0c7a-45ad-a8b1-24fd0ac75f8c")
        request.AddHeader("cache-control", "no-cache")
        request.AddHeader("api-version", "1")
        request.AddHeader("Authorization", "Basic xxx")
        request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
        Dim response As IRestResponse = client.Execute(request)

Open in new window


However I get this answer:
{"error":"unsupported_grant_type"}
0
Using VB.NET I am filling in a one <input> element.  That element isn't part of a form... it is part of Ajax.

Upon entering text into the input element and hitting the Enter key Ajax posts the contents of the form to another page.

How can I do this using VB.NET.

If the data that I am entering into the input element is appending with Chr(13) or Chr(10) this doesn't help.
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,