I am building a module using linq to SQL and I am running into some problems. I have been following Michal Washington's tutorial on adefwebserver.com. The problem is that VB does not recognize my Complaint Class when I try to create new Complaint object. Any idea why I am unable to Dim a Complaint object? Here is my code:
View.ascx.vb(
Imports Complaint
Protected Sub LinqDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs) Handles LinqDataSource1.Inserting
Dim Complaint As **Complaint** = DirectCast(e.NewObject, Complaint)
Complaint.UserID = Entities.Users.UserController.GetCurrentUserInfo().Username
Complaint.ModuleId = ModuleId
Complaint.System_Time_Date_Stamp = Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss.fff")
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim Complaint As Complaint = (DirectCast((e.Row.DataItem), Complaint))
If (PortalSecurity.IsInRole("Administrators")) Then
e.Row.Cells(0).Enabled = True
Else
e.Row.Cells(0).Text = " "
End If
End If
End Sub
)
Complaint.designer.vb(
Option Strict On
Option Explicit On
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Linq
Imports System.Data.Linq.Mapping
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Reflection
Namespace Complaint
<System.Data.Linq.Mapping.DatabaseAttribute(Name:="NewDnn")> _
Partial Public Class ComplaintDataContext
Inherits System.Data.Linq.DataContext
Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = New AttributeMappingSource
#Region "Extensibility Method Definitions"
Partial Private Sub OnCreated()
End Sub
Partial Private Sub InsertComplaint(instance As Complaint)
End Sub
Partial Private Sub UpdateComplaint(instance As Complaint)
End Sub
Partial Private Sub DeleteComplaint(instance As Complaint)
End Sub
#End Region
Public Sub New()
MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As String)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As System.Data.IDbConnection)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As String, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
MyBase.New(connection, mappingSource)
OnCreated
End Sub
Public ReadOnly Property Complaints() As System.Data.Linq.Table(Of Complaint)
Get
Return Me.GetTable(Of Complaint)
End Get
End Property
End Class
<Table(Name:="dbo.Complaint")> _
Partial Public Class Complaint
Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
Private _ID As Integer
Private _ModuleID As System.Nullable(Of Integer)
Private _Member_UserName As String
Private _Reporter_Preffered_Contact As String
Private _Target_FName As String
Private _Target_LName As String
Private _Target_Street_Address As String
Private _Target_City As String
Private _Target_State As String
Private _Target_Zip As String
Private _Complaint_Details As String
Private _Status As String
Private _System_Time_Date_Stamp As System.Nullable(Of Date)
#Region "Extensibility Method Definitions"
Partial Private Sub OnLoaded()
End Sub
Partial Private Sub OnValidate(action As System.Data.Linq.ChangeAction)
End Sub
Partial Private Sub OnCreated()
End Sub
Partial Private Sub OnIDChanging(value As Integer)
End Sub
Partial Private Sub OnIDChanged()
End Sub
Partial Private Sub OnModuleIDChanging(value As System.Nullable(Of Integer))
End Sub
Partial Private Sub OnModuleIDChanged()
End Sub
Partial Private Sub OnMember_UserNameChanging(value As String)
End Sub
Partial Private Sub OnMember_UserNameChanged()
End Sub
Partial Private Sub OnReporter_Preffered_ContactChanging(value As String)
End Sub
Partial Private Sub OnReporter_Preffered_ContactChanged()
End Sub
Partial Private Sub OnTarget_FNameChanging(value As String)
End Sub
Partial Private Sub OnTarget_FNameChanged()
End Sub
Partial Private Sub OnTarget_LNameChanging(value As String)
End Sub
Partial Private Sub OnTarget_LNameChanged()
End Sub
Partial Private Sub OnTarget_Street_AddressChanging(value As String)
End Sub
Partial Private Sub OnTarget_Street_AddressChanged()
End Sub
Partial Private Sub OnTarget_CityChanging(value As String)
End Sub
Partial Private Sub OnTarget_CityChanged()
End Sub
Partial Private Sub OnTarget_StateChanging(value As String)
End Sub
Partial Private Sub OnTarget_StateChanged()
End Sub
Partial Private Sub OnTarget_ZipChanging(value As String)
End Sub
Partial Private Sub OnTarget_ZipChanged()
End Sub
Partial Private Sub OnComplaint_DetailsChanging(value As String)
End Sub
Partial Private Sub OnComplaint_DetailsChanged()
End Sub
Partial Private Sub OnStatusChanging(value As String)
End Sub
Partial Private Sub OnStatusChanged()
End Sub
Partial Private Sub OnSystem_Time_Date_StampChanging(value As System.Nullable(Of Date))
End Sub
Partial Private Sub OnSystem_Time_Date_StampChanged()
End Sub
#End Region
Public Sub New()
MyBase.New
OnCreated
End Sub
<Column(Storage:="_ID", AutoSync:=AutoSync.OnInsert, DbType:="Int NOT NULL IDENTITY", IsPrimaryKey:=true, IsDbGenerated:=true)> _
Public Property ID() As Integer
Get
Return Me._ID
End Get
Set
If ((Me._ID = value) _
= false) Then
Me.OnIDChanging(value)
Me.SendPropertyChanging
Me._ID = value
Me.SendPropertyChanged("ID")
Me.OnIDChanged
End If
End Set
End Property
<Column(Storage:="_ModuleID", DbType:="Int")> _
Public Property ModuleID() As System.Nullable(Of Integer)
Get
Return Me._ModuleID
End Get
Set
If (Me._ModuleID.Equals(value) = false) Then
Me.OnModuleIDChanging(value)
Me.SendPropertyChanging
Me._ModuleID = value
Me.SendPropertyChanged("ModuleID")
Me.OnModuleIDChanged
End If
End Set
End Property
<Column(Storage:="_Member_UserName", DbType:="NVarChar(50)")> _
Public Property Member_UserName() As String
Get
Return Me._Member_UserName
End Get
Set
If (String.Equals(Me._Member_UserName, value) = false) Then
Me.OnMember_UserNameChanging(value)
Me.SendPropertyChanging
Me._Member_UserName = value
Me.SendPropertyChanged("Member_UserName")
Me.OnMember_UserNameChanged
End If
End Set
End Property
<Column(Storage:="_Reporter_Preffered_Contact", DbType:="NVarChar(50)")> _
Public Property Reporter_Preffered_Contact() As String
Get
Return Me._Reporter_Preffered_Contact
End Get
Set
If (String.Equals(Me._Reporter_Preffered_Contact, value) = false) Then
Me.OnReporter_Preffered_ContactChanging(value)
Me.SendPropertyChanging
Me._Reporter_Preffered_Contact = value
Me.SendPropertyChanged("Reporter_Preffered_Contact")
Me.OnReporter_Preffered_ContactChanged
End If
End Set
End Property
<Column(Storage:="_Target_FName", DbType:="NVarChar(50)")> _
Public Property Target_FName() As String
Get
Return Me._Target_FName
End Get
Set
If (String.Equals(Me._Target_FName, value) = false) Then
Me.OnTarget_FNameChanging(value)
Me.SendPropertyChanging
Me._Target_FName = value
Me.SendPropertyChanged("Target_FName")
Me.OnTarget_FNameChanged
End If
End Set
End Property
<Column(Storage:="_Target_LName", DbType:="NVarChar(50)")> _
Public Property Target_LName() As String
Get
Return Me._Target_LName
End Get
Set
If (String.Equals(Me._Target_LName, value) = false) Then
Me.OnTarget_LNameChanging(value)
Me.SendPropertyChanging
Me._Target_LName = value
Me.SendPropertyChanged("Target_LName")
Me.OnTarget_LNameChanged
End If
End Set
End Property
<Column(Storage:="_Target_Street_Address", DbType:="NVarChar(100)")> _
Public Property Target_Street_Address() As String
Get
Return Me._Target_Street_Address
End Get
Set
If (String.Equals(Me._Target_Street_Address, value) = false) Then
Me.OnTarget_Street_AddressChanging(value)
Me.SendPropertyChanging
Me._Target_Street_Address = value
Me.SendPropertyChanged("Target_Street_Address")
Me.OnTarget_Street_AddressChanged
End If
End Set
End Property
<Column(Storage:="_Target_City", DbType:="NVarChar(50)")> _
Public Property Target_City() As String
Get
Return Me._Target_City
End Get
Set
If (String.Equals(Me._Target_City, value) = false) Then
Me.OnTarget_CityChanging(value)
Me.SendPropertyChanging
Me._Target_City = value
Me.SendPropertyChanged("Target_City")
Me.OnTarget_CityChanged
End If
End Set
End Property
<Column(Storage:="_Target_State", DbType:="NVarChar(50)")> _
Public Property Target_State() As String
Get
Return Me._Target_State
End Get
Set
If (String.Equals(Me._Target_State, value) = false) Then
Me.OnTarget_StateChanging(value)
Me.SendPropertyChanging
Me._Target_State = value
Me.SendPropertyChanged("Target_State")
Me.OnTarget_StateChanged
End If
End Set
End Property
<Column(Storage:="_Target_Zip", DbType:="NVarChar(50)")> _
Public Property Target_Zip() As String
Get
Return Me._Target_Zip
End Get
Set
If (String.Equals(Me._Target_Zip, value) = false) Then
Me.OnTarget_ZipChanging(value)
Me.SendPropertyChanging
Me._Target_Zip = value
Me.SendPropertyChanged("Target_Zip")
Me.OnTarget_ZipChanged
End If
End Set
End Property
<Column(Storage:="_Complaint_Details", DbType:="NVarChar(4000)")> _
Public Property Complaint_Details() As String
Get
Return Me._Complaint_Details
End Get
Set
If (String.Equals(Me._Complaint_Details, value) = false) Then
Me.OnComplaint_DetailsChanging(value)
Me.SendPropertyChanging
Me._Complaint_Details = value
Me.SendPropertyChanged("Complaint_Details")
Me.OnComplaint_DetailsChanged
End If
End Set
End Property
<Column(Storage:="_Status", DbType:="NVarChar(4000)")> _
Public Property Status() As String
Get
Return Me._Status
End Get
Set
If (String.Equals(Me._Status, value) = false) Then
Me.OnStatusChanging(value)
Me.SendPropertyChanging
Me._Status = value
Me.SendPropertyChanged("Status")
Me.OnStatusChanged
End If
End Set
End Property
<Column(Storage:="_System_Time_Date_Stamp", DbType:="DateTime")> _
Public Property System_Time_Date_Stamp() As System.Nullable(Of Date)
Get
Return Me._System_Time_Date_Stamp
End Get
Set
If (Me._System_Time_Date_Stamp.Equals(value) = false) Then
Me.OnSystem_Time_Date_StampChanging(value)
Me.SendPropertyChanging
Me._System_Time_Date_Stamp = value
Me.SendPropertyChanged("System_Time_Date_Stamp")
Me.OnSystem_Time_Date_StampChanged
End If
End Set
End Property
Public Event PropertyChanging As PropertyChangingEventHandler Implements System.ComponentModel.INotifyPropertyChanging.PropertyChanging
Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub SendPropertyChanging()
If ((Me.PropertyChangingEvent Is Nothing) _
= false) Then
RaiseEvent PropertyChanging(Me, emptyChangingEventArgs)
End If
End Sub
Protected Overridable Sub SendPropertyChanged(ByVal propertyName As [String])
If ((Me.PropertyChangedEvent Is Nothing) _
= false) Then
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End If
End Sub
End Class
End Namespace
)
Using "Complaint" as the NameSpace, Class name, and Object name is a bad idea and might be causing your problem. I know you can name the variable the same as the class in C# but I'm not sure it's legal in VB.NET, it's not something I do since it can be confusing on whether you're referring to the instance or the class.
I ran into an issue similar to this. My app code was in a folder above my DesktopModules folder, so the designer put the incorrect namespace in my designer.vb file.
All of my other .vb files had
Namespace Modules.CGaming
but the auto generated one only had
Namespace CGaming
Once I modified the namespace on my designer.vb file, it was available in the context.
Hope this helps!
Related
I'm create a program in VB.NET with embedded GeckoFx browser. How to creating zip:// protocol to read from password protected zip file?
Example: zip:///d:/dir/file.zip!/idnex.html
Note: jar:file:///d:/dir/file.zip!/idnex.html is not read the index.html from password protected ZIP file.
Initialize Gecko in MainWindow class:
Sub New()
InitializeComponent()
Xpcom.Initialize("Firefox64")
Xpcom.RegisterFactory(
New Guid("66170430-e4ec-11e9-aaef-0800200c9a66"),
"Zip protocol handler",
"#mozilla.org/network/protocol;1?name=zip",
New ZipFacrory)
End Sub
The ZipFactory class:
Class ZipFacrory
Implements nsIFactory
Public Function CreateInstance(aOuter As nsISupports, ByRef iid As Guid) As IntPtr Implements nsIFactory.CreateInstance
Return Marshal.GetComInterfaceForObject(New ZipProtocolHandler(), GetType(nsIProtocolHandler))
End Function
Public Sub LockFactory(lock As Boolean) Implements nsIFactory.LockFactory
End Sub
End Class
The ZipProtocolHandler class:
Class ZipProtocolHandler
Implements nsIProtocolHandler
Public Sub GetSchemeAttribute(aScheme As nsACStringBase) Implements nsIProtocolHandler.GetSchemeAttribute
aScheme.SetData("zip")
End Sub
Public Function GetDefaultPortAttribute() As Integer Implements nsIProtocolHandler.GetDefaultPortAttribute
Return -1
End Function
Public Function GetProtocolFlagsAttribute() As UInteger Implements nsIProtocolHandler.GetProtocolFlagsAttribute
Return nsIProtocolHandlerConsts.URI_NOAUTH Or nsIProtocolHandlerConsts.URI_IS_LOCAL_FILE Or
nsIProtocolHandlerConsts.URI_IS_LOCAL_RESOURCE
End Function
Public Function NewURI(aSpec As nsAUTF8StringBase, aOriginCharset As String, aBaseURI As nsIURI) As nsIURI Implements nsIProtocolHandler.NewURI
Dim mutator As nsIStandardURLMutator = Xpcom.CreateInstance(Of nsIStandardURLMutator)("#mozilla.org/network/standard-url-mutator;1")
Return mutator.Init(nsIStandardURLConsts.URLTYPE_STANDARD, -1, aSpec, aOriginCharset, aBaseURI).Finalize()
End Function
Public Function NewChannel2(aURI As nsIURI, aLoadinfo As nsILoadInfo) As nsIChannel Implements nsIProtocolHandler.NewChannel2
Return New ZipChannel(aURI, aLoadinfo)
End Function
Public Function NewChannel(aURI As nsIURI) As nsIChannel Implements nsIProtocolHandler.NewChannel
Return NewChannel2(aURI, Nothing)
End Function
Public Function AllowPort(port As Integer, scheme As String) As Boolean Implements nsIProtocolHandler.AllowPort
Return False
End Function
End Class
The ZipChannel class:
Class ZipChannel
Implements nsIChannel
Private status As Integer
Private loadGroup As nsILoadGroup
Private loadFlags As UInteger
Private originalURI As nsIURI
Private owner As nsISupports
Private notificationCallbacks As nsIInterfaceRequestor
Private contentType As String
Private contentCharset As String
Private loadInfo As nsILoadInfo
Private contentLengt As Long
Private contentDisposition As UInteger
Private contentDispositionFilename As Integer
Sub New(aURI As nsIURI, aloadInfo As nsILoadInfo)
originalURI = aURI
loadInfo = aloadInfo
End Sub
Public Sub GetNameAttribute(aName As nsAUTF8StringBase) Implements nsIChannel.GetNameAttribute, nsIRequest.GetNameAttribute
aName.SetData("Zip channel")
End Sub
Public Function IsPending() As Boolean Implements nsIChannel.IsPending, nsIRequest.IsPending
Return False
End Function
Public Function GetStatusAttribute() As Integer Implements nsIChannel.GetStatusAttribute, nsIRequest.GetStatusAttribute
Return status
End Function
Public Sub Cancel(aStatus As Integer) Implements nsIChannel.Cancel, nsIRequest.Cancel
status = aStatus
End Sub
Public Sub Suspend() Implements nsIChannel.Suspend, nsIRequest.Suspend
status = GeckoError.NS_OK
End Sub
Public Sub [Resume]() Implements nsIChannel.Resume, nsIRequest.Resume
status = GeckoError.NS_OK
End Sub
Public Function GetLoadGroupAttribute() As nsILoadGroup Implements nsIChannel.GetLoadGroupAttribute, nsIRequest.GetLoadGroupAttribute
Return loadGroup
End Function
Public Sub SetLoadGroupAttribute(aLoadGroup As nsILoadGroup) Implements nsIChannel.SetLoadGroupAttribute, nsIRequest.SetLoadGroupAttribute
loadGroup = aLoadGroup
End Sub
Public Function GetLoadFlagsAttribute() As UInteger Implements nsIChannel.GetLoadFlagsAttribute, nsIRequest.GetLoadFlagsAttribute
Return loadFlags
End Function
Public Sub SetLoadFlagsAttribute(aLoadFlags As UInteger) Implements nsIChannel.SetLoadFlagsAttribute, nsIRequest.SetLoadFlagsAttribute
loadFlags = aLoadFlags
End Sub
Public Function GetOriginalURIAttribute() As nsIURI Implements nsIChannel.GetOriginalURIAttribute
Return originalURI
End Function
Public Sub SetOriginalURIAttribute(aOriginalURI As nsIURI) Implements nsIChannel.SetOriginalURIAttribute
originalURI = aOriginalURI
End Sub
Public Function GetURIAttribute() As nsIURI Implements nsIChannel.GetURIAttribute
Return originalURI
End Function
Public Function GetOwnerAttribute() As nsISupports Implements nsIChannel.GetOwnerAttribute
Return owner
End Function
Public Sub SetOwnerAttribute(aOwner As nsISupports) Implements nsIChannel.SetOwnerAttribute
owner = aOwner
End Sub
Public Function GetNotificationCallbacksAttribute() As nsIInterfaceRequestor Implements nsIChannel.GetNotificationCallbacksAttribute
Return notificationCallbacks
End Function
Public Sub SetNotificationCallbacksAttribute(aNotificationCallbacks As nsIInterfaceRequestor) Implements nsIChannel.SetNotificationCallbacksAttribute
notificationCallbacks = aNotificationCallbacks
End Sub
Public Function GetSecurityInfoAttribute() As nsISupports Implements nsIChannel.GetSecurityInfoAttribute
'???
Return Nothing
End Function
Public Sub GetContentTypeAttribute(aContentType As nsACStringBase) Implements nsIChannel.GetContentTypeAttribute
aContentType.SetData(contentType)
End Sub
Public Sub SetContentTypeAttribute(aContentType As nsACStringBase) Implements nsIChannel.SetContentTypeAttribute
contentType = aContentType.ToString
End Sub
Public Sub GetContentCharsetAttribute(aContentCharset As nsACStringBase) Implements nsIChannel.GetContentCharsetAttribute
aContentCharset.SetData(contentCharset)
End Sub
Public Sub SetContentCharsetAttribute(aContentCharset As nsACStringBase) Implements nsIChannel.SetContentCharsetAttribute
contentCharset = aContentCharset.ToString
End Sub
Public Function GetContentLengthAttribute() As Long Implements nsIChannel.GetContentLengthAttribute
Return contentLengt
End Function
Public Sub SetContentLengthAttribute(aContentLength As Long) Implements nsIChannel.SetContentLengthAttribute
contentLengt = aContentLength
End Sub
Public Function Open() As nsIInputStream Implements nsIChannel.Open
'NS_ERROR_IN_PROGRESS (if the channel is reopened)
Throw New NotImplementedException()
End Function
Public Function Open2() As nsIInputStream Implements nsIChannel.Open2
Throw New NotImplementedException()
End Function
Public Sub AsyncOpen(aListener As nsIStreamListener, aContext As nsISupports) Implements nsIChannel.AsyncOpen
'example zip://impera.zip!/folder/file.png
Dim uri As Uri = originalURI.ToUri
Dim filespec As String = uri.Authority & uri.AbsolutePath
Dim t As String() = filespec.Split({"!/", "!\", "!"}, StringSplitOptions.None)
' MIME type
Dim ms = Xpcom.CreateInstance(Of nsIMIMEService)("#mozilla.org/mime;1")
Dim mime As nsACString = New nsACString
ms.GetTypeFromURI(originalURI, mime)
SetContentTypeAttribute(mime)
contentCharset = Text.Encoding.Default.WebName
aListener.OnStartRequest(Me, aContext)
Try
Using zip As ZipFile = New ZipFile(t(0))
Using zipstream As System.IO.Stream = zip(t(1)).OpenReader(kulcs), sr As System.IO.StreamReader = New System.IO.StreamReader(zipstream, Text.Encoding.Default)
Dim data As String = sr.ReadToEnd
Dim s = New nsAString
s.SetData(data)
Dim converter = Xpcom.CreateInstance(Of nsIConverterOutputStream)("#mozilla.org/intl/converter-output-stream;1")
Dim size As UInteger = zipstream.Length
Dim storagestream = Xpcom.CreateInstance(Of nsIStorageStream)("#mozilla.org/storagestream;1")
storagestream.Init(8192, size)
converter.Init(storagestream.GetOutputStream(0), Text.Encoding.Default.WebName) 'UTF-8 Text.Encoding.Default.BodyName
converter.WriteString(s)
converter.Close()
Dim stream = storagestream.NewInputStream(0)
aListener.OnDataAvailable(Me, aContext, stream, 0, stream.Available)
End Using
End Using
Catch ex As Exception
End Try
aListener.OnStopRequest(Me, aContext, GeckoError.NS_OK)
End Sub
Public Sub AsyncOpen2(aListener As nsIStreamListener) Implements nsIChannel.AsyncOpen2
AsyncOpen(aListener, Nothing)
End Sub
Public Function GetContentDispositionAttribute() As UInteger Implements nsIChannel.GetContentDispositionAttribute
Return contentDisposition
End Function
Public Sub SetContentDispositionAttribute(aContentDisposition As UInteger) Implements nsIChannel.SetContentDispositionAttribute
contentDisposition = aContentDisposition
End Sub
Public Sub GetContentDispositionFilenameAttribute(aContentDispositionFilename As nsAStringBase) Implements nsIChannel.GetContentDispositionFilenameAttribute
aContentDispositionFilename.SetData(contentDispositionFilename)
End Sub
Public Sub SetContentDispositionFilenameAttribute(aContentDispositionFilename As nsAStringBase) Implements nsIChannel.SetContentDispositionFilenameAttribute
contentDispositionFilename = aContentDispositionFilename.ToString
End Sub
Public Sub GetContentDispositionHeaderAttribute(aContentDispositionHeader As nsACStringBase) Implements nsIChannel.GetContentDispositionHeaderAttribute
'???
'aContentDispositionHeader.SetData("inline")
'aContentDispositionHeader.SetData("Content-Disposition: inline")
End Sub
Public Function GetLoadInfoAttribute() As nsILoadInfo Implements nsIChannel.GetLoadInfoAttribute
Return loadInfo
End Function
Public Sub SetLoadInfoAttribute(aLoadInfo As nsILoadInfo) Implements nsIChannel.SetLoadInfoAttribute
loadInfo = aLoadInfo
End Sub
Public Function GetIsDocumentAttribute() As Boolean Implements nsIChannel.GetIsDocumentAttribute
Return False
End Function
End Class
Test HTML page (D:/index.html):
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<p><img src="zip:///d:/web.zip!/truck.png"/><img src="truck.png"/></p>
</body>
</html>
The image does not load from the web.zip file.
But the channel works:
Dim uri = IOService.CreateNsIUri("zip:///d:/web.zip!/truck.png")
Dim ch As nsIChannel = IOService.NewChannelFromUri(uri)
Dim list = New Listener
ch.AsyncOpen(list, Nothing)
The Listener class:
Class Listener
Implements nsIStreamListener
Public Sub OnStartRequest(aRequest As nsIRequest, aContext As nsISupports) Implements nsIStreamListener.OnStartRequest
End Sub
Public Sub OnStopRequest(aRequest As nsIRequest, aContext As nsISupports, aStatusCode As Integer) Implements nsIStreamListener.OnStopRequest
End Sub
Public Sub OnDataAvailable(aRequest As nsIRequest, aContext As nsISupports, aInputStream As nsIInputStream, aOffset As ULong, aCount As UInteger) Implements nsIStreamListener.OnDataAvailable
Try
Dim ss = Gecko.IO.InputStream.Create(aInputStream)
Dim fs = System.IO.File.Create("d:\truck2.png")
ss.CopyTo(fs)
fs.Close()
Catch ex As Exception
End Try
End Sub
Private Sub nsIRequestObserver_OnStartRequest(aRequest As nsIRequest, aContext As nsISupports) Implements nsIRequestObserver.OnStartRequest
End Sub
Private Sub nsIRequestObserver_OnStopRequest(aRequest As nsIRequest, aContext As nsISupports, aStatusCode As Integer) Implements nsIRequestObserver.OnStopRequest
End Sub
End Class
The D:/truck.png and D:/truck2.png are same.
Why doesn't the picture appear in browser?
Not an experienced programmer, so probably not a hard question.
Developing a small application in VB.net in WPF.
I made 3 classes, EngineeringObject<==Inherits==PartOfInstallation<==Inherits==SensorActor
In the class SensorActor I'm trying to get a property of PartOfInstallation with the function MyBase.Name. But this goes directly to EngineeringObject. How do I solve this?
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Private sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor)
End Sub
End Class
Public Class SensorActor
Inherits PartOfInstallation
Dim sMyPartOfInstallation As String
Public Property MyPartOfInstallation As String
Get
Return sMyPartOfInstallation
End Get
Set(value As String)
sMyPartOfInstallation = MyBase.Name
End Set
End Property
End Class
If I understand it correctly, based on your comments, you want every SensorActor instantiated within a PartOfInstallation instance to get the same name as that instance.
If so, then just add a second constructor to your SensorActor class allowing you to pass a name for it as well:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New() 'Empty constructor, for if/when you don't want to set the name immediately.
End Sub
Public Sub New(ByVal Name As String)
Me.Name = Name
End Sub
End Class
Now in your PartOfInstallation class you can do:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me.Name)) 'Here, "Me" refers to the current PartOfInstallation instance.
End Sub
Alternatively you can make the SensorActor constructor take a PartOfInstallation instance instead, allowing you to copy any properties you like:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New()
End Sub
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
Me.Name = BasedOnPOI.Name
End Sub
End Class
Thus making the code in the PartOfInstallation class:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
Read more about constructors: Object Lifetime: How Objects Are Created and Destroyed (Visual Basic) | Microsoft Docs
The result below, if there's room for improvement... always welcome.
SensorActor
Public Class SensorActor
Inherits PartOfInstallation
Dim sTemp As String
Public Overloads Property SystemId() As String
Get
Return Me.sSystemId
End Get
Set(ByVal value As String)
Me.sSystemId = sTemp + "." + value
End Set
End Property
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
sTemp = BasedOnPOI.SystemId
End Sub
End Class
PartOfInstallation
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
End Class
EngineeringObject
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Friend sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = "=" + value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class
I am having a problem getting my program to print an array. I have created a class with code and I want to be able to use the class to print the array. I have submitted my code below. hopefully Y'all can help me out thanks.
Option Strict On
Imports System.IO
Imports FinalLIB
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fsrFile As StreamReader = New StreamReader("Cars.csv")
Dim line, splitLine(1) As String
Dim bestCars(14) As Cars
Dim counter As Integer
Do Until fsrFile.EndOfStream
line = fsrFile.ReadLine
splitLine = Split(line, ",")
bestCars(counter) = New Cars(splitLine(0), (splitLine(1)), (splitLine(2)), (splitLine(3)))
counter += 1
Loop
Dim strCarMake, strCarModel, intyear, strColorc As Cars
Console.WriteLine(bestCars(3))
End Sub
This is the code from my library created.
Option Strict On
Public Class Cars
Private strCarMake As String
Private strCarModel As String
Private intYear As String
Private strColor As String
Public Sub New(ByVal bvstrCarMake As String, ByVal bvstrCarModel As String, ByVal bvintYear As String, ByVal bvstrColor As String)
prpCarMake = bvstrCarMake
prpYear = CInt(bvintYear)
prpCarModel = bvstrCarModel
prpColor = bvstrColor
End Sub
Public Property prpCarMake() As String
Get
Return strCarMake
End Get
Set(bvstrCarMake As String)
strCarMake = bvstrCarMake
End Set
End Property
Public Property prpCarModel() As String
Get
Return strCarModel
End Get
Set(bvstrCarModel As String)
strCarModel = bvstrCarModel
End Set
End Property
Public Property prpYear() As Integer
Get
Return CInt(intYear)
End Get
Set(bvintYear As Integer)
intYear = CType(bvintYear, String)
End Set
End Property
Public Property prpColor() As String
Get
Return strColor
End Get
Set(bvstrColor As String)
strColor = bvstrColor
End Set
End Property
Public ReadOnly Property prpIsOld() As Boolean
Get
If prpYear > 2010 Then
Return True
Else
Return False
End If
End Get
End Property
'Public ReadOnly Property prpSSN() As String
'Get
'Return strSSN
'End Get
'End Property
Public Function ReturnFullInfo() As String
Return "Make: " & prpCarMake & " Model: " & prpCarModel & "Year: " & prpYear & "Color: " & prpColor
End Function
End Class
I've defined a SerialPort object as the following:
Public WithEvents SerialComm As New System.IO.Ports.SerialPort
SerialComm is setup and opened in the object constructor and closed when the object is disposed. My handler signature is as follows:
Private Sub OnComm(sender as Object, e as SerialDataReceivedEventArgs) Handles SerialComm.DataReceived
I'm trying to get a DataReceived event to fire from HyperTerminal. After sending some data, I can set a breakpoint and check the value of SerialComm.BytesToRead and see that it has updated to the proper number of bytes.
I have confirmed that the SerialPort is open and is receiving data, but I can't get the event to fire.
I've also tried manually wiring up the event (after removing the WithEvents definition) using AddHandler, but I was still unable to get the event to trigger.
What am I missing?
Update:
This is the class that I'm having trouble with:
Imports System.IO.Ports
Public Class CopyCat
Implements IDisposable
Private RxString As String
Private LastReceiveTime As DateTime
Public WithEvents SerialComm As New SerialPort
Public Property Timeout As TimeSpan
Public Sub New(commPort As String, timeout As TimeSpan)
Me.Timeout = timeout
Enable(commPort)
End Sub
Public Sub New(commPort As String)
Me.New(commPort, TimeSpan.FromMilliseconds(1000))
End Sub
Public Sub Enable()
CommUtilities.SetupComm(SerialComm, commPort, 115200, 8, Parity.Odd, StopBits.One, Handshake.None, System.Text.Encoding.Default)
End Sub
Public Sub Disable()
SerialComm.Close()
End Sub
Private Sub OnComm(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialComm.DataReceived
If(DateTime.Now - LastReceivedTime > Timeout) Then RxString = ""
Do While(SerialComm.BytesToRead > 0)
Dim readChar As String
Dim termChar As Char = Chr(RxString.ToByteList().XorAll())
readChar = SerialComm.ReadChar
RxString &= readChar
if (readChar = termChar) Then
SerialComm.Write((From item In GetResponse(RxString).Build()
Select item.Data).ToRawString)
RxString = ""
End If
Loop
End Sub
Public Function GetResponse(commandString As String) As MessageResponse
Dim response As MessageResponse = MessageResponse.GetMessageResponseFromByteList(commandString.ToByteList())
if (response.GetType = GetType(GetStatusResponse)) Then
response.DataBytes(8).Data = Math.Floor(Rnd() * 255)
response.DataBytes(9).Data = Math.Floor(Rnd() * 255)
End If
Return response
End Function
Private disposedValue as Boolean
Protected Overridable Sub Dispose(disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
SerialComm.Dispose()
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End Class
I have a question related with VB.Net Code.
I see that the DataTable we can use:
DataTable(0) ' This return a DataRow with the selected index
In the intellisense I see that this functionality can achieve with a extension... but, If I create a extension, always I need refer the Extension before to use it
Public Module asdadsdas
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)>
<System.Runtime.CompilerServices.ExtensionAttribute()>
Friend Function MyExt(ByVal pMyObject As MyObject, ByVal ColumnName As String) As MyObject.ColumnData
Return pMyObject.Columns(0)
End Function
End Module
Public Class MyObject
Friend Structure ColumnData
Friend vNombre As String
Friend vApellido As String
Friend vTelefono As String
Public Property Nombre As String
Get
Return Me.vNombre
End Get
Set(ByVal value As String)
Me.vNombre = value
End Set
End Property
End Structure
Friend Columns() As ColumnData
Public Sub add(ByVal MyColumn As String)
ReDim Columns(0)
Columns(0).vNombre = MyColumn
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Test As New MyObject
Test.add("TEST 001")
' HERE IS THE PROBLEM
Test("TEST 001")
' CORRECT USE
Test.MyExt("TEST 001")
End Sub
End Class
Now, my concrete question: How I can make a default extension in a specific Object?
#competent_tech: man you are a genius... thanks by your comment!
This is the solution of my problem:
Public Class ColumnData
Friend Name As String
Friend LastName As String
Friend Phone As String
End Class
Public Class MyColumns
Friend Data() As ColumnData
Default Property Item(ByVal ColumnName As String) As ColumnData
Get
Return Data(0)
End Get
Set(ByVal value As ColumnData)
End Set
End Property
Public Sub add(ByVal Name As String, ByVal LastName As String, ByVal Phone As String)
If Data Is Nothing Then
ReDim Data(0)
Data(0) = New ColumnData
End If
With Data(0)
.Name = Name
.LastName = LastName
.Phone = Phone
End With
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Test As New MyColumns
Test.add("Name 001", "bolanos.m", "500-2004-1000")
Debug.Print(Test("Name 001").LastName & " - " & Test("Name 001").Phone)
' bolanos.m - 500-2004-1000
Test("Name").LastName = "BOLANOS.M MODIFY"
Debug.Print(Test("Name 001").LastName & " - " & Test("Name 001").Phone)
' BOLANOS.M(MODIFY - 500 - 2004 - 1000)
End Sub
End Class
Why not just add default properties to the MyObject class?
Default Public Property IndexedColumn(index As String) As ColumnData
Get
Return Columns(index)
End Get
Set(value As ColumnData)
Columns(index) = value
End Set
End Property
Default Public Property IndexedColumn(index As Integer) As ColumnData
Get
Return Columns(index)
End Get
Set(value As ColumnData)
Columns(index) = value
End Set
End Property
You will need to change the exposure level of the structure and the access will be:
Dim oColumnData = Test("TEST 001")