"New": Too many arguments - vb.net

I made a "custom" form as seen below. When I say:
Dim nSplash As New frmSplash(nBitmap)
It is telling me that there are "too many arguments for Public Sub New".
I do not see why it is mocking about it.
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Namespace AlphaWindow
Public Class frmSplash
Inherits Form
Public Sub New(ByRef uBitmap As Bitmap)
Me.Size = uBitmap.Size
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
APIHelp.ShowTopmost(Me)
Me.SelectBitmap(uBitmap)
End Sub
(...)
' Class to assist with Win32 API calls
Class APIHelp
Private Const SW_SHOWNOACTIVATE As Integer = 4
Private Const HWND_TOPMOST As Integer = -1
(...)
End Class
End Namespace

The problem is not the Namespace, but when a namespace is included, the form has to be called by "Namespace.Form" instead of just "Form".

Related

Why the XUnit attributs aren't recognised?

I installed the libraries xUnit with NuGet, and added references but I have errors because of the attributes [Theory], [InlineData("11/12/2011","2011-11-12")] and [Fact].
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports System.Text.RegularExpressions
Imports FluentAssertions
Imports Xunit
Imports System
Imports System.Diagnostics
Imports Xunit.Extensions
Public Class XUnitClassTest
[Theory]
[InlineData("11/12/2011","2011-11-12")]
Public Sub test(input As String, output As String)
Dim pattern As String = "\d+|[A-Za-zÀàÂâÄäÇçÉéÈèÊêËëÎîÏïÔôÖöÙùÛûÜü']+"
Dim matchList As MatchCollection = Regex.Matches(input, pattern)
Dim matchArray(matchList.Count - 1) As Match
matchList.CopyTo(matchArray, 0)
Dim manager As Processeur = New Processeur
manager.GetData(matchArray.Select(Function(a) a.ToString())).Should().Be(output)
End Sub
[Fact]
Public Sub FactMethodName()
Write(DateTime.Parse("1658").ToString())
End Sub
Public Shared Sub Write(format As String, ParamArray param As Object())
Console.WriteLine(format, param)
End Sub
End Class
You are using C# attribute syntax in VB.NET.
VB.NET syntax would be
<Fact>
Public Sub FactMethodName()
Write(DateTime.Parse("1658").ToString())
End Sub
and so on.

How to transform this into a DLL

I want to compile a DLL control, is a Extended Panel but I only have the class, I don't like to use classes for add a custom control, i prefer to add the DLL into the toolbox.
Someone can help me to transform this into a class library DLL control?
PS: In addition maybe I can need a guide-step to make the class-library too, it's my first time trying this.
Thankyou.
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Text
Imports System.Windows.Forms
Namespace GradientPanel
Public Partial Class GradientPanel
Inherits System.Windows.Forms.Panel
' member variables
Private mStartColor As System.Drawing.Color
Private mEndColor As System.Drawing.Color
Public Sub New()
' InitializeComponent()
PaintGradient()
End Sub
Protected Overrides Sub OnPaint(pe As PaintEventArgs)
' TODO: Add custom paint code here
' Calling the base class OnPaint
MyBase.OnPaint(pe)
End Sub
Public Property PageStartColor() As System.Drawing.Color
Get
Return mStartColor
End Get
Set
mStartColor = value
PaintGradient()
End Set
End Property
Public Property PageEndColor() As System.Drawing.Color
Get
Return mEndColor
End Get
Set
mEndColor = value
PaintGradient()
End Set
End Property
Private Sub PaintGradient()
Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), PageStartColor, PageEndColor)
Dim bmp As New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.FillRectangle(gradBrush, New Rectangle(0, 0, Me.Width, Me.Height))
Me.BackgroundImage = bmp
Me.BackgroundImageLayout = ImageLayout.Stretch
End Sub
End Class
End Namespace
I have always just used a CustomControlLibrary Name it and set the Assembly Name and Default Namespace to what you want the dll to be, you will then right click on the project and select add class then you will add your Custom Control's Class Code to the the Project. You can also add a new UserControl at that time. When you compile it, it will create a dll that you can browse to by right clicking on your ToolBox selecting choose items then Browse to your Dll that was created. It will then add the Controls that are contained in your Control Library to your ToolBox.

Creating DBContext Initializer Getting 'Type argument <context> does not inherit from or implement the constraint type 'System.Data.Entity.DBContext'

