VB and digiCamControl standalone library - vb.net

I am trying to build a simple VB application using the digicamControl standalone library.
I am facing an issue where I cannot initialize the cameras connected to my PC.
Here is my sample code:
Imports CameraControl.Devices
Public Class Form1
Public Property DeviceManager As CameraDeviceManager
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DeviceManager = New CameraDeviceManager()
DeviceManager.UseExperimentalDrivers = True
DeviceManager.DisableNativeDrivers = False
DeviceManager.ConnectToCamera()
For Each cameraDevice As ICameraDevice In DeviceManager.ConnectedDevices
TextBox1.AppendText(cameraDevice.DisplayName)
Next
End Sub
End Class
Could you please advise me what I am doing wrong?

Related

Convert the program interface to another language interface VB.NET

What is wrong with the code to convert the program interface to another language interface? In Visual Basic .NET (Visual Studio 2019)
Imports System.Globalization
Imports System.ComponentModel
Public Class Form1
Private Sub ArButton_Click(sender As Object, e As EventArgs) Handles ArButton.Click
Languages.changelanguge("ar")
End Sub
Private Sub EnButton_Click(sender As Object, e As EventArgs) Handles EnButton.Click
Languages.changelanguge("en")
End Sub
End Class
Public Module Languages
Public Sub changelanguge(ByVal languge As String)
For Each obj As Control In Form1.Controls
Dim lang As ComponentResourceManager = New ComponentResourceManager(GetType(Form1))
lang.ApplyResources(obj, obj.Name, New CultureInfo(languge))
Next
End Sub
End Module
What is happening when you run the code? I was implementing this recently and the below link assisted a lot.
https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=netframework-4.8

VB - Find child form from parent

I am in a project with multiple form.
I create a TicTacToe form here :
Private Sub MenuTicTacToe(ByVal sender As Object, ByVal e As System.EventArgs)
Dim page As Form = New TicTacToe
page.Show(Me)
End Sub
Here is a TicTacToe form:
Public Class TicTacToe
Public opponent as String
'Some code where user set opponent
Public Function Receive(S As String)
if string = opponent
'Some code
End Function
End Class
I would like to call my function Receive in my main form
If i do:
TicTactoe.Receive(S)
It call a instance of Receive where opponent does not exist.
I would like to find the oppened form of TicTacToe and call Receive
Thanks
Comments in line
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
page.Receive("Joe")
End Sub
'A form level variable to hold a reference to the instance of TicTacToe
'Although vb.net can use default instances, you have created an explicit
'instance of TicTacToe so you need to keep a reference if you want to
'refer to this instance.
Private page As TicTacToe
Private Sub MenuTicTacToe(ByVal sender As Object, ByVal e As System.EventArgs)
page = New TicTacToe()
page.Show(Me)
End Sub
Partial Public Class TicTacToe
Inherits Form
Public opponent As String
'Functions must be declared as a Type
'If you do not need a return value use a Sub
Public Function Receive(S As String) As String
Dim someString As String = ""
If S = opponent Then
'Do something
End If
'There must be a return Value
Return someString
End Function
End Class
Use this to show the form
Dim page As TicTacToe
Private Sub MenuTicTacToe(ByVal sender As Object, ByVal e As System.EventArgs)
page = New TicTacToe
page.Show(Me)
End Sub
Then you can use
page.Receive(S)
Edit
To use multiple forms
For Each f As TicTacToe in Application.OpenForms().OfType(Of TicTacToe)
f.Receive (S)
Next
In C#, you'd need a new instance, but as you are in VB, the compiler already does that for you.
What you are currently doing, is creating a new instance of the TicTacToe form and showing it:
Private Sub MenuTicTacToe(ByVal sender As Object, ByVal e As System.EventArgs)
Dim page As Form = New TicTacToe
page.Show(Me)
End Sub
But you don't save that instance anywhere. Then, in your next piece of code, you are using a different instance, which is the static one created by the compiler:
TicTacToe.Receive(S) // TicTacToe is the static instance
Therefore, you end up calling two different instances, which explains why there is no opponent set.
To get around this problem, do not create a new instance. In your Private Sub MenuTicTacToe, just use the instance created by the compiler, and you won't have this problem, just like this:
Private Sub MenuTicTacToe(ByVal sender As Object, ByVal e As System.EventArgs)
TicTacToe.Show(Me)
End Sub
Hope this helps.

NSQ vb.net MessageHandler

