How to open two applications using one button? - vb.net

Hi sorry i am beginner in vb.net Can you please help me how to open 2 applications using 1 button and what code should i use?
I already try this code in 1 application
shell("C:\Windows\System32\calc.exe") and it's work.

This really depends on what you'd like to be done when clicking the button.
If you want the button to open two applications at the same time, then you could just call 2 Process.Start() functions.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim p As Process = Process.Start("PATH for first application.")
Dim x As Process = Process.Start("PATH for second application.")
End Sub
However, if you'd like to run two separate applications and have the second application wait until the first is closed then you can use the .WaitForExit() method. For example:
Private Sub Button1_Click(sender as Object, e As EventArgs) Handles Button1.Click
Dim p As Process = Process.Start("PATH for first application.")
p.WaitForExit()
Dim x As Process = Process.Start("PATH for second application.")
x.WaitForExit()
End Sub

Related

How can I write data into a row in Virtual Studio? (MS Access Database file"

I would like to make a small application what can make easier my work.
I have to make one ordering process some labels where I have a plan and from the plan I have to one excel list making with the labelnames what will be printed by the Manufacturer. We have a lot of type of the label (names) but they are fixing. (160 pieces differentnames).
So I make this always if I get a new plan then I make new label-list. I do it alway by hand cell by cell.. Sometime I have to filling out 400 cell for one plan... I don’t have a lot’s of time to this..
So I started making my first Windows app with Visual Studio(in Windows From – Visual Basic).
I found some cool video, so I already have the „basics”.
I connected one MS Access database to my Project where I would like to store the datas.
And now i have trouble.. I have some Comboboxes. I would like to choose some cases and then I would like to update the database where the rows will be filled with the correct values. If its done, i can this exporting to excel and sendig forward to the Manufacturer.
I have a textbox where I write the Plan name (it linked to the database first Column)
And then:
So the Combobox1 have Sektor A, B, C, D ,E, F (six value)
The Combobox2 have 09RRU, 09RSU, 18RRU ... empty - (eight value)
The Combobox3 have 21RRU, 21RSU, 26RRU ... empty - (eight value)
The Combobox4 have ja or nein (only two value)
and so on.. I have 8 Combobox.
My Idea:
If I select the Sektor A and 09RRU , the another two is empty and nein, then I click on the Update button I would like to get back in database 09.SekA1, 09.SekA2, AISG.SekA
If I select the Sektor A and 09RRU and 21RRU and ja, then after click Update, I would like get 09.SekA1, 09.SekA2, 21.SekA1, 21.SekA2, 09.21.SekA1, 09.21SekA2, AISG.09.21.SekA
….
I can every type of labels line by line writing if needed, I think I have to do this. I don’t think so can I dynamic Arrays making which can the different String e.g. ( Text (09) & Text (.SekA) & Text(1)) creating. I just now started the VB..
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.SelectedIndexChanged
SektorForm1()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
End Sub
Private Sub SektorForm1()
BEschriftungenDataSet.Standort.RRU18Column = "18.SekA1"
BEschriftungenDataSet.Standort.RRU21Column = "18.SekA2"
BEschriftungenDataSet.Standort.RRU26Column = "AISG.18.SekA"
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.StandortTableAdapter.Fill(Me.BEschriftungenDataSet.Standort)
ComboBox1.SelectedIndex = 5
ComboBox2.SelectedIndex = 3
ComboBox3.SelectedIndex = 3
ComboBox4.SelectedIndex = 1
ComboBox5.SelectedIndex = 1
ComboBox6.SelectedIndex = 1
ComboBox7.SelectedIndex = 1
ComboBox8.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error GoTo SaveErr
StandortBindingSource.EndEdit()
StandortTableAdapter.Update(BEschriftungenDataSet.Standort)
MessageBox.Show("Saved")
End Sub
Could some one for me Helping what is wrong in my code? I tried some data inserting to tha database when I choose someting in Combobox1 but it doesn't work..
I get failures: BC30526 Property'RRU18Column' is 'ReadOnly' and BC30311 Value 'String' cannot be converted to 'DataColumn'..
And giving some help how I sould staring building up my cases to my Combobox chooses..
Thanks guys

Simulate web search using the WebBrowser control

I am trying to write a program that simulates a simple browser search in www.google.com using the WebBrowser control. I'm really just wanting to simulate internet activity.
I came up with the idea of using a loop to send a number to the google search box and then pressing enter.
The line WebBrowser1.Document.GetElementById("q").SetAttribute("value", i) successfully sends each number in the loop to the google search box, but the next line WebBrowser1.Document.GetElementById("btnK").InvokeMember("Click") won't initiate the google search button. I don't get any errors.
Does anyone have any ideas why WebBrowser1.Document.GetElementById("btnK").InvokeMember("Click") doesn't work?
Also I've noticed that when I run this code and then launch Internet Explorer, the code stops. Does anyone have any ideas on this as well?
Most grateful for any help!
Regards
George
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call LoadBrowser()
End Sub
Private Sub LoadBrowser()
WebBrowser1.Navigate("http://www.google.com/")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Send search string 'i' to browser n times
Dim i As Integer
For i = 1 To 100
' Browser search
WebBrowser1.Document.GetElementById("q").SetAttribute("value", i)
WebBrowser1.Document.GetElementById("btnK").InvokeMember("Click")
' Pause n seconds before next loop
For x As Integer = 0 To 5 * 100 ' Pause for 5 seconds
Threading.Thread.Sleep(10)
Application.DoEvents()
Next
Next
End Sub
Ok, working off the example you have given us.
Try this.
Imports WindowsInput '' <---------
''' <summary>
''' This program will run quick slow, would be best to use another thread for it, I'll leave that to you.
''' </summary>
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("www.google.com.au")
End Sub
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SIM = New InputSimulator() ''Use NuGet package manager and search for Input Simulator at Import it at the top
For i = 0 To 100
WebBrowser1.Document.GetElementById("lst-ib").InvokeMember("Click") ''this will click on googles searchbox
WebBrowser1.Document.GetElementById("q").InnerText = i
Await Task.Delay(500) ''This will delay your code so you can see what is in the searchbox, I prefer this over Thread.Sleep, each to their own I guess.
WebBrowser1.Document.GetElementById("q").InvokeMember("Click") ''This will click on googles search box to get the delete simulator ready.
SIM.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.DELETE) '' This will delete whatever is in the searchbox since your original code was doing this and you didn't complain about it
Next
WebBrowser1.Document.GetElementById("lst-ib").InvokeMember("Click") ''ONCE the loop as completed it will click on googles search box
SIM.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN) '' Another keypress for the enter key (MAY NOT WORK DEPENDING IF YOU HAVE CLICK OFF THE WEBBROWSER CONTROL) maybe you can tab back to it?
'WebBrowser1.Document.GetElementById("sblsbb").InvokeMember("Click") ''if the above line doesn't work
End Sub
End Class
Sorry for the long comments, I'm just trying to help you understand what the code is doing and the possible errors you may or may not encounter along with possible fixes and or work arounds.Good luck.

Visual Basic - Create an application to pick a number

Hye,
I'm new with Visual Basic and i had a few problems.
I've create a new Windows Forms Application in Visual Basic. Using one TextBox and two Button. The TextBox for displaying the number. One button for Generate and another one for Help.
I want to create a simple application that will pick one of the listed number instead of generating it.
Example :
Each time I click on the Generate button, it will pick either 14412GG or TE921W or 13123SA only. The number will appear in the TextBox.
Evertime i click on Help button, a windows will pop-up with help messages. Multiple line messages.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
**This is for Generate button**
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
**This is for Help button**
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
**This is to display the number**
End Sub
End Class
Save those 3 values in an arrayList, create a Random class.
private static ArrayList values1 = new ArrayList{"14412GG","TE921W","13123SA"};
Random rnd = new Random();
int r = rnd.Next(values1.Count);
(string)values1[r]
Display the string when Generate button clicks.
TextBoxVariable.Text = (string)values1[r];
Use Messagebox.Show to display the help message.
MessageBox.Show(""Help message line1" + Environment.NewLine + "Help message line2";");
Hope this helps!
Here is what you need :
'Button 1
Dim pool As String = "ABCDEFGHIJKLMNOPQURSTUVWXYZ1234567890"
Dim cc As New Random
Dim count = 0
While count <= 6
textbox1.text = cc.Next(0, pool.Length)
'button2
msgbox("message line1" + vbnewline + "message line2.")
i hope it be useful to you .

VB.Net trial application

how can i make my application goes to function after certain usage
like if i click an button 10 times, then button is disabled
just like trial program,
so far, i can do that on run-time only,
how can i make it count clicks without using Registry?
my program is very simple: convert strings to Base64
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = Convert.ToBase64String(New System.Text.ASCIIEncoding().GetBytes(TextBox1.Text))
End Sub
You probably need Settings. Easily Save and Retrieve Application and User Settings in VB.NET or C# Apps. First create ClickCouter of type integer with value 0 in settings (see the article).
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.ClickCouter +=1
My.Settings.Save()
If My.Settings.ClickCouter>=10 then Button1.Enabled = False
End Sub
It is necessary to check ClickCouter also in Form_Load. The value is stored in a file in a user profile so the solution is not too "hacker proof" (but is fool proof :-D ).

Form_Load doesn't execute in application

I am new to Visual Basic. I have installed Microsoft Visual Studio 2010. Created a new Windows Form Application. As an example, I made a simple program which will ask the end user to input 2 numbers and allow them to either add them or subtract the second number from the first one and display the output in a Textbox.
Now, I added another Subroutine which would be executed automatically when the Windows Form loads. This would calculate the width of the output Textbox and the Form Width and display at the bottom.
This is how the code looks like right now:
Public Class Form1
' Run this Subroutine initially to display the Form and Text box width
Private Sub Form_Load()
Label5.Text = TextBox3.Width
Label7.Text = Me.Width
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a + b
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a - b
End Sub
End Class
While everything works correctly for the addition and subtraction, it does not display the Form and output Textbox width in the Windows Form.
I think, Form_Load() is not executing properly.
I also tried, Form_Activate() but that did not work either.
Once I am able to do this, I would like to extend this concept to resize the output Textbox along with the Form resize. However, for the purpose of understanding I wanted to see if I can execute Form_Load() successfully.
Thanks.
Form_Load doesn’t execute. For now, it’s just any other method. In order to tell VB to make this method handle the Load event, you need to tell it so:
Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Loasd
Label5.Text = TextBox3.Width
Label7.Text = Me.Width
End Sub
(And add the required parameters for the event.)
A few other remarks:
Ensure that Option Strict On is enabled in your project options at all times. This will make the compiler much stricter with your code and flag more errors. This is a good thing since these errors are potential bugs. In particular, your code is very lax with conversions between different data types, these should be made explicit.
Initialise variables when you declare them, don’t assign a value in a separate statement. That is, write this:
Dim a As Integer = Integer.Parse(TextBox1.Text)
(Explicit conversion added as well.)
If you want to make a control fill the form, you can just set its Dock property appropriately in the forms editor, instead of having to program this manually.
You need to add the Handle so the app executes it automatically:
Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
'...
End Sub