Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [VB.NET]Perche questo codice non va??

    Questo codice non vuole funzionare e non capisco perchè!
    Sono 2 form e un modulo;

    Form Main
    codice:
    Imports WindowsApplication14.Connection
    
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    #Region " Windows Form Designer generated code "
        Dim form2 As form2
    
        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 Label1 As System.Windows.Forms.Label
        Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents Label5 As System.Windows.Forms.Label
        Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
        Friend WithEvents txtStato As System.Windows.Forms.TextBox
        Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
        Friend WithEvents btnConnect As System.Windows.Forms.Button
        Friend WithEvents btnDisconnect As System.Windows.Forms.Button
        Friend WithEvents Label3 As System.Windows.Forms.Label
        Friend WithEvents Label4 As System.Windows.Forms.Label
        Friend WithEvents Host As System.Windows.Forms.TextBox
        Friend WithEvents Port As System.Windows.Forms.TextBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
            Me.Label1 = New System.Windows.Forms.Label()
            Me.btnConnect = New System.Windows.Forms.Button()
            Me.GroupBox1 = New System.Windows.Forms.GroupBox()
            Me.txtStato = New System.Windows.Forms.TextBox()
            Me.btnDisconnect = New System.Windows.Forms.Button()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.Label5 = New System.Windows.Forms.Label()
            Me.GroupBox2 = New System.Windows.Forms.GroupBox()
            Me.GroupBox3 = New System.Windows.Forms.GroupBox()
            Me.Label3 = New System.Windows.Forms.Label()
            Me.Label4 = New System.Windows.Forms.Label()
            Me.Host = New System.Windows.Forms.TextBox()
            Me.Port = New System.Windows.Forms.TextBox()
            Me.GroupBox1.SuspendLayout()
            Me.GroupBox2.SuspendLayout()
            Me.GroupBox3.SuspendLayout()
            Me.SuspendLayout()
            '
            'Label1
            '
            Me.Label1.Location = New System.Drawing.Point(10, 25)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(135, 30)
            Me.Label1.TabIndex = 0
            Me.Label1.Text = "HackerSim 2.0"
            Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            '
            'btnConnect
            '
            Me.btnConnect.BackColor = System.Drawing.SystemColors.GrayText
            Me.btnConnect.Enabled = False
            Me.btnConnect.ForeColor = System.Drawing.Color.Black
            Me.btnConnect.Image = CType(resources.GetObject("btnConnect.Image"), System.Drawing.Bitmap)
            Me.btnConnect.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
            Me.btnConnect.Location = New System.Drawing.Point(30, 25)
            Me.btnConnect.Name = "btnConnect"
            Me.btnConnect.Size = New System.Drawing.Size(90, 30)
            Me.btnConnect.TabIndex = 1
            Me.btnConnect.Text = "Connect"
            Me.btnConnect.TextAlign = System.Drawing.ContentAlignment.MiddleRight
            '
            'GroupBox1
            '
            Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtStato, Me.btnDisconnect, Me.Label2, Me.btnConnect})
            Me.GroupBox1.Location = New System.Drawing.Point(15, 95)
            Me.GroupBox1.Name = "GroupBox1"
            Me.GroupBox1.Size = New System.Drawing.Size(405, 65)
            Me.GroupBox1.TabIndex = 2
            Me.GroupBox1.TabStop = False
            Me.GroupBox1.Text = "Connection Optrions"
            '
            'txtStato
            '
            Me.txtStato.BackColor = System.Drawing.Color.Red
            Me.txtStato.Cursor = System.Windows.Forms.Cursors.Arrow
            Me.txtStato.Location = New System.Drawing.Point(180, 30)
            Me.txtStato.Name = "txtStato"
            Me.txtStato.ReadOnly = True
            Me.txtStato.Size = New System.Drawing.Size(80, 20)
            Me.txtStato.TabIndex = 4
            Me.txtStato.Text = ""
            Me.txtStato.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
            '
            'btnDisconnect
            '
            Me.btnDisconnect.BackColor = System.Drawing.SystemColors.GrayText
            Me.btnDisconnect.Enabled = False
            Me.btnDisconnect.ForeColor = System.Drawing.SystemColors.ControlText
            Me.btnDisconnect.Image = CType(resources.GetObject("btnDisconnect.Image"), System.Drawing.Bitmap)
            Me.btnDisconnect.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
            Me.btnDisconnect.Location = New System.Drawing.Point(285, 25)
            Me.btnDisconnect.Name = "btnDisconnect"
            Me.btnDisconnect.Size = New System.Drawing.Size(90, 30)
            Me.btnDisconnect.TabIndex = 3
            Me.btnDisconnect.Text = "Disconnect"
            Me.btnDisconnect.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'Label2
            '
            Me.Label2.Location = New System.Drawing.Point(145, 30)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(35, 20)
            Me.Label2.TabIndex = 2
            Me.Label2.Text = "Stato:"
            Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'Label5
            '
            Me.Label5.Location = New System.Drawing.Point(140, 25)
            Me.Label5.Name = "Label5"
            Me.Label5.Size = New System.Drawing.Size(259, 30)
            Me.Label5.TabIndex = 4
            Me.Label5.Text = "Local system abilited to continue operations"
            Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
            '
            'GroupBox2
            '
            Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.Label5})
            Me.GroupBox2.Location = New System.Drawing.Point(15, 15)
            Me.GroupBox2.Name = "GroupBox2"
            Me.GroupBox2.Size = New System.Drawing.Size(405, 60)
            Me.GroupBox2.TabIndex = 5
            Me.GroupBox2.TabStop = False
            Me.GroupBox2.Text = "Informations"
            '
            'GroupBox3
            '
            Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.Port, Me.Host, Me.Label4, Me.Label3})
            Me.GroupBox3.Location = New System.Drawing.Point(15, 170)
            Me.GroupBox3.Name = "GroupBox3"
            Me.GroupBox3.Size = New System.Drawing.Size(405, 280)
            Me.GroupBox3.TabIndex = 6
            Me.GroupBox3.TabStop = False
            Me.GroupBox3.Text = "Main Menù"
            Me.GroupBox3.Visible = False
            '
            'Label3
            '
            Me.Label3.Location = New System.Drawing.Point(40, 40)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(55, 20)
            Me.Label3.TabIndex = 0
            Me.Label3.Text = "Host at"
            Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            '
            'Label4
            '
            Me.Label4.Location = New System.Drawing.Point(240, 40)
            Me.Label4.Name = "Label4"
            Me.Label4.Size = New System.Drawing.Size(55, 20)
            Me.Label4.TabIndex = 1
            Me.Label4.Text = "Port"
            Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            '
            'Host
            '
            Me.Host.BackColor = System.Drawing.SystemColors.ScrollBar
            Me.Host.Cursor = System.Windows.Forms.Cursors.Default
            Me.Host.Location = New System.Drawing.Point(95, 40)
            Me.Host.Name = "Host"
            Me.Host.ReadOnly = True
            Me.Host.Size = New System.Drawing.Size(105, 20)
            Me.Host.TabIndex = 2
            Me.Host.Text = ""
            '
            'Port
            '
            Me.Port.BackColor = System.Drawing.SystemColors.ScrollBar
            Me.Port.Cursor = System.Windows.Forms.Cursors.Default
            Me.Port.Location = New System.Drawing.Point(295, 40)
            Me.Port.Name = "Port"
            Me.Port.ReadOnly = True
            Me.Port.Size = New System.Drawing.Size(65, 20)
            Me.Port.TabIndex = 3
            Me.Port.Text = ""
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.BackColor = System.Drawing.Color.Black
            Me.ClientSize = New System.Drawing.Size(432, 461)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox3, Me.GroupBox2, Me.GroupBox1})
            Me.ForeColor = System.Drawing.Color.Gold
            Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
            Me.MaximizeBox = False
            Me.Name = "Form1"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "HackerSim 2.0"
            Me.GroupBox1.ResumeLayout(False)
            Me.GroupBox2.ResumeLayout(False)
            Me.GroupBox3.ResumeLayout(False)
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Connection.Connection = True Then
                btnDisconnect.Enabled = True
                txtStato.Text = "connesso"
                txtStato.BackColor = System.Drawing.Color.Green
                GroupBox3.Show()
                Host.Text = Connection.HostAddress
                Port.Text = Connection.ConnectPort
            Else
                btnConnect.Enabled = True
                txtStato.Text = "disconnesso"
                txtStato.BackColor = System.Drawing.Color.Red
            End If
        End Sub
    
        Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
            form2 = New Form2()
            form2.Show()
        End Sub
    
        Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
            Connection.Connection = False
        End Sub
    End Class
    Nothing To Say :-D

  2. #2

    Secondo form

    Procedo con il secondo form, Connect.vb
    codice:
    Imports WindowsApplication14.Connection
    
    Public Class Form2
        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 GroupBox1 As System.Windows.Forms.GroupBox
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents Label3 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents txtPort As System.Windows.Forms.TextBox
        Friend WithEvents txtHost As System.Windows.Forms.TextBox
        Friend WithEvents Button3 As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form2))
            Me.GroupBox1 = New System.Windows.Forms.GroupBox()
            Me.Button3 = New System.Windows.Forms.Button()
            Me.Button1 = New System.Windows.Forms.Button()
            Me.Label3 = New System.Windows.Forms.Label()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.txtPort = New System.Windows.Forms.TextBox()
            Me.txtHost = New System.Windows.Forms.TextBox()
            Me.GroupBox1.SuspendLayout()
            Me.SuspendLayout()
            '
            'GroupBox1
            '
            Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button1, Me.Label3, Me.Label2, Me.txtPort, Me.txtHost})
            Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
            Me.GroupBox1.Name = "GroupBox1"
            Me.GroupBox1.Size = New System.Drawing.Size(296, 152)
            Me.GroupBox1.TabIndex = 0
            Me.GroupBox1.TabStop = False
            Me.GroupBox1.Text = "GroupBox1"
            '
            'Button3
            '
            Me.Button3.BackColor = System.Drawing.SystemColors.GrayText
            Me.Button3.ForeColor = System.Drawing.Color.Black
            Me.Button3.Image = CType(resources.GetObject("Button3.Image"), System.Drawing.Bitmap)
            Me.Button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
            Me.Button3.Location = New System.Drawing.Point(192, 104)
            Me.Button3.Name = "Button3"
            Me.Button3.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.Button3.Size = New System.Drawing.Size(80, 25)
            Me.Button3.TabIndex = 12
            Me.Button3.Text = "Annulla"
            Me.Button3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
            '
            'Button1
            '
            Me.Button1.BackColor = System.Drawing.SystemColors.GrayText
            Me.Button1.ForeColor = System.Drawing.Color.Black
            Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Bitmap)
            Me.Button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
            Me.Button1.Location = New System.Drawing.Point(32, 104)
            Me.Button1.Name = "Button1"
            Me.Button1.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.Button1.Size = New System.Drawing.Size(104, 25)
            Me.Button1.TabIndex = 10
            Me.Button1.Text = "Try Connect"
            Me.Button1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
            '
            'Label3
            '
            Me.Label3.Location = New System.Drawing.Point(16, 64)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(74, 15)
            Me.Label3.TabIndex = 9
            Me.Label3.Text = "Port"
            Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'Label2
            '
            Me.Label2.Location = New System.Drawing.Point(16, 32)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(74, 15)
            Me.Label2.TabIndex = 8
            Me.Label2.Text = "IP Address"
            '
            'txtPort
            '
            Me.txtPort.Location = New System.Drawing.Point(112, 64)
            Me.txtPort.Name = "txtPort"
            Me.txtPort.Size = New System.Drawing.Size(78, 20)
            Me.txtPort.TabIndex = 7
            Me.txtPort.Text = "80"
            '
            'txtHost
            '
            Me.txtHost.Location = New System.Drawing.Point(112, 32)
            Me.txtHost.Name = "txtHost"
            Me.txtHost.Size = New System.Drawing.Size(142, 20)
            Me.txtHost.TabIndex = 6
            Me.txtHost.Text = ""
            '
            'Form2
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.BackColor = System.Drawing.Color.Black
            Me.ClientSize = New System.Drawing.Size(312, 174)
            Me.ControlBox = False
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox1})
            Me.ForeColor = System.Drawing.Color.Gold
            Me.Name = "Form2"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "HS Connection"
            Me.GroupBox1.ResumeLayout(False)
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Connection.Connection = True
            Me.Close()
        End Sub
    
        Private Sub txtHost_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHost.TextChanged
            Connection.HostAddress = txtHost.Text
        End Sub
    
        Private Sub txtPort_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPort.TextChanged
            Connection.ConnectPort = txtPort.Text
        End Sub
    End Class
    E infine il modulo Connection.vb
    codice:
    Module Connection
        Public Connection As Boolean = True
        Public HostAddress As String = "0.0.0.0"
        Public ConnectPort As String = "80"
    End Module
    Però quando si avvia clicco sul pulsante conetti, inserisco i parametri e non si connette, cambiando poi manualmente la variabile booleana, si avvia già connesso, ma non si disconnette!

    Perchè mi fa questo??
    Nothing To Say :-D

  3. #3
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,477
    In questo modo, aiutarti è un compito veramente arduo.

    Ci si dovrebbe leggere tutto il codice e, almeno dalla tua spiegazione, non è ben chiaro cosa stai cercando di ottenere, con il risultato che non si riescono ad estrapolare dal listato le parti importanti.

    Dovresti prenderti un attimo di tempo per spiegare meglio cosa stai cercando di realizzare e commentare le parti significative del tuo codice mostrando attentamente cosa non funziona e quello che vorresti invece ottenere.

    In caso contrario, chi è costretto a leggere tutto il codice per poi cercare di capire il problema...preferisce andare altrove, lasciandoti senza una risposta.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.