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 ant to declare a variable in the following code used with an API but
I get an error showing that the variable is hidden in an encclosong blocck


If Hosting.HostingEnvironment.IsDevelopmentEnvironment Then
                Dim myxeroconsumer As New Consumer("xxx", "yyyy")
            Else
                Dim myxeroconsumer As New Consumer("gggg", "jjjjj")
            End If
0
OWASP Proactive Controls
LVL 13
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

I want to practice vb.net by creating a few applications.  I can't seem to find a free download that when i download contains vb.net. Where can i go to download this?
0
Hi. When I select an item in my ASP.net DropDownList I don't see the value in the variable P below
Also after the section the DropDownList text is  blank. What might cause this

    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged


        Dim P As String = Me.DropDownList1.Text

    End Sub
0
Hi
I currently use the following connection string in my VB.net code to connect to a local database
Server=(localdb)\MSSQLLocalDB;Integrated Security=true
What connection string would I use to connect to the local database shown in the following image
Image1.jpg
0
Hi

I am using my local host to authenticate into the Xero API

Dim myxerocallbackurl = "https://localhost:51970/Default.aspx"

but am getting the following error

oauth_problem=parameter_rejected&oauth_problem_advice=Callback%20url%20is%20not%20in%20the%20registered%20callback%20domain

what are the possible causes? In my Xero app do I have to specify the local host?
0
Hi all.

I have a checkedlistbox that I populate via the code below. I also added a ContextMenuStrip that when the end user right clicks a row (regardless if it's checked or not) I want to be able to edit the text. To do this I need to get the SelectedValue but unfortunately with the code below, the SelectedValue (i.e. StepID) is blank.

What am I doing wrong? Thank you in advance.

Private Sub LoadSteps()
CheckedListBox_OpportunitySteps.Items.Clear()

        Dim con As New SqlConnection
        Dim cmd As New SqlCommand

        con.ConnectionString = "Data Source=myserver;Initial Catalog=mydatabase;Integrated Security=True"

        con.Open()

        cmd.Connection = con

        cmd.CommandText = "SELECT Step, Completed, StepID FROM CRMOpportunitySteps WHERE OpportunityID = @OpportunityID ORDER BY StepID"
        cmd.Parameters.AddWithValue("@OpportunityID", opportunityID)

        Dim sda As New SqlDataAdapter(cmd)
        Dim dt As New DataTable()

        sda.Fill(dt)

        CheckedListBox_OpportunitySteps.DisplayMember = "Step"
CheckedListBox_OpportunitySteps.ValueMember = "StepID"

If dt.Rows.Count > 0 Then
            For i As Integer = 0 To dt.Rows.Count - 1
 CheckedListBox_OpportunitySteps.Items.Add(CStr(dt.Rows(i).Item(0)), dt.Rows(i).Item(1))

            Next
 End If
    End Sub

Private Sub EditToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditToolStripMenuItem.Click

        
        Dim itm As String

        itm = 

Open in new window

0
I am having issues trying to populate a datagrid that has predefined columns. The array is 46 in length and I am trying to populate each row with the right information.

I have the code below but it only populates the first first and the first 3 cells. In the 4th cell I do have a combox, could this be what is holding it up?

  ArrayGWHIZModel = strDataCOM1.Split(New Char() {Chr(13)}, StringSplitOptions.RemoveEmptyEntries)
                    If ArrayGWHIZModel.Length = 46 Then
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), True, ArrayGWHIZModel(3), True, ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), ArrayGWHIZModel(2), ArrayGWHIZModel(3), ArrayGWHIZModel(4), ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), ArrayGWHIZModel(2), ArrayGWHIZModel(3), ArrayGWHIZModel(4), ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        'DataGridView1.Rows.Add(ArrayGWHIZModel(0), ArrayGWHIZModel(1), ArrayGWHIZModel(2), ArrayGWHIZModel(3), ArrayGWHIZModel(4), ArrayGWHIZModel(5), ArrayGWHIZModel(6), ArrayGWHIZModel(7), ArrayGWHIZModel(8), ArrayGWHIZModel(9))
                        

Open in new window

0
Greetings:

I am quite confused as to what I can do and what I cannot do within the UploadComplete event of the AjaxFileUpload control.

