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
Related
Getting the error "Event 'Load' cannot be found" referring to "Handles MyBase.Load" Please see attached code. Any help much appreciated!
I have many other applications set up the same way and they all work. However, these were in an older version of Visual Studio.
Option Explicit On
Option Strict On
Imports System, System.IO
Imports System.Text
Public Class Form1
Private Sub cleanXMLDialog_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
Main()
End
End Sub
Public Sub Main()
Dim directories() As String = Directory.GetDirectories("C:\")
Dim files() As String = Directory.GetFiles("C:\", "*.dll")
DirSearch("c:\")
End Sub
Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String
Try
For Each d In Directory.GetDirectories(sDir)
For Each f In Directory.GetFiles(d, "*.xml")
'Dim Response As String = MsgBox(f)
Debug.Write(f)
Next
DirSearch(d)
Next
Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
End Class
Load should happen without this error.
This is the class declaration:
Public Class Form1
It looks like you intend this to inherit from a windows Form type, but there's nothing here to make that happen.
You may want this:
Public Class Form1 Inherits System.Windows.Forms.Form
but even this is unlikely to really accomplish anything. It's not enough just to inherit from the Form type if you don't have any controls are properties set and don't ever show the form.
Did you accidentally create a Console or Class Library project when you mean to create a WinForms project?
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?
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
Quick question about a windows service, I've added a setup project for my Windows service, and ive added a custom dialog to it, with 4 text fields, but my question is how to i get these informations/variables?
Ive also added an installer for the windows service also, and afterwards the setup project, with the custom dialog.
The informations is something like database connection strings, and so on - so just string values.
This is my code for the "project installer" . the installer item ive added for the windows serive if you wanted to see it.
Imports System
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.Runtime.InteropServices
Public Class ProjectInstaller
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
My.Settings.TestSetting = Context.Parameters.Item("PathValue")
#If DEBUG Then
Dim ServicesToRun As ServiceBase()
ServicesToRun = New ServiceBase() {New tdsCheckService()}
ServiceBase.Run(ServicesToRun)
#Else
Dim listener As New tdsCheckService()
listener.Start()
#End If
End Sub
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Dim regsrv As New RegistrationServices
regsrv.RegisterAssembly(MyBase.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase)
End Sub
Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
MyBase.Uninstall(savedState)
Dim regsrv As New RegistrationServices
regsrv.UnregisterAssembly(MyBase.GetType().Assembly)
End Sub
Private Sub ServiceProcessInstaller1_AfterInstall(sender As Object, e As InstallEventArgs) Handles ServiceProcessInstaller1.AfterInstall
End Sub
Private Sub ServiceInstaller1_AfterInstall(sender As Object, e As InstallEventArgs) Handles ServiceInstaller1.AfterInstall
End Sub
End Class
You should eb able to access them using the Context object.
'Get Protected Configuration Provider name from custom action parameter
Dim variableName As String = Context.Parameters.Item("dialogSettingName")
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
I have been trying to build a game bot in vb.net. One of the main problems is getting access to the text the game prints on the screen so I have been trying to hook the games calls to the windows api drawtext and textout functions. I have been hunting for examples of how to set up a hook in vb.net for a long time without any luck. I have found it impossible to translate examples in old school vb, C++, and C#. For convenience's sake I would like to use the freely available deviare and/or easyhook libraries. Can anyone help?
I found working vb.net code based on the deviare hooking dlls buried in the deviare forums.
please remember to add all 6 deviare references found under the com tab of the add references page of visual studio after installing deviare.
Public Class Form1
'To print to a textbox in the gui you will have to call textbox.invoke
Private _mgr As Deviare.SpyMgr
Private WithEvents _hook As Deviare.Hook
Private _proc As DeviareTools.IProcess
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_mgr = New Deviare.SpyMgr()
_hook = _mgr.CreateHook("user32.dll!ShowWindow")
_hook.Attach(_mgr.Processes)
_hook.AddProcessFilter(0, "notepad", 1)
_hook.Hook()
Private Sub OnFunctionCalled(ByVal proc As DeviareTools.IProcess, ByVal callInfo As DeviareParams.ICallInfo, ByVal rCall As Deviare.IRemoteCall) Handles _hook.OnFunctionCalled
Debug.Print("Caught function call in " & proc.Name) 'view in imediate window
End Sub
end class
I am in the process of converting the Easyhook c# code into vb.net. At the moment I am getting the error code 5 message and the hooked application is being closed by windows eg to help protect your computer etc. If anyone could help with this then I would be grateful. What I have so far is...
Imports EasyHook
Imports System
Imports System.Diagnostics
Imports System.Runtime.Remoting
Imports System.Windows.Forms
Imports System.Security
Imports System.Security.Principal
Namespace FileMon
Friend Class Program
' Methods
Public Shared Sub Main(ByVal args As String())
Dim result As Integer = 0
If ((args.Length <> 1) OrElse Not Integer.TryParse(args(0), result)) Then
Console.WriteLine()
Console.WriteLine("Usage: FileMon %PID%")
Console.WriteLine()
Else
Try
Try
Console.WriteLine("Registering Application")
Console.WriteLine()
Config.Register("A FileMon like demo application.", "FileMon.exe", "FileMonInject.dll")
Catch exception1 As ApplicationException
Console.WriteLine("This is an administrative task! " & exception1.ToString)
Console.WriteLine()
Process.GetCurrentProcess.Kill()
End Try
Console.WriteLine("Creating IPC Server")
Console.WriteLine()
RemoteHooking.IpcCreateServer(Of FileMonInterface)(Program.ChannelName, WellKnownObjectMode.SingleCall)
RemoteHooking.Inject(result, "FileMonInject.dll", "FileMonInject.dll", New Object() {Program.ChannelName})
Console.WriteLine("Injected")
Console.WriteLine()
Console.ReadLine()
Catch exception As Exception
Console.WriteLine("There was an error while connecting to target:" & exception.ToString)
End Try
End If
End Sub
' Fields
Private Shared ChannelName As String
End Class
End Namespace
and
Imports System
Namespace FileMon
Public Class FileMonInterface
Inherits MarshalByRefObject
' Methods
Public Sub IsInstalled(ByVal InClientPID As Integer)
Console.WriteLine("FileMon has been installed in target " & InClientPID)
End Sub
Public Sub OnCreateFile(ByVal InClientPID As Integer, ByVal InFileNames As String())
Dim i As Integer
For i = 0 To InFileNames.Length - 1
Console.WriteLine(InFileNames(i))
Next i
End Sub
Public Sub Ping()
End Sub
Public Sub ReportException(ByVal InInfo As Exception)
Console.WriteLine(("The target process has reported an error:" & InInfo.ToString))
End Sub
End Class
End Namespace
easyhook libraries
Try to use the EasyHook library