System.InvalidOperationException: 'An error occurred creating the form - vb.net

Upon trying to run/debug code of a WindowsForm I run into the following exception:
System.InvalidOperationException HResult=0x80131509 Message=An
error occurred creating the form. See Exception.InnerException for
details. The error is: Object reference not set to an instance of an
object. Source=Automated SoundPower Testing StackTrace: at
Automated_SoundPower_Testing.My.MyProject.MyForms.Create__Instance__[T](T
Instance) in :line 190 at
Automated_SoundPower_Testing.My.MyProject.MyForms.get_Form1() at
Automated_SoundPower_Testing.My.MyApplication.OnCreateMainForm() in
C:\Users\M0110823\source\repos\Automated SoundPower Testing\My
Project\Application.Designer.vb:line 35 at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine) at
Automated_SoundPower_Testing.My.MyApplication.Main(String[] Args) in
:line 81
Inner Exception 1: NullReferenceException: Object reference not set to
an instance of an object."
This exception references:
Me.MainForm = Global.Automated_SoundPower_Testing.Form1
I'm thinking this could possibly be due to the fact that I am trying to call Me.Mainform before it has been created? Or is there possibly a naming miscommunication between the directory and the project properties? I have created blank project and transferred code/vb form over and run into the same error.
This leads me to believe that there is some error in my code?
This is the first section of my code, everything after this is categorized into regions under Class Form1.
Imports System.Windows.Forms
Imports System.Windows.Controls.Label
Imports System.IO
Imports System
Imports System.Text.RegularExpressions
Imports Microsoft.Office.Interop
Imports LMSTestLabAutomation
Imports System.IO.File
Imports System.IO.Path
Imports System.Threading
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Class Form1
Dim TL As LMSTestLabAutomation.Application
Public tlDb As IDatabase
Dim SaveDataName As String
'Declare UA variables
Dim UAmodel, UAtype, UAsn, UAoperator, UAdate, UAcomment,
UAtesttype, UAtestpurpose, UAtime, UAtestduration As String
Dim UAlist As New SortedList(Of String, String)
Dim AcqState As String = "Acquisition Offline"
Dim aRecordTime As Boolean() = New Boolean() {}
Dim aRunNames As String() = New String() {}
Dim aProjectNames As String() = New String() {}
Dim aStatus As String() = New String() {}
Dim aStartTrigger As Single() = New Single() {}
Dim aStopTrigger As Single() = New Single() {}
Dim aTriggerCondition As String() = New String() {}
Dim aSequences As Integer() = New Integer() {}
Dim newTestIncrement As Integer
Dim newTest As String() = aRunNames
'Declarations of the used objects
Dim database As LMSTestLabAutomation.IDatabase
Dim datawatch_pictManag As LMSTestLabAutomation.IDataWatch
Dim WithEvents gDataWatch_AcqState As LMSTestLabAutomation.DataWatch
Dim pictManag As LMSTestLabAutomation.IPictureManager
Dim myPicture As LMSTestLabAutomation.IPicture
Dim myBlock As LMSTestLabAutomation.IBlock2
Dim myDisplay As LMSTestLabAutomation.IDisplay
Dim Measure_Port As LMSTestLabAutomation.DataWatch
Dim Open_book = TL.ActiveBook
Dim sequence_number = Open_book(0, 2)
runtime exception

Related

VB.NET Tool To List And Change Users Groups On Active Directory