I am trying to use this package in vb.net NsqSharp
There is a good code for it in C# but i need it in vb.net.
I got it to send a message to my NSQ server, but the problem is to get it.
But i get a error on consumer.AddHandler(New HandleMessage()) and i do not know if i declare the HandleMessage right.
Imports NsqSharp
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim producer = New Producer("127.0.0.1:4150")
producer.Publish("test-topic-name", Me.txt_tx.Text)
producer.Stop()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim consumer = New Consumer("test-topic-name", "channel-name")
consumer.AddHandler(New HandleMessage())
consumer.ConnectToNsqLookupd("127.0.0.1:4161")
consumer.Stop()
End Sub
Public Interface IHandler : End Interface
Public Sub HandleMessage(message As Message)
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MsgBox(msg)
End Sub
Public Sub LogFailedMessage(message As Message)
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MsgBox(msg)
End Sub
End Class
But i get a error on Implements IHandler
Lovely description of the problem, you can't get useful answers when you don't describe the exact error message you see. You did write the code wrong, VB.NET requires the Implements keyword on interface method implementations. You'd normally fall in the pit of success by letting the IDE generate these methods for you. As soon as you type "Implements IHandler" and press the Enter key, the IDE automagically adds the methods.
So there's probably something wrong with the library reference as well. Steps one-by-one:
Tools > Nuget Package Manager > Package Manager Console.
Type "Install-Package NsqSharp". Watch it trundle while it downloads and installs the package.
Put Imports NsqSharp at the top of the source file.
You should now end up with:
Public Class MessageHandler
Implements IHandler
Private Sub IHandler_HandleMessage(message As Message) Implements IHandler.HandleMessage
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MessageBox.Show(msg)
End Sub
Private Sub IHandler_LogFailedMessage(message As Message) Implements IHandler.LogFailedMessage
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MessageBox.Show(msg)
End Sub
End Class

Create a dll file to load image to form but get "System.NullReferenceException"

I created the following dll file to load image and draw image
Imports System.Drawing
Namespace GDI
Public Class ImageManager
Public Images As Dictionary(Of String, Image)
Public Sub LoadImage(Name As String, Path As String)
If Images.ContainsKey(Name) Then
Exit Sub
Else
Try
Dim i As Image = Image.FromFile(Path)
Images.Add(Name, i)
Catch ex As Exception
End Try
End If
End Sub
Public Sub RemoveImage(Name As String)
If Images.ContainsKey(Name) Then Images.Remove(Name)
End Sub
Public Sub DrawImage(Surface As Object, Name As String, Position As Point, Optional Size As Point = Nothing)
Try
If Images.ContainsKey(Name) Then
Dim G As Graphics = Surface.CreateGraphics
If Size.IsEmpty Then
G.DrawImage(Images(Name), Position)
Else
G.DrawImage(Images(Name), New Rectangle(Position.X, Position.Y, Size.X, Size.Y))
End If
End If
Catch ex As Exception
End Try
End Sub
End Class
End Namespace
I use the dll file in the form application to load the picture. I put both pictures in the project debug folder. But when I try to run the project. It gives me the ""System.NullReferenceException" in the dll file on
f Images.ContainsKey(Name) Then
Here is my code behind the form application:
Imports GFX.GDI
Public Class Form1
Private ImgMan As New ImageManager
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ImgMan.LoadImage("background", "Pic\background.jpg")
ImgMan.LoadImage("download", "Pic\downlaod.jpg")
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
ImgMan.DrawImage(Me, "runningman", New Point(0, 0), New Point(Me.Width, Me.Height))
End Sub
End Class
You have not initialized the Images dictionary in the code above. Edit the declaration as below:
Public Images As new Dictionary(Of String, Image)

inside class calling form1 sub

Hey all i am trying to call a public sub within a class that resides within my form1 code:
Public Class Form1
Public Shared objItem As ListViewItem
Class Server
Private Shared Sub StringMessageReceived(ByVal sender As Object, ByVal e As StringMessageEventArgs)
MsgBox("Received message: " & Convert.ToString(e.Message))
'Form1.ListView1.Items.Add(Convert.ToString(e.Message))
Call Form1.writeToLV(Convert.ToString(e.Message))
End Sub
End Class
Public Sub writeToLV(ByRef theStuff As String)
MsgBox(theStuff)
objItem = ListView1.Items.Add(theStuff)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.View = View.Details
ListView1.Columns.Add("Response", CInt(500))
End Sub
End Class
It sends the value over just fine but when it gets to putting it into the listview it never does?
Any pointers?
David
The most likely explanation is that the form that has been opened on the screen is not the default instance referenced by Form1 in the Server class.
I think that you need to restructure your code somewhat: if you are only going to have one instance of Form1, explicitly create the form and keep a reference to it in a global variable (i.e. g_Form1) rather than relying on the VB-provided default instance (assuming you are ever only going to have 1 instance of the form.
If you can have more than 1 instance of Form1, I would convert your internal Server static class to an Interface and when a new form is created, have it register itself with whatever mechanism is calling Server.StringMessageReceived.