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

Hi all, after select data from a combobx and save
i want to make it readonly as a textbox,
i only find the option enabled=false for achive that but the text is so blur
how to made a combobox read only
regards!
0
So I added the references here...
http://vb.net-informations.com/files/create-pdf.htm
For creating a PDF document in vb.net.  This works fine, but in my code, I don't know how to start a new line.  I tried using Evironment.NewLine, but it doesn't advance beyond the first line of text.  I'm sure the issue is that I can't keep using "TopLeft", but I can't figure out how to write multiple lines to the page.  Here's my code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim pdf As PdfDocument = New PdfDocument
        pdf.Info.Title = "Renewal Report"
        Dim pdfPage As PdfPage = pdf.AddPage
        Dim graph As XGraphics = XGraphics.FromPdfPage(pdfPage)
        Dim font As XFont = New XFont("Consolas", 20, XFontStyle.Regular)
        '// Writing first line
        graph.DrawString("First Line of Document", font, XBrushes.Black,
        New XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
        '// Trying to add new line
        graph.DrawString(Environment.NewLine, font, XBrushes.Black,
        New XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
        '// Trying to write second line
        graph.DrawString("Second Line of Document", font, XBrushes.Black,
        New XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
        Dim pdfFilename As String = "firstpage.pdf"
        pdf.Save(pdfFilename)
        

Open in new window

0
Troubleshooting a piece of code.
            Dim web As Net.WebClient = New Net.WebClient()
            Dim html As String = web.DownloadString("https://www.google.com/finance/converter?a=1&from=EUR&to=USD")
            Dim m1 As Match = Regex.Match(html, "<span class=bld>\s*(.+?)\s*</span>", RegexOptions.Singleline)
            Dim currency As String = m1.Groups(1).Value.Replace("USD", "")

            user.setEuro(Convert.ToDouble(currency))

Open in new window

currency is blank.  

My question is what does "<span class=bld>\s*(.+?)\s*</span>", RegexOptions.Singleline" do?
0
Hi,

How do I prevent users from resizing a Form by dragging its border using VB.NET?

Kind regards,

Victor
0
Hi,



I have two tables created from 2 xml files which are linked by the NSC column, How do I create a new table with data from table2 by merging data from table2 to table1, where the fields from table2 are included in table1, for example if table1 contains

NSC:   F1                            F2

1         AGD, AGD1            AGD

2        AGD                        AGD, AGD1



table2 contains:

NSC:   AGD   AGD1

1         XXX    YYY

2        ZZZ    WWW



How do I create table3?



NSC:   F1                            F2

1         XXX;YYY                XXX

2        XXX                        XXX;YYY


Thanks,

Victor
0
An employee is filling leave application form, mentions leave start date and end date. I have following on my .aspx form :

 
Label(Leave starts Date), text box, calendar extender (with format set to dd/mm/yyyy), required field validator


Label(Leave End Date), text box, calendar extender (with format set to dd/mm/yyyy), required field validator

Compare Validator
to ensure Start Date is not less than end date.



      <div class="form-group">
            <label>Leave starts Date</label>
            <asp:TextBox runat="server" ID="txtDurationFrom" CssClass="form-control" AutoPostBack="true" />
            <cc1:CalendarExtender ID="txtDurationFrom_CalendarExtender" runat="server" TargetControlID="txtDurationFrom"  Format="dd/MM/yyyy" > 
            </cc1:CalendarExtender>

            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Starting Date of Leave Period" ControlToValidate="txtDurationFrom" >
            </asp:RequiredFieldValidator>
 

            <label>Leave End Date</label>
            <asp:TextBox runat="server" ID="txtDurationTo" CssClass="form-control" AutoPostBack="true" />
            <cc1:CalendarExtender ID="txtDurationTo_CalendarExtender" runat="server" Enabled="True"
            TargetControlID="txtDurationTo" Format="dd/MM/yyyy" >
            </cc1:CalendarExtender>

            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter Last Date of Leave Period"
            ControlToValidate="txtDurationTo">
            </asp:RequiredFieldValidator>
   
 
            <asp:CompareValidator  …
0
How to display the size of tblmountertrace_1 (to) 9 to text box? Please see picture:

database table
Im using this code but I dont know how to query. I put it on the Timer (timSERVERSIZE) to update every 4 Hours a day.

        Private Sub timSERVERSIZE_Tick(sender As Object, e As EventArgs) Handles timSERVERSIZE.Tick
        Dim cmd2 As New MySqlCommand
        Dim myDA2 As New MySqlDataAdapter(cmd2)
        Dim myDT2 As New DataTable
        cmd2.Connection = conn
        cmd2.CommandText = "SELECT * FROM esd_reco ?????????????????????????????????????"
        myDA2.Fill(myDT2)
        TextBox1.items.add(myDA2)  <<<<<<<<<<<<??????????????????????????


    End Sub

Open in new window


Thanks for the help
0
I have an aspx page that runs a stored proc. The stored proc returns a value ( a record ID) after performing a few insert statements.  I want to get that return value with vb code.  My current code (see * below) gets an error message: "Input string was not in a correct format."  I can't find the right code to get the return value.  What is the flaw(s) in my code?

Thanks for looking.

The stored proc:
CREATE PROCEDURE [dbo].[CreateEval]
	    @EmployeeNumber int
	  , @EmpLastName varchar(30)
	  , @EmpFirstName varchar(30)
	  , @EmpDepartmentID int
	  , @EmpJobTitleID int
	  , @SupervisorID int
	  , @SupLastName varchar(30)
	  , @SupFirstName varchar(30)
	  , @SupervisorDeptID int
	  , @SupervisorTitleID int
	  , @EvalID int = NULL OUTPUT
AS

BEGIN
	/*some inserting happens here		
END

BEGIN
	/*some inserting happens here		
END

BEGIN
	INSERT INTO EvalHeader
		(EmployeeNumber
	   , SupervisorID
	   , EvalDate)
	VALUES (@EmployeeNumber
		  , @SupervisorID
		  , GETDATE())
	SET @EvalID = SCOPE_IDENTITY()
	
	INSERT INTO EvalScoring
		(EvalID)
	VALUES (@EvalID)
	RETURN 
END

Open in new window


Here is the sql data source:
<asp:SqlDataSource ID="dsCreateEval" runat="server" ConnectionString="<%$ ConnectionStrings:EmpEval_TestConnectionString %>" SelectCommand="CreateEval" SelectCommandType="StoredProcedure"
        InsertCommand="CreateEval"
        InsertCommandType="StoredProcedure">
        <InsertParameters>
            
            <asp:ControlParameter 

Open in new window

0
I want to use the following C# code in a VB program.  How would I convert this?  The first line seems to just be a matter or removing the semicolon, but I can't test it since I am unable to figure out the second line.
textbox1.Select( textbox1.GetFirstCharIndexFromLine( 0 ), textbox1.GetFirstCharIndexFromLine( 1 ) - textbox1.GetFirstCharIndexFromLine( 0 ) );
textbox1.SelectionFont = new System.Drawing.Font( "Tahoma", 10, FontStyle.Bold );

Open in new window

0
how do i create a string variable with a date like this MMDDCCYY?

I am going to use that to name a field later
0
Hello,
How can I Draw line from datagridview1 cell to another datagridview2 cell.
Just want to show a connection.
I am using vb.net desktop.

Thanks
0
Hi,
I have two tables, Table1 and table2, with the same structure, and same keys (D1, D2 ...). Is possible to sum and copy automatically values to a third table.
Attached image with exemple.

best regards
vb.net
Img9.png
0
What is the best way to take a string (let's say 99900) and string it so it equals 999.00 ?  format for some reason I am struggling with..  I think I am overthinking it but looking for other ideas.


CInt(node.SelectSingleNode("FineAmount").InnerText.Trim().ToString("D"))

I have also tried variants to string.format() seems to not add the decimal.  

Thanks in advance!
0
I have a text file with data that I want to output to a report.  I was thinking of using ReportViewer, but I can't find it in my Visual Studio and I'm thinking ReportViewer is overkill for what I'm looking to do.  I plan on creating the columns by just placing them on the report and padding with spaces (see image below).  For example, I decided on 20 characters for the Expiration Date, so if the date is 10 characters in length, then I will insert 10 spaces after the date.

I have a comment field that comes after each entry so I think that will cancel out the use of a grid.  I thought about putting a multiline textbox on a form, but the report could run 3 or 4 pages long and I want to be able to print it.  What would be the easiest way to output my data to a report?
Report Document
0
Coding: VB.net 2013 / Windows 7 64-bit
Camera: Logitech HD Pro Webcam C920 (Full HD 1080p video calling (up to 1920 x 1080 pixels))

I have an app that I want to simply trigger the camera to take a still, high quality photo and store the image with a file name I will provide automatically.   I would also like to display an image on the screen so they know the product being photographed is lined up under the camera.

All the code I find online seems to be a variation of this code:  

While this code does take a picture, the quality is worse than a cheap kids camera.    So for some reason it does not use the full capability of the camera to take a quality picture.  I want to be able to zoom in on the picture to make out the writing.

Is there some way in the code I can force the camera to take a higher quality picture?

If not, is there some low cost VB.net add-in that could be used to acheive this?

Is there a low cost non-webcam digital camera that can be mounted and can connect via UBS and be controlled by vb.net to take HQ photos?

I have attached the picture I took.   In the middle of the picture there is a tan cut out of a magazine article.  When I zoom in on the photo it is all pixelated and you cannot make out any words.

Thanks
TestWebCam_Net.jpg
0
Hi,

I have a service that used a FileSystemWatcher to monitor a directory waiting for XML files to be posted from on-site scanners and then it is to process them appropriately. The files are generated from the scanners via a PHP script to post the files into the directory being watched.

There is an issue in this application that occasionally it posts a zero-byte file that I have to detect and then delete as the file is useless. I have coded this, but it has exposed another issue that I now need to address.

Sometimes the FileSystemWatcher detects and attempts to grab the file before the post from the scanner is complete. I have added a loop to wait on the service being able to open the file with exclusive access which I thought would mean that the post was complete (assuming the file would remain locked until it was fully written). However, this occasionally appears not to be the case. On the odd occasion my loop appears to be getting exclusive access to the file (about 1% of the time) before it should (in my mind), and is detecting the file as zero-byte as the write has not completed. It then proceeds to try to delete the file, which fails as the writing process seems to again have taken out a lock on the file.

My question is, what is the best way to wait on exclusive access to a file and to be 100% sure that the writing process has finished with the file??

A snippet from my code is below (detectedFilename comes in as a parameter):

        Dim 

Open in new window

0
Hi,

I recently had to move one of out sites from one platfrom to another (both asp.net). Now I'm getting these kind of errors all the time:

Error in: http://mediapaket.se/webresource.axd
Error Message: This is an invalid webresource request.
Stack Trace:
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  

Open in new window

Error in: http://www.kanal10forlag.se/ScriptResource.axd?d=dUrVbIn2q3VgM_eY2_dVougHVl9VgISMOVdWGnrEsIZQBUmppUJ96sn8eE3KBWoIfQ4YF7XUTdPSSOD1ZrCo4oMa7MK6NKewcQj4Z63N0Fkfl0CYAUwR5Th9MGa52vuMi5L0dVyveDbHwaVjgwGtz_UkI8ldkmnZT15lnNw4jl81&t=ffffffffa8d92b60
Error Message: This is an invalid script resource request.
Stack Trace:
at System.Web.Handlers.ScriptResourceHandler.Throw404() at System.Web.Handlers.ScriptResourceHandler.ProcessRequest(HttpContextBase context, VirtualFileReader fileReader, Action`2 logAction, Boolean validatePath) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  

Open in new window


Why do I get these kind of errors and how can I fix them?

Thanks for help!

Peter
0
I have the following code, which I haven't tested thoroughly yet, but so far it seems to work well.  I'm wondering if the Try...Catch statement that I have is sufficient for error handling?

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim strArrayDate As String          '// Date of entries already in the file
        Dim strNewItemDate As String = expirationDate.Value.ToShortDateString '// Date of item being added
        Dim boolInsertionPoint As Boolean = False '// Determine if location for new item was found
        Dim delim As String = Chr(149)      '// Delimiter character
        Dim i As Integer = 0                '// line counter
        '// Backup file
        Try
            My.Computer.FileSystem.CopyFile("\\server\folder\Renewals\renewals.db", "\\server\folder\Renewals\renewals" + (Date.Now.ToShortDateString).Replace("/", "-") + ".bkp", overwrite:=True)
            '// Input file into array
            Dim lines() As String = IO.File.ReadAllLines("\\server\folder\Renewals\renewals.db")

            If strComment.Text = "Enter comments here" Then strComment.Text = "No comments added"

            '// Add each item back to the file, inserting new item in proper place
            For Each line As String In lines
                strArrayDate = lines(i).Split(Chr(149))(0)      '// Get date of entry being examined
                '// Find where new item should be inserted
                If CDate(strNewItemDate) < 

Open in new window

1
Hi I have used telerik to convert code but getting error, please help

this is the c# version:
System.Xml.XmlElement[] headers = doc.DocumentElement.ChildNodes.Cast<XmlElement>().ToArray<XmlElement>();

Open in new window

       
this is the vb converted version:
Dim headers As System.Xml.XmlElement() = doc.DocumentElement.ChildNodes.Cast(Of XmlElement)().ToArray(Of XmlElement)()

Open in new window


the error message is

Error      109      Extension method 'Public Function ToArray() As TSource()' defined in 'System.Linq.Enumerable' is not generic (or has no free type parameters) and so cannot have type arguments.

I have the: Imports System.Linq
0
I have finally ordered my Murach's Visual Basic 2015 book. So hopefully it will help me with learning VB.NET. However, I have some controls, two text box controls that are used to input hours and minutes. In the grid we have it set that when the data is an expense we disable the time textbox controls. However, the validation remains in effect. What I am hoping to accomplish is when in edit mode and the control is disabled to not attempt validation. I'm a little confused as to how to go about this when in edit mode.
0
I am using vb.net trying to send an email,   the following is my code

        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("username@gmail.com", "myPass")
           
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"            

            e_mail = New MailMessage()
            e_mail.From = New MailAddress(Txt_FromEmail.Text)
            e_mail.To.Add(Txt_ToEmail.Text)
            e_mail.Subject = "Email Sending For test"
            e_mail.IsBodyHtml = False
            e_mail.Body = Txt_Message.Text
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")

        Catch error_t As Exception
            TextBox1.Text = error_t.ToString
        End Try

and I am getting the following error


System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
   at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)
   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String …
0
Hi.  Do you know how I can translate the .vbs to vb.net for SSIS 2008?   There’s a lot of logic in the .vbs files so I am concerned about not translating it right.   Please provide specific examples of a .vbs and the end result SSIS .dtsx package so I can follow, not just guidelines.

I am using:
-  Visual Studio 2008
- SQL SERVER 2008R2
0
Hello,

I'm trying to change multiple  panel back color depends on data from database,
the data comes from list called mylist  it have a strings with true and false,
so i need to change the back color of panels depends on that data , so if mylist(1) = true i want the back color is green:
this is what i tried  :

Dim p As List(Of Panel) = Me.Controls.OfType(Of Panel).ToList
        For i As Integer = 1 To duration
            If myList(i) = True Then
                p(i).BackColor = Color.SpringGreen
            End If
        Next

Open in new window


but its not working.
0
Hello,
I have code  which replaces the merge field.I need to replace with backspace.How can i achieve this .
Any suggestions are appreciated.
 oDoc.Content.Find.Execute(FindText:="«Date4»",
                       ReplaceWith:=Str_Date, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)

Open in new window


Cheers
0
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
int main()
{
    int pictureLength, pictureWidth, pictureSquareInchSize, picturePerimiter, numberOfStars;
    char frameType;
    string frameColour;
    float totalPrice;
   
    //values below represent cost per inch
    const float FRAME_COLOURING_PRICE = 0.10;
    const float REGULAR_FRAME_PRICE = 0.15;
    const float FANCY_FRAME_PRICE = 0.25;
   
    //values below represent cost per square inch
    const float CARDBOARD_PRICE = 0.02;
    const float GLASS_PRICE = 0.07;
   
    const float STARS_PRICE = 0.35;
   
    cout << "Please enter the length & width of the picture: ";
    cin >> pictureLength >> pictureWidth;
    pictureSquareInchSize = pictureLength * pictureWidth;
    picturePerimiter = (pictureLength * 2) + (pictureWidth * 2);
    cout << "Please select your frame type (r for regular & f for fancy): ";
    cin >> frameType;
   
    // Calculate cost of the frame type
    switch (frameType) {
        case 'r':
        case 'R':
            totalPrice = picturePerimiter * REGULAR_FRAME_PRICE;
            break;
        case 'f':
        case 'F':
            totalPrice = picturePerimiter * FANCY_FRAME_PRICE;
            break;
        default:
            cout << "You entered an invalid fram type" << endl;
            return 1;
            break;
    }
   
    cout << "Please enter which colour frame you would like (Note: white is …
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,