I'm trying to make a tool to list and change users group on active directory based on groups that manager has control. I'm stuck on listing function, and it keep getting me this error:
System.DirectoryServices.DirectoryServicesCOMException
Hresult=0x80072032 Message=Invalid distinguished name (DN) syntax specified
Line: Dim searchResults As Search...
Public Class Form1
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
Dim managerID As String
managerID = mngID.Text
Dim employeeID As String
employeeID = empID.Text
Dim emptybox
emptybox = mngID.Text.Length
If emptybox < 8 Then
MsgBox("ManagerID Inválido")
End If
Dim emptybox2
emptybox2 = empID.Text.Length
If emptybox2 < 8 Then
MsgBox("EmployeeID Inválido")
End If
If emptybox = 8 Then
Dim domain = New PrincipalContext(ContextType.Domain)
Dim user = UserPrincipal.FindByIdentity(domain, managerID)
Dim userDN
userDN = user.DistinguishedName
Dim ADEntry As New DirectoryEntry
ADEntry.Path = "LDAP://domain/CN:Users;DC:domain"
Dim Groups As New Collection
Dim mySearcher As DirectorySearcher = New DirectorySearcher(ADEntry)
Dim arrList As New ArrayList()
mySearcher.Filter = "(&(ObjectClass=user)(DistinguisedName=" & userDN & "))"
mySearcher.PropertiesToLoad.Add("MemberOf")
Dim searchResults As SearchResultCollection = mySearcher.FindAll()
If searchResults.Count = 0 Then
MsgBox("ManagerID inválido2")
End If
If searchResults.Count > 0 Then
Dim group As New DirectoryEntry(searchResults(0).Path)
For Each member As Object In group.Properties("MemberOf")
groupbox.Items.Add(member)
Next
End If
End If
End Sub
Your Error
Error 0x80072032 - ERROR_DS_INVALID_DN_SYNTAX
An invalid 'dn' syntax has been specified
Here's something to get you going.
Example VB Script To Connect to Active Directory
Imports System
Imports System.Data
Imports System.Linq
Imports System.IO
Imports System.DirectoryServices
Imports System.DirectoryServices.AccountManagement
Imports System.DirectoryServices.ActiveDirectory
Imports System.Security
Imports System.Security.Permissions
Imports System.Text
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Function EnumerateDomains() As ArrayList
Dim alDomains As New ArrayList()
Dim currentForrest As Forest = Forest.GetCurrentForest()
Dim myDomains As DomainCollection = currentForrest.Domains
For Each objDomain As Domain In myDomains
alDomains.Add(objDomain.Name)
Next
Return alDomains
End Function
Public Function EumerateDomainUsers() As ArrayList
Dim domainUsers As New ArrayList()
Dim usr As String
'Dim fqdns As String = DropDownList1.SelectedItem.ToString()
Dim fqdns As String = DropDownList1.SelectedItem.Text
Dim adStrng As String = "LDAP://" & fqdns
Dim adEntry As DirectoryEntry = GetObject(adStrng)
Dim searcher As DirectorySearcher = New DirectorySearcher(adEntry)
searcher.Sort.PropertyName = "cn"
Dim results As SearchResultCollection
Dim result As SearchResult
searcher.PropertiesToLoad.Add("cn")
results = searcher.FindAll
For Each result In results
usr = result.GetDirectoryEntry().Properties("cn").Value
domainUsers.Add(usr)
Next
Return domainUsers
End Function
There is a spelling mistake and should be "DistinguishedName" instead of "DistinguisedName":
mySearcher.Filter = "(&(ObjectClass=user)(DistinguishedName=" & userDN & "))"

referencing a dll in a windows service

I wrote an OPC client using interop.opcautomation.dll. I wrote it as a windows form in vb 2010 express. everything is currently working well. I wanted to make it a windows service though. The problem I am having is that it will not connect to the opc server when I run the service. I get the following exception "Object reference not set to an instance of an object.- OPC Connect Error" I get the exception at the end of the code where I am trying to connect. Below is the code. Thanks for any input, it is appreciated.
Imports System.ServiceProcess
Imports System.Threading
Imports System.Text
Imports System.Windows.Forms
Imports System
Imports System.IO
Imports System.IO.File
Imports System.Net
Imports OPCAutomation
Public Class Service1
Inherits System.ServiceProcess.ServiceBase
Dim WithEvents OPCServer As OPCAutomation.OPCServer
Dim WithEvents ConnectedGroup As OPCAutomation.OPCGroup
Dim Batch As String
Dim Group As String
Dim Press As String
Dim Line As String
Dim sWidth As String
Dim sHeight As String
Dim sBifold As String
Dim sCore As String
Dim StartUp As Integer
Dim iHandle As Integer
Dim sError As String
Dim ItemIds(60) As String
Dim ServerHandles As Array
Dim ClientHandles(60) As Integer
Dim ServerErrors As Array
Dim SnapServerURL As String = "snapserver"
Private trd As Thread
Private Stopping As Boolean = False
Private StoppedEvent As New ManualResetEvent(False)
Protected Overrides Sub OnStart(ByVal args() As String)
EventLog.WriteEntry("PressControlService in OnStart.")
trd = New Thread(AddressOf ServiceMain)
trd.IsBackground = True
trd.Start()
End Sub
Protected Overrides Sub OnStop()
EventLog.WriteEntry("PressControlService in OnStop.")
Me.Stopping = True
Me.StoppedEvent.WaitOne()
End Sub
Private Sub ServiceMain()
Dim strOPCServerName As String
Dim strOPCServerNode As String
Dim strOPCGroupName As String
Dim i As Integer
StartUp = 0
strOPCServerName = "Kepware.KEPServerEX.V5"
strOPCServerNode = ""
strOPCGroupName = "MyGroup"
Try
Dim OPCServer As New OPCAutomation.OPCServer
Catch ex As Exception
EventLog.WriteEntry(ex.Message & " - New OPC Server")
End Try
Try
OPCServer.Connect(strOPCServerName, strOPCServerNode)
Catch ex As Exception
EventLog.WriteEntry(ex.Message & "- OPC Connect Error")
End Try
End Sub
End Class

How can I get the events for one day (Google calendar Api) using TimeMax and TimeMin in net?

