Call a form in another form with button click [closed] - vb.net

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to open FrmNovaRegra with a button click in another form.
I already tried the basic "Dim form as new FrmNovaRegra" and "form.show()" it didnt work, how can i open it? The code of the Form that i want to open is in the next line:
Public Class FrmNovaRegra
Private regras As BServices.NovaRegra
'Private MyDictionary As New Dictionary(Of String, List(Of String))
Public Sub New(ByVal cls As BServices.NovaRegra)
InitializeComponent()
Me.regras = cls
End Sub

Your form needs it's parameter, because there are no other overloads. There are many ways you can correct this.
If you have the cls As BServices.NovaRegra you can create the form using:
Dim form as new FrmNovaRegra(cls)
If you want to create a new one on the fly, that's also possible:
Dim form as new FrmNovaRegra(New BServices.NovaRegra())
This new cls might need some parameters too, I'm not familiar with this class.
Another way to work around this would be to add a new overload which doesn't need a parameter, but your form looks like it needs the cls, so let me know if you need more explanations for this one as a comment.

Related

vb.net - managementeventwatcher not capturing a second instance of any process [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I've got an application which is watching over executed processes on a device using a managementeventwatcher, like so...
Dim wmiq As String = "SELECT TargetInstance FROM __InstanceCreationEvent WITHIN .025 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name like '%'"
Dim scope As String = "\\.\root\CIMV2"
startProcWatcher = New ManagementEventWatcher(scope, wmiq)
AddHandler startProcWatcher.EventArrived, AddressOf ProcessStarted
startProcWatcher.Start()
And my handler (just logging for now)...
Private Shared Sub ProcessStarted(sender As Object, e As EventArrivedEventArgs)
Dim targetinstance As ManagementBaseObject = e.NewEvent.Properties("TargetInstance").Value
Dim processname As String = targetinstance.Properties("Name").Value.ToString
Dim exepath As String = targetinstance.Properties("ExecutablePath").Value.ToString
Dim thisexeinfo As New FileInfo(exepath)
If Not ProcessExclusionList.Contains(processname) Then
MyApp.DoLogging("Process Started : " & processname & "(" & exepath & ")")
End If
End Sub
This works a treat and I successfully capture the event creation with minimal resource usage (as opposed to Process.GetProcesses(), which was hammering resource!), however I notice that if a second instance of the same process is run, I do not get an event on the second execution.
For example, I can run calculator and my watcher will log calc.exe was executed with all the associated properties. If I then open a second calculator my watcher sees nothing.
I'm guessing I need to modify the WMI query slightly, but my WMI is limited and I'm not struggling.
Can anyone help out with this?
TIA
The code I posted actually works perfectly for multiple instances of a process, however when I was testing, I used calc and it turns out calc spawns multiple instances of itself all under the same process.
repeating the test with any other executable/process results in the desired behavior.

How to auto-close another panel upon manually closing one panel [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have 2 forms in a program in which i want to pass the input from form 1 to form 2. I want to close form 1 after form 2 is opened so that the program stops running when all forms stop showing up on the screen; However, i won't be able to close form 1 if i want to pass the value into form 2 (If i can in classes, please let me know) so i hide it after form 2 is open. This, consequently, results in the program running forever even after form 2 is closed, form 1 staying hidden. I want to close form 1 whenever the user closes form 2 using the Close (X) button. Any idea how to implement this? Also, i have already set the program to 'When the last form closes'.
Also, i have already set the program to 'When the last form closes.
You almost there.
As I understand, you are keeping the Form1 opened but hidden to access it's members and/or objects from Form2 and that is the only reason why you are keeping Form1 opened.
You could solve this problem by creating a parameterized constructor in Form2 to pass whatever you need from Form1 before you close it.
Sub New(obj1FromForm1 As obj1Type, obj2FromForm1 As obj2Type, ....)
Me.New 'Don't forget this!
'Update Form2 accordingly...
End Sub
Where the obj1Type, obj2Type are the types of the passed objects. (Integer, String, ...etc.)
You could also declare class variables to refer to these objects if you need to access theme later somewhere in your Form2's code.
Private obj1 As obj1Type
Private obj2 As obj2Type
Sub New(obj1FromForm1 As obj1Type, obj2FromForm1 As obj2Type, ....)
Me.New
obj1 = obj1FromForm1
obj2 = obj2FromForm1
End Sub
Now back to your Form1. Make sure that you Close it once you create Form2 using its new parameterized constructor and showing it.
Private Sub Form2Caller()
Dim f As New Form2(obj1 As obj1Type, obj2 As obj2Type, ....)
f.show
Me.Close() 'and not Me.Hide nor Me.Visible = False.
End Sub
One last point. Don't pass disposable objects to Form2 that will be disposed by Form1 when you close it.
Good luck.

Write does not produce a value issue [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Alright, I've managed to get a string containing HTML content inside of it, but I need to get into an HTMLDocument for parsing.
I've tested the following code, and I've been unable to get it to work through any of the variations I've tried.
Dim webclient As New System.Net.WebClient
Dim result As String = webclient.DownloadString(link)
Dim htm As HtmlDocument
htm = htm.Write(result)
Dim sDD As Object
sDD = htm.GetElementById("tag-sidebar")
Dim IDD As Object
IDD = htm.GetElementById("highres")
Currently it is telling me that htm = htm.Write(result) does not produce a value, so I'm sort of stumped.
I'm Currently using Microsoft Visual Studio 2013 Professional
The error just indicates that the Write method does not produce a value. In VB-speak that means Write is a Sub, not a Function.

I am looking for someone that has patience to help me understand VB terminology and the hows and whys [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Some basic terms that interchange that i have no one to ask, and i guess to stupid to understand my self.
Method,procedure, parameters, operation, operator, function, instaniantiantion, separator,
I really need help!
I really need to see a long module of code that every thing is broken down for a stupid guy like me.
For instance break this down, not what it does but how it does it, and the terminology. Word by word,, all dots, = parentheses, the passes the gets all that stuff, I know that this is simple to everyone else. And i will need more help until i get it... Maybe we can work something out. Some one that is available,,, that knows this stuff backwards and forwards and has the patience, that would like to help me... I have tried books i just do not get it HELP
Public Class ViewerForm1
Private Sub btnSelectPicture_Click(sender As Object, e As EventArgs) Handles btnSelectPicture.Click
'Show the open dialog box.
If ofdSelectPicture.ShowDialog = DialogResult.OK Then
'Load the picture in the box.
btnSelectPicturePicture.Image = Image.FromFile(ofdSelectPicture.FileName)
'Show the name of the file in the forms caption.
Me.Text = "Picture Viewer "(ofdSelectPicture.FileName)
'Close the window at exit the application.
Me.Close()
End If
End Sub
Private Sub btnSelectPicture_Click(sender As Object,
e As EventArgs) Handles btnSelectPicture.Click
This line declares a default Click event handler and binds button's click event to it.
If ofdSelectPicture.ShowDialog = DialogResult.OK Then
Opens an open file dialog and if user presses OK, processes the result.
btnSelectPicturePicture.Image = Image.FromFile(ofdSelectPicture.FileName)
Loads the image into the button, based on the file previously selected.
Me.Text = "Picture Viewer "(ofdSelectPicture.FileName)
Line does not make sense and probably won't compile. Missing a & or a + for string concatenation. Assuming it had one, it would assign a form caption/title to a constant value + a file name that was selected.
Me.Close()
Closes the current form.

Deduplicate Text file VB.NET [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a large text file with over 100k of lines. Some of the lines are duplicates. I would like to be a to dedupe these entries before processing them. I am using visual basic 2010 Express to write this.
Text file example:
132165
165461
646843
654654
321358
132165
165461
I want to dedupe these entries before processing them
You can use a HashSet(Of T)
Dim nodupes As New HashSet(Of String)(File.ReadLines(path))
For Each str As String In nodupes
' no duplicate here '
Next
Edit Since a HashSet(Of T) does not guarantee to preserve the insertion order you can use following code if you need to ensure this order:
Dim nodupeSet As New HashSet(Of String)
Dim nodupes = From line In File.ReadLines(path)
Where nodupeSet.Add(line)
For Each str As String In nodupes
' no duplicate here '
Next