vb.net error on something - vb.net

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Shell("CMD.exe")
SendKeys.Send("net user")("TextBox1.Text")("TextBox2.Text")
SendKeys.Send("{ENTER}")
End Sub
End Class
It says:
Error 1 Expression is not an array or a method, and cannot have an
argument list.
for SendKeys.Send("net user")

Glad that you have resolved, but trust me, this is not the correct way to work with CMD.exe from inside a NET app.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim pi = new ProcessStartInfo()
pi.FileName = "CMD.EXE"
pi.Arguments = "/K NET USER " + textBox1.Text + " " + TextBox2.Text
Process.Start(pi)
End Sub
ProcessStartInfo class
Process class

Related

Search to DataGridView ( showing record) selected record print vb.net

This is my code but it prints all records. I want to search a record and print crystalreport.
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'
Me.Patient_tblTableAdapter.Fill(Me.DoctorDataSet.patient_tbl)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PatienttblBindingSource.Filter = "(Convert(ID,'System.String') LIKE '" & TextBox1.Text & "%')"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rpt As New CrystalReport1
rpt.SetDataSource(DoctorDataSet)
Form2.CrystalReportViewer1.ReportSource = rpt
Form2.ShowDialog()
End Sub
End Class
try to use '*' instead '%' in like statement :
PatienttblBindingSource.Filter = "(Convert(ID,'System.String') LIKE '" & TextBox1.Text & "*')"

Save text on my.settings saved multiple times vb.net

i have start a new application to encrypt strings and save them on my settings the code its work fine but wen it save it save multiple times the same.
How can i do for save all the content from a listbox to my settings with out to repeat.
This is my code
Imports System.Text
Imports System.Security.Cryptography
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'My.Settings.md5_hashes.Clear()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim md5 As MD5 = System.Security.Cryptography.MD5.Create()
Dim inputBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
Dim hash As Byte() = md5.ComputeHash(inputBytes)
Dim sb As New StringBuilder()
For i As Integer = 0 To hash.Length - 1
sb.Append(hash(i).ToString("x2"))
Next
TextBox2.Text = sb.ToString
ListBox1.Items.Add(TextBox1.Text + "<--->" + TextBox2.Text)
My.Settings.md5_hashes.Add(TextBox1.Text + "<--->" + TextBox2.Text)
My.Settings.Save()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each item In My.Settings.md5_hashes
ListBox1.Items.Add(item)
Next
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
For Each item In My.Settings.md5_hashes
ListBox1.Items.Add(item)
Next
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class
Well i just solved my self the problem its because wen i start the timer its is there the code to retrieved all the content from my settings to the listbox.
I just removed and solved.

vb.net Find and REMOVE a line in a textbox

I'm very frustrated trying to get my code to work.
I'm trying to have a selected item in a listbox removed also in the textbox.
Getting ready to remove text;
Removed the text;
But it's still in the textbox.
Here is my code
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox2.Text += TextBox1.Text & vbNewLine
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
'
'//HOW TO REMOVE THE SELECTED TEXT IN THE LISTBOX ALSO REMOVED IN THE TEXTBOX2??
'
'
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim filenames As String = "C:\log\log.txt"
My.Computer.FileSystem.WriteAllText(filenames, TextBox2.Text, False)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim filenames As String = "C:\log\log.txt"
If My.Computer.FileSystem.FileExists(filenames) Then
TextBox2.Text = My.Computer.FileSystem.ReadAllText(filenames)
Dim items()
items = TextBox2.Lines()
For Each item In items
ListBox1.Items.Add(item)
Next
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Clipboard.SetText(ListBox1.SelectedItem)
End Sub
End Class
The worst part is that every time I try to look it up online, there are no errors until I click the button that says 'Value Cannot Be Null'
It happened every single time.
Please, before you mash the -1 button, at least tell me why. I'm new to this.
This should work for you
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text.Replace(ListBox1.Items(ListBox1.SelectedIndex), Nothing)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
End Class

Interrupting loop in VB.net

I have a loop that runs but would like it to stop on the press of a button and start again when another is pressed. This is my code:
Public Class Form1
Private loopon As Boolean
Public Function ping(ByVal server As String) As String
Dim s As New Stopwatch
s.Start()
My.Computer.Network.Ping(server)
s.Stop()
Return s.ElapsedMilliseconds.ToString
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
loopon = True
TextBox1.Text = "Ping results:"
Do While loopon = True
TextBox1.AppendText(Environment.NewLine)
TextBox1.AppendText(ping("server name here"))
Loop
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
loopon = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = String.Empty
TextBox1.Text = "Ping results:"
loopon = True
End Sub
End Class
When I try to run the code, with debugging, my computer gives me a blue screen after a while and restarts. I'm pretty sure I messed up with the exiting of the loop. Any suggestions?
You could use a Timer to ping (say) every 5 seconds until the "Stop" button is clicked. In the Form Designer, drag a Timer onto the form, and use this code:
Public Class Form1
Private stopPing As Boolean
Public Sub Ping(ByVal server As String)
Dim s As New Stopwatch
s.Start()
My.Computer.Network.Ping(server)
s.Stop()
TextBox1.AppendText(Environment.NewLine & s.ElapsedMilliseconds.ToString)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "Ping results:"
Ping "server name here"
Timer1.Interval = 5000 'Set timer Interval to 5 seconds
Timer1.Start
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
stopPing = True
End Sub
Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If stopPing Then Timer1.Stop Else Ping "server name here"
End Sub
End Class

Throw New NotImplementedException - VB

I'm making an application that manages the inputs and outputs of a company's customers as well as the creation of the same, however when I "submit" the form of the creation of a new customer to me the following error:
"Throw New NotImplementedException"
I leave here my code, so they can help me.
FORM1.vb
Public Class Form1
Private Property cnt As Object
<SerializableAttribute> _
'<ComVisibleAttribute(True)> _
Public Class NotImplementedException _
'Inherits SystemException
End Class
Private Sub TabPage1_Click(sender As Object, e As EventArgs)
Dim cnt As New OleDb.OleDbConnection
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
TabControl1.SelectedTab = TabPage2
End Sub
Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'cnt.ConnectionString = "Provinder=Microsoft.Jet.Oledb.40; Data Source=" & Application.StartupPath & "\bdtesteentradas.mdb"
'TODO: This line of code loads data into the 'BdtesteentradasDataSet.empresa' table. You can move, or remove it, as needed.
Me.EmpresaTableAdapter.Fill(Me.BdtesteentradasDataSet.empresa)
End Sub
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs) Handles FillByToolStripButton.Click
Try
Me.EmpresaTableAdapter.FillBy(Me.BdtesteentradasDataSet.empresa)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Me.EmpresaBindingSource.Filter = "nif ='" & TextBox1.Text & "'"
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox2.Text = ""
TextBox3.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox5.Text = ""
TextBox4.Text = ""
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Dim cnt As New OleDb.OleDbCommand
If Not ConnectionState.Open Then
End If
Cmd.Connection = cnt()
Cmd.CommandText = "INSERT INTO empresa (NIF, Empresa, nCliente, Distrito, NomeContacto, ApelidoContacto, Funcao" &
"VALUES(" & Me.TextBox6.Text & ")"
'Cmd.ExecuteNonQuery()
MsgBox("Dados inseridos.")
End Sub
Cmd.vb
Class Cmd
Shared Property CommandText As String
Shared Property Connection As Object
Shared Sub ExecuteNonQuery()
Throw New NotImplementedException
End Sub
End Class
Error message
Already a big thank you
You got error on your "cmd" variable and "fixed it" this way:
Didn't you? This generated the file Cmd.vb for you.
That is not what you want. Remove Cmd.vb from you project an try this:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'You want to check, what the State of *your* connection is
If Not cnt.State = ConnectionState.Open Then
End If
'Create a Command-Object from the Connection
Using cmd = cnt.CreateCommand()
cmd.CommandText = "INSERT INTO empresa (NIF, Empresa, nCliente, Distrito, NomeContacto, ApelidoContacto, Funcao" &
"VALUES(" & Me.TextBox6.Text & ")"
cmd.ExecuteNonQuery()
MsgBox("Dados inseridos.")
End Using
End Sub