I have a code for get a event list of calendar but retrieves ALL events. How can I get the events for just ONE day?
Here is the code that Im using:
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports System.Collections.Generic
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.Data.Event
Imports Google.Apis.Util.Store
Imports Google.Apis.Calendar.v3.EventsResource
Imports System.Threading
Public Class Form1
Dim scopes As IList(Of String) = New List(Of String)
Dim service As CalendarService
Dim initializer = New BaseClientService.Initializer
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
Dim service As CalendarService
Try
scopes.Add(CalendarService.Scope.Calendar)
Dim Secrets = New ClientSecrets()
Secrets.ClientId = "CLIENT ID"
Secrets.ClientSecret = "CLIENT SECRET"
Dim scope = New List(Of String)
scope.Add(CalendarService.Scope.Calendar)
Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scopes, "xxxxxxxxxxx#developer.gserviceaccount.com", CancellationToken.None).Result()
Dim initializer = New BaseClientService.Initializer
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "APP NAME"
service = New CalendarService(initializer)
Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items
Dim requeust As ListRequest = service.Events.List("MY EMAIL")
Me.DataGridView1.DataSource = requeust.Execute.Items
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Try to add your searching range with these few lines of code
requeust.TimeMax = Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK")
requeust.TimeMin = "2014-12-01T16:00:00" 'changing the time whenever you want
I think it's work :)

Testing in Visual Basic with structures

I have a VS2012 Visual Basic.NET application and am wanting to create some unit tests for this application.
In my application, I have a module that contains the following structure:
<Serializable()> Public Structure MediaItem
Dim longMediaID As Long
Dim MediaObject As WMPLib.IWMPMedia
Dim FileInfoObject As FileInfo
Dim stringGenre As String
Dim stringMediaDuration As String
Dim doubleMediaLength As Double
End Structure
How do I 'Import' the above MediaItem structure so that I can do some Unit Testing using this structure? Currently, the TestClass cannot 'see' this structure.
UPDATE
This structure is custom made by myself. It is not actually in a class, it is in a module.
UPDATE 2
Here is the module code:
Imports System.IO
Namespace modCanMediaStructures
Module modCanMediaStructures
<Serializable()> Public Structure MediaItem
Dim longMediaID As Long
Dim MediaObject As WMPLib.IWMPMedia
Dim FileInfoObject As FileInfo
Dim stringGenre As String
Dim stringMediaDuration As String
Dim doubleMediaLength As Double
End Structure
<Serializable()> Public Structure MediaPlayList
Dim stringMediaPlayListName As String
Dim stringMediaPlayListDescription As String
Dim stringMediaPlayListComments As String
Dim mediaItemList As List(Of MediaItem)
Dim stringPlayListDuration As String
Dim doublePlayListDuration As Double
Dim booleanShuffle As Boolean
Dim booleanLoop As Boolean
End Structure
Public Structure genreItem
Dim stringGenreName As String
Dim longGenreCount As Long
Dim doubleGenreDuration As Double
End Structure
<Serializable()> Public Structure ScheduleItem
Dim stringItemName As String
Dim stringItemPlaylist As String
Dim stringItemDuration As String
Dim stringItemComments As String
Dim doubleItemDuration As Double
Dim booleanStartDateIsDerivedFromEndOfOtherScheduleItem As Boolean
Dim stringScheduleItemThatStartDateIsDerivedFrom As String
Dim dateItemStartDateTime As Date
Dim dateItemEndDateTime As Date
Dim booleanEndDateIsDerivedFromPlayListDuration As Boolean
End Structure
End Module
End Namespace
In my main form, I declare a variable as follows:
Dim testMediaItem As modCanMediaStructures.MediaItem
After importing the following statement:
Imports modCanMediaStructures
This works. However, when I do the same statement in the UnitTest test, the following error occurs:
Type 'modCanMediaStructures.MediaItem' is not defined
Here is my code:
Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports CanMediaPlayer
Imports modCanMediaStructures
<TestClass()> Public Class MediaListTests
<TestMethod()> Public Sub TestaddMediaItemToList()
Dim myStructure As New modCanMediaStructures.MediaItem
End Sub
End Class
I believe that this is happeneing because the UnitTest Project cannot actually 'see' the code in the other solution files.
May I please have some help to get this working?

RenderControl for radiobuttonlist using class not working vb.net

I built a simple class
Imports Microsoft.VisualBasic
Imports System.IO
Public Class buildcntrl
Function buildcontrol() As String
Dim SB As New StringBuilder()
Dim SW As New StringWriter(SB)
Dim o As New HtmlTextWriter(SW)
Dim d As New RadioButtonList
d.Items.Add("True")
d.Items.Add("False")
d.RenderControl(o)
Return SB.ToString()
End Function
End Class
When I use the class from an asp.net page like this
Dim t As New buildcntrl
Response.Write(t.buildcontrol)
it works fine but when use a class to call the same class I receive an error
System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.UI.WebControls.RadioButtonList.Render(HtmlTextWriter writer)
When I debugged the problem it throws an error when trying to execute d.RenderControl(o)
This works fine for all the other objects except for RadioButtonList