I am trying to initialize a database using Database.SetInitializer but I am getting a 'Type argument does not inherit from or implement the constraint type 'System.Data.Entity.DBContext' Error when my initializer class DOES inherit from DBContext. Any ideas? I'm new to Code First EF by the way!
Context Class:
Imports System.Data.Entity
Imports System.Collections.Generic
Imports System.Data.Entity.Infrastructure
Imports System.Configuration
Public Class PropertyManagementContext
Inherits DbContext
#Region "Constructor"
Public Sub New()
MyBase.New("Data Source=WSBS2K3SQL;Initial Catalog=AQUARIUS_TEST;Persist Security Info=True;User ID=SomeUser;Password=SomePassword;")
End Sub
#End Region
#Region "Tables"
Public Complexes As DbSet(Of Complex)
Public Buildings As DbSet(Of Building)
Public Units As DbSet(Of Unit)
Public Tenants As DbSet(Of Tenant)
#End Region
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
MyBase.OnModelCreating(modelBuilder)
'Set the Primary Keys
modelBuilder.Entity(Of Complex).HasKey(Function(c) c.ComplexId)
modelBuilder.Entity(Of Building).HasKey(Function(b) b.BuildingId).HasKey(Function(b) b.ComplexId)
modelBuilder.Entity(Of Unit).HasKey(Function(u) u.UnitId).HasKey(Function(u) u.BuildingId)
modelBuilder.Entity(Of Tenant).HasKey(Function(t) t.TenantId)
'Set Complex Primary Key to Identity(MS SQL Auto-Increment)
modelBuilder.Entity(Of Complex).Property(Function(c) c.ComplexId) _
.HasDatabaseGeneratedOption(ComponentModel.DataAnnotations.DatabaseGeneratedOption.Identity)
End Sub
End Class
Initializer Class:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data.Entity
Public Class PropertyManagementInitializer
Inherits DropCreateDatabaseAlways(Of PropertyManagementContext)
Protected Overrides Sub Seed(context As PropertyManagementContext)
MyBase.Seed(context)
Dim complex As New Complex With {
.Name = "SomeComplex",
.City = "SomeCity",
.Address = "SomeStreet",
.PostalCode = "R2R2R2",
.Type = "1"
}
context.Complexes.Add(complex)
context.SaveChanges()
End Sub
End Class
Main Form where Database.SetInitializer() is called and giving the error:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Database.SetInitializer(Of PropertyManagementContext)(New PropertyManagementInitializer)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
I have seen this before and for me it seemed that Visual Studio was in a funny way to fix I removed "Inherits DbContext" run a build and then re added "Inherits DbContext" and built solution again, Visual Studio no longer complained.

VB silverlight for windows phone

I am writing an application in VB for windows phone 7.5
but it has some bug
Imports System.IO
Imports System.IO.TextReader
Imports System.Xml
Imports System.Windows.RoutedEventArgs
Imports System.Windows.RoutedEvent
Imports System.ComponentModel
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Tasks
Imports System.Xml.Linq
Imports System.Net.NetworkInformation
Imports Microsoft.VisualBasic.CompilerService
Partial Public Class MainPage
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
End Sub
Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Final.Items.Clear()
If NetworkInterface.GetIsNetworkAvailable Then
Dim cl As New WebClient
AddHandler cl.DownloadStringCompleted, AddressOf cl_DownloadStringCompleted
cl.DownloadStringAsync(New Uri("http://web.com/xml.xml"))
Else
MessageBox.Show("check your internet connection")
End If
End Sub
Private Sub cl_DownloadStringCompleted(sender As Object, e As System.Net.DownloadStringCompletedEventArgs)
Dim doc = XDocument.Parse(e.Result)
Dim names = XDocument.Parse(e.Result)
Dim result_name = names.<Data>.<Entry>
For Each result In doc.<Data>.<Entry>.<tag>
Dim item As New ListBoxItem
item.Content = result.Value
AddHandler item.Tap, AddressOf ItemTap
Final.Items.Add(item)
Next
End Sub
Private Sub ItemTap(sender As Object, e As GestureEventArgs)
Dim lbi As New ListBoxItem
lbi = sender
Dim url As New Uri("/" & lbi.Content & ".xaml", UriKind.Relative)
Me.NavigationService.Navigate(url)
End Sub
End Class
it finds a bug at Dim url As New Uri("/" & lbi.Content & ".xaml", UriKind.Relative)
and it says on the report :
Requested operation is not available because the runtime library
function
'Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject'
is not defined.
NOTE :
when i am changing the ItemTap to this :
Private Sub ItemTap(ByRef sender As Object, e As GestureEventArgs)
this error is gone and appears another one :
Method 'Private Sub ItemTap(ByRef sender As Object, e As
System.Windows.Input.GestureEventArgs)' does not have a signature
compatible with delegate 'Delegate Sub EventHandler(Of
System.Windows.Input.GestureEventArgs)(sender As Object, e As
System.Windows.Input.GestureEventArgs)'.
at line : "AddHandler item.Tap, AddressOf ItemTap"
Any ideas why i have this one ??
thank you !
You're trying to combine two strings and an object and it can't do this.
I strongly suspect that lbi.Content (in the line that is erroring) is a TextBlock, so your code says "concatenate a string, a TextBlock and a string together".
I suspect that you want the text that is displayed in the TextBlock, so just cast it accordingly:
"/" & DirectCast(lbi.Content, TextBlock).Text & ".xaml"

how can i use ActiveDirectory

I have an active Directory (window) on the server ..and i want to connect it with my web pages..
this is my vb code:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Data
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.DirectoryServices ' cannot be found '
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class Default3
Inherits System.Web.UI.Page
Public Function IsADUser(ByVal UserName As [String], ByVal Password As [String]) As [Boolean]
Dim entry As New DirectoryEntry()
entry.Username = UserName
entry.Password = Password
Dim searcher As New DirectorySearcher(entry)
searcher.Filter = "(objectclass=user)"
Dim Authentecated As [Boolean] = False
Try
searcher.FindOne()
Authentecated = True
Catch ex As COMException
Authentecated = False
End Try
Return (Authentecated)
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
The ASP.NET Membership supports Active Directory as well. Check it out:
http://msdn.microsoft.com/en-us/library/ms998360.aspx
To use Active Directory manually, you should add System.DirectoryServices.dll as a reference before.