There are 2 ASPX Label controls which are assigned values within the UploadComplete event, however, the assigned values do not appear on the page after the event completes. The uploaded file is saved to the designated directory, however.

I'm including the ASPX, the VB code behind and the web.config files as follows:

ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<div>

			<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

			<asp:Label ID="Label1" runat="server"></asp:Label>

			<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpeg,jpg,gif" />

			<asp:Label ID="Label2" runat="server"></asp:Label>

		</div>
	</form>
</body>
</html>

Open in new window

VB Code Behind
Imports AjaxControlToolkit

Partial Class _Default
	Inherits System.Web.UI.Page

	Private Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete

		Label1.Text = "Here we are 1."

		AjaxFileUpload1.SaveAs("C:\inetpub\ClientWebs\AjaxFileUploadSync\Images\" & e.FileName)

		Label2.Text = "Here we are 2."

	End Sub

End Class

Open in new window

web.config
<?xml version="1.0" encoding="utf-8"?>

<configuration>

	<system.web>
		<compilation debug="true" targetFramework="4.0" />
	<pages>
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages></system.web>

	<system.webServer>

		<handlers>

			<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />

		</handlers>

	</system.webServer>
</configuration>

Open in new window

Any assistance you might provide would be most helpful.


Much thanks,
David Bach
0
Hi.  There are times when DNS and a PC name do not match, and can determine this with PING -a, for example, I ping Computer 1 and returns an IP address, then PING -a the IP address and find the IP is associated with Computer2. I once wrote a simple batch that pinged the PC by name, captured the IP, then PING -a and if the PC names don't match, there's a conflict. That worked well.

Is there an elegant way to do this type of verification in VB.net?   I have an app that depends on connectivity to a remote PC host (on an AD domain), but it fails if there's a DNS conflict.  I'd like to verify there's an actual DNS issue in VB, instead of calling on CMD to check.
0
Hello. I am a newbie to programming. I'm working on a web form in asp.net. So my files are set up so that I have a Master page and aspx pages that look like this.
<%@ Page Title="" Language="VB" MasterPageFile="~/Layout.master" AutoEventWireup="false" CodeFile="delete.aspx.vb" Inherits="Appointment_Online_delete" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="wide" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

Open in new window



   I have everything built.  But on the form I want a collapsible panel.  I've tried all the basic tricks I know and nothing works.  I have no problem doing this on a page with only 1 button but this page will have 2.  One button to submit the form and the other button to expand a content div or panel.  No matter what I've tried when I click the button to expand the panel or div it doesn't do anything but jump to the top of the page and trigger all my form validators.  It seems like it tries to submit the form also.   Like I said, I've tried several different way to do it but this is the way I would like to do it if I can get it to work.

Here is the panel
<asp:Panel id="pnlfaq_content" runat="server" Visible="false">

Open in new window

As you see I start off with the visibility of false because I want the user to click the button to see the FAQ information.

This is my button.  I've tried different types of buttons but I think a asp linkbutton is what I need. Let me know if there is something better.
<asp:LinkButton ID="btnFAQ" runat="server" onclick="btnFAQ_Click" CssClass="btn b_g" Style="width: 80px;"><span>FAQ</span></asp:LinkButton>

Open in new window


I was hoping it would be so simple as to just add this in my code file .aspx.vb
Protected Sub btnFAQ_Click(sender As Object, e As EventArgs) Handles btnFAQ.Click
        pnlfaq_content.Visible = True
    End Sub

Open in new window

But this doesn't work.  It only sends to focus to the top of the page and triggers my form validators as if I was submitting the form.  

I would like some help in how to make this work.   Thank you.
0
Python 3 Fundamentals
LVL 13
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

VB .net creating mailitem via Microsoft.Office.Interop works for me but not others ??

They get the error...
System.BadImageFormatException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

I've already tried Target x86 in the compile options with no luck.
I've tried 2 ways of adding the Reference....

1. Add Reference/COM
2. Add via Nuget PM > Install-Package Microsoft.Office.Interop.Outlook -Version 15.0.4797.1003 (with Embed Interop Types = True)

All variations work on my machine (64 bit Win10 Administrator accounts) but not others (also 64 bit Win10 Administrator accounts)

When adding reference via COM and i check the properties i have an Identity = {00062FFF-0000-0000-C000-000000000046}\9.6\0\primary so I'm also wondering if this is a clue as the error is reported on 0006F03A-0000-0000-C000-000000000046 ??

All help appreciated
0
Hi

I am getting the following error "oShaft      Cannot obtain value of the local variable or argument because it is not available at this instruction pointer, possibly because it has been optimized away"
There are three rows of data in the GridView. I have included the html for the GridView below.


            Dim oGridView As GridView = Me.GridViewData
           Dim oGridViewRow As GridViewRow
            For i As Integer = 0 To oGridView.Rows.Count - 1

                oGridViewRow = GridViewData.Rows(i)

                Dim lblShaft As Label = oGridViewRow.FindControl("lblShaft")
                oShaft = lblShaft.Text

Open in new window


<asp:GridView ID="GridViewData" runat="server" AllowSorting="True" AutoGenerateColumns="False">
             <Columns>
                 <asp:TemplateField HeaderText="Shaft" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Shaft">
                     <ItemTemplate>
                         <asp:Label ID="lblShaft" runat="server" Text='<%# Bind("Shaft")%>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Site" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Site">
                     <ItemTemplate>
                         <asp:Label ID="lblSite" runat="server" Text='<%# Bind("Site")%>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 

Open in new window

0
I have created a new SQL database with all the required data and tables. The DB houses PDF's and other data. Using SSMS i can run query's and pull the data I need but it's not good for the staff.

What I want to do is to created maybe a simple web page (think google search) or front end where they can type in a key word, phrase, or combination of both and get a result list with a download option for the pdf/documents if any.

How would I start on creating such a front end? I have never made any front end's for SQL DB before
0
I have this code that works for joining a computer to a group, but occasionally fails to join. This does a search for the group, but I don't need to search, I know the exact name of the group and where it's located.  The user is adding the computer into the domain and then into groups using ldap credentials. This code searches for the group, but I have the name and location of the group so I want to avoid searching.


    Private Sub ComputerGroupAdd(ByVal GroupName As String, ByVal ComputerName As String)
        Try
            Dim sDomainName As String = "LDAP://mydomain.local"
            Dim adUserFolder As DirectoryEntry = New DirectoryEntry("LDAP://mydomain.local/DC=mydomain,DC=local")

            adUserFolder.Username = "mydomain.local\myUser"
            adUserFolder.Password = "mypassword"
            Dim adSearch As New System.DirectoryServices.DirectorySearcher(adUserFolder)

            adSearch.Filter = String.Format("(&(objectCategory=group)(sAMAccountName= {0}))", GroupName)

            For Each x As SearchResult In adSearch.FindAll
                Dim group As DirectoryEntry = x.GetDirectoryEntry
                group.Properties("member").Add(ComputerName)
                group.CommitChanges()
            Next
        Catch ex As Exception
                MsgBox(ex.Message)
        End Try
    End Sub

Open in new window

How can I add a computer to a group with credentials using the group's exact name and location. In other words, without searching for the group, which is what this code is doing. Thanks!
0
Hi there.

I'm a step further in my VB.NET study... and I ran into a problem when I'm supposed to create a BasePage.vb where I add the "Inherit System.Web.UI.Page" and after that edit an existing code behind from "Inherit System.Web.UI.Page" to "Inherit BasePage".
When I test the page, I get an error, that:

.... is not allowed here because it does not extend class 'System.Web.UI.Page'.

Even though it's all a bit new to me, it doesn't make sense, because the BasePage does inherit the System.Web.UI.Page...
Any idea what I'm doing wrong?
Let me know if you need more info.

Best regards

Ulrich
0
I have a VB.net program that will be launched by users on our network, but I only want one user to be able to open it at a time. I checked the option "Make single instance application", but that only keeps it from being launched more than once on the same computer.  How can I keep it from being launched more than once from any computers on the network?
0
I'm using MailKit and MimeKit in my VB.NET application to send out emails. In order to do this, the end user must configure settings like SMTP Server, Port, etc.

All of the end users have email clients installed, like Outlook or Thunderbird. Is there some way for my program to use the same credentials as those installed clients without the user having to enter them again? I'm assuming the answer is no, but wanted to ask those more experienced in this sort of thing.
0
Hi there.

Another question in my self-study of vb.NET:

I just tried deleting a control on a form, and I double-clicked a control because I wanted to add some vb-code. Later I deleted the control, but then I see, that the vb-code remains even though the control is gone.... and of course that causes a compiling error.
Is there a setting to automatically delete the related vb-code to a control, if the control is deleted?

Best regards

Ulrich
0
I am doing some VB.Net practice and learning.
For that purpose I need some SQL Server learning version or light version that is free and could be downloaded on my Widows PC.
I assume that is Microsoft web site that could be downloaded those anybody has some link or suggestion.
0
Rowby Goren Makes an Impact on Screen and Online
LVL 13
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

What is the future of VB.NET with .CORE?

Is .CORE only supporting C#?

Is VB.NET becoming obsolete?

Is .CORE replacing webforms?

What is the future of vb.net and webforms?

thanks!
0
I am trying to update a database with info from a WinForm. I had no issues when using a “normal” SQL update command written by hand (parameters set to the text box values,) but I am trying to clean up and reduce my code and I thought I would bind the controls to a DataTable and use a DataAdapter's update command to achieve the same thing.

I have tried to get various combinations of setting parameters and update commands to work, but the Database is not getting updated from the new DataTable values. I have stepped through the code with each change and can see that the DataTable is getting the new textbox values, but those updates aren’t going to the Database. (This is seen when the Fill_Date block runs and selects all new data from the database.)

Things I’ve tried: Letting the binding get the new values vs. setting the parameters manually. Using the command builder to build the update command, using the .UpdateCommand.ExecuteNonQuery(), command and of course a straight.Update(DataTable) command.

Below is the code that I am using. I am hoping someone can tell me what it is I am doing wrong/missing, or what is the correct path to take. Is there a "best practice" or a better way to do this?

Public Class frmDATA
    Dim dt_Test As New DataTable
    Dim da_Test As New SqlDataAdapter
    Dim SQLcmd As SqlCommand

    Private Sub frmDemog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BuildSQL()
        Fill_Data()
        BindControls()
    End 

Open in new window

0
I am calling GetOpenFileName() in Visual Studio and I want it to always appear on top of my current Main Form.
0
Is there a way in VB.Net to actively monitor a computer for when a new file has been created, an existing file has been edited, or a file has been deleted?
0
Hi there.

I started working on a new VB.NET project. It's my first real attempt to make a .NET project. I used classic asp in the past, and all those files is tricking me. This is the case:
At my hosting company I have some old projects stored. In the www-folder (the root of my webserver) I have subfolders with projects, and this new .NET has got a folder too.
Now when I try to publish my very first page, I get an error message with compiling.
When I publish my project, the web.config ends up in the project-folder. Not in the www.root. So I moved it manually to the root on the server, but I have the feeling that it's not the right thing to do.
Can anyone please guide me how to do the publishing correct? Let me know if you need more info.

Best regards

Ulrich
0
Hi

I use the following VB.net code to authenticate against the Xero API. It worked fine on my local machine
but I published the site and changed the post back url from my local machine to that of the published site and it doesn't work

    Protected Function XeroAuthenticate(inpage As Page, authpagereturnedauthentication As Boolean, incode As String) As XeroCoreApi
        ' This procedure will return w working XeroCoreApi if successful and nothing otherwise
        ' Set client secrets for general use and then load any override ones from the web.config file
        Dim myxeroconsumer As New Consumer("xxx", "yyyy")
        Dim myxerouser = New ApiUser() With {.Name = "mxx@yahoo.com"}

        ' If user defined ID and Secrets exist then use those instead
        If Not System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientId") Is Nothing Then
            If Not System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientSecret") Is Nothing Then
                If System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientId").ToString <> "" Then
                    myxeroconsumer = New Consumer(System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientId").ToString, System.Configuration.ConfigurationManager.AppSettings("XeroAPIClientSecret").ToString)
                End If
            End If
        End If

        ' Define Page Call Information
        'Dim myxerocallbackurl = "http://localhost:62054/Default.aspx"
        

Open in new window

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,