https://www.ohjelmointiputka.net/koodivinkit/
miksi se ei toimi?
Ei voi tietää. Jospa alottaisit vaikka kertomalla, millä tavalla se ei toimi?
jumittuu
Minne asti pääset koodissa? Ilmoittaako VB mahdollisesti jotakin? Virheilmoituksia?
laitoin sen tälläseen muotoon
tarviiko tässä koodissa jotain *.dll:n tyypistä juttua?
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(0, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(88, 8)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 32)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(168, 8)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(64, 40)
Me.Button3.TabIndex = 2
Me.Button3.Text = "Button3"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(0, 56)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(248, 20)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "TextBox1"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(24, 136)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(232, 30)
Me.ListBox1.TabIndex = 4
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pList() As Process
Dim myProcess As System.Diagnostics.Process
pList = myProcess.GetProcesses
For Each myProcess In pList
ListBox1.Items.Add(myProcess.ProcessName)
Next
MsgBox("Ohjelmia on käynnissä yhteensä: " & ListBox1.Items.Count, 64, "Ohjelmat") ' näyttää käynnissä olevat ohjelmat
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If ListBox1.FindString(TextBox1.Text) <> -1 Then
MessageBox.Show("Löydetty")
ListBox1.SelectedIndex = ListBox1.FindString(TextBox1.Text)
Else
MsgBox("Etsimääsi ohjelmaa ei löytynyt.")
End If
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim proc As System.Diagnostics.Process
Dim pList() As Process
pList = Process.GetProcessesByName(ListBox1.Text)
For Each proc In pList
Dim resp As MsgBoxResult
resp = MsgBox("Haluatko sammuttaa " & proc.ProcessName & "?", _
MsgBoxStyle.YesNo, "Sammuta?")
If resp = MsgBoxResult.Yes Then
proc.Kill() 'sammuttaa valitun ohjelman
End If
Next
End Sub
End ClassHmmm kyllä minulla tuo toimi... kokeile lisätä msgbox väliin:
For Each myProcess In pList
msgbox(myProcess.ProcessName)
ListBox1.Items.Add(myProcess.ProcessName)
NextAntti kirjoitti:
Hmmm kyllä minulla tuo toimi...
voitko pistää sinun source koodin tarteeks tossa jotain komponentteja?
Siis copypastesin suoraan sinun ylläolevan koodisi uuteen projektiin.
Ei tarvitse mitään erityistä... edellyttäen, että sinulla on referenssit Systemiin ja System.Windows.Forms.Form'iin
Antti kirjoitti:
referenssit Systemiin ja System.Windows.Forms.Form'iin
sain tän ohjelman toimimaan vasta vähän aikaa sitten ja en tiedä mitä noi on kun vb.net on niin erillainen kuin vb6, että voisitko selittää tarkemmin.
Ei toi tietääkseni toimi vb6:ssa. Korjatkaa jos oon väärässä.
Ei, se ei toimi vb6 minulla onkin vb.net, mutta kun minä en ole kovin hyvä siinä.
Itse asiassa ne eivät hirveästi eroa toisistaan. VB.NET:issa on vain tuotu paljon sellaista esiin, mikä VB6:ssa oli piiloitettuna kokonaan tai valikkojen taakse.
Lueskelemalla tekstieditorilla VB6:n lähdetiedostoja huomaat tiettyjä samankaltaisuuksia.
Referenssi, eli viittaus tiettyyn luokkakirjastoon löytyy project browserista sieltä oikeasta laidasta (edellyttäen, että sinulla on se siellä oikeassa laidassa auki) Siis siitä missä näkyy form1 jne.
Referenssin voit lisätä klikkaamalla oikealla hiiren näppäimellä references-valikon "kansiota" ja valitse add.
Aukeaa ikkuna, josta valitset haluamasi referenssit, kaksoisklikkaat niitä ja valitset OK.
en saanu toimimaan
Aihe on jo aika vanha, joten et voi enää vastata siihen.