Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - vb.net 2013 variabili public o dim ?
Forum - C# / VB.NET - vb.net 2013 variabili public o dim ? - Pagina 2

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
Fharamir (Normal User)
Rookie


Messaggi: 21
Iscritto: 06/05/2011

Segnala al moderatore
Postato alle 9:51
Venerdì, 29/11/2013
anche la parola "avvolte" esiste, ma non credo volessi usare quella xD

comunque sposta
Codice sorgente - presumibilmente C# / VB.NET

  1. Dim MysqlConn As MySqlConnection



subito sotto
Codice sorgente - presumibilmente C# / VB.NET

  1. Public Class Form1



al di fuori degli altri metodi, tipo:

Codice sorgente - presumibilmente VB.NET

  1. Public Class Form1
  2.  
  3.     Dim MysqlConn As MySqlConnection
  4.  
  5.     Public Function _database_connect()
  6.  
  7.         'Codice
  8.  
  9.     End Function
  10.  
  11.     'Altri metodi
  12.  
  13. End Class


PM Quote
Avatar
faustf (Normal User)
Newbie


Messaggi: 7
Iscritto: 27/11/2013

Segnala al moderatore
Postato alle 11:57
Venerdì, 29/11/2013
certo


Codice sorgente - presumibilmente VB.NET

  1. Imports MySql.Data.MySqlClient
  2. Imports System.IO
  3.  
  4.  
  5. Public Class Form1
  6.  
  7.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8.         _database_connect()
  9.  
  10.  
  11.  
  12.  
  13.     End Sub
  14.     Public Function _database_connect()
  15.  
  16.         Dim lines() As String = My.Resources.database_config.Split(Environment.NewLine)
  17.  
  18.         Dim server As String = (lines(0).Split("=")(1))
  19.         Dim username As String = (lines(1).Split("=")(1))
  20.         Dim password As String = (lines(2).Split("=")(1))
  21.         Dim database As String = (lines(3).Split("=")(1))
  22.  
  23.         Dim MysqlConn As MySqlConnection
  24.         MysqlConn = New MySqlConnection()
  25.  
  26.         MysqlConn.ConnectionString = "server=pincopallino.it;" _
  27.         & "user id=root;" _
  28.         & "password=baobab;" _
  29.         & "database=demade"
  30.  
  31.         Try
  32.             MysqlConn.Open()
  33.             MessageBox.Show("Connessione avvenuta con successo.")
  34.  
  35.             _estrae_rubrica_dispari()
  36.  
  37.  
  38.  
  39.  
  40.  
  41.         Catch myerror As MySqlException
  42.             MessageBox.Show("Non è possibile connettersi al database: " & myerror.Message)
  43.             Application.Exit()
  44.  
  45.         Finally
  46.             MysqlConn.Dispose()
  47.         End Try
  48.  
  49.  
  50.     End Function
  51.  
  52.     Public Function _estrae_rubrica_dispari()
  53.         Dim myadapter As New MySqlDataAdapter("select * from  dynarc_rubrica_contacts;", MysqlConn)
  54.         Dim mydatateble As New DataTable
  55.         myadapter.Fill(mydatateble)
  56.  
  57.         MsgBox(mydatateble.Rows(10).Item("name"))
  58.     End Function
  59.  
  60.  
  61.  
  62.     Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
  63.  
  64.     End Sub
  65.     Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
  66.  
  67.     End Sub
  68.  
  69.     Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs)
  70.  
  71.     End Sub
  72.  
  73.     Private Sub RubricaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RubricaToolStripMenuItem.Click
  74.         Dim lines() As String = My.Resources.database_config.Split(Environment.NewLine)
  75.         Dim server As String = (lines(0).Split("=")(1))
  76.         System.Diagnostics.Process.Start("http://" & server & "/gestionale/Rubrica/")
  77.  
  78.     End Sub
  79.  
  80.     Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  81.  
  82.  
  83.  
  84.     End Sub
  85.  
  86.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  87.         Process.Start("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe")
  88.     End Sub
  89. End Class


PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6404
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 14:44
Venerdì, 29/11/2013
Quindi la classe c'era

Public Class Form1

Perché hai detto che sopra quella funzione c'erano solo le Imports?

Quindi

Public Class Form1
   Private MysqlConn As MySqlConnection

e poi il resto, ovviamente eliminando la Dim dalla funzione

Ultima modifica effettuata da nessuno il 29/11/2013 alle 14:44


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
faustf (Normal User)
Newbie


Messaggi: 7
Iscritto: 27/11/2013

Segnala al moderatore
Postato alle 14:54
Venerdì, 29/11/2013
ho  fatto cosi  
sia  mettendo  dim  che  private  

Codice sorgente - presumibilmente VB.NET

  1. Imports MySql.Data.MySqlClient
  2. Imports System.IO
  3.  
  4.  
  5. Public Class Form1
  6.     Dim MysqlConn As MySqlConnection
  7.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8.         _database_connect()
  9.  
  10.  
  11.  
  12.  
  13.     End Sub
  14.     Public Function _database_connect()
  15.  
  16.         Dim lines() As String = My.Resources.database_config.Split(Environment.NewLine)
  17.  
  18.         Dim server As String = (lines(0).Split("=")(1))
  19.         Dim username As String = (lines(1).Split("=")(1))
  20.         Dim password As String = (lines(2).Split("=")(1))
  21.         Dim database As String = (lines(3).Split("=")(1))
  22.  
  23.  
  24.         MysqlConn = New MySqlConnection()
  25.  
  26.         MysqlConn.ConnectionString = "server=pincopallino.it;" _
  27.         & "user id=root;" _
  28.         & "password=baobab;" _
  29.         & "database=demade"
  30.  
  31.         Try
  32.             MysqlConn.Open()
  33.             MessageBox.Show("Connessione avvenuta con successo.")
  34.  
  35.             _estrae_rubrica_dispari()
  36.  
  37.  
  38.  
  39.  
  40.  
  41.         Catch myerror As MySqlException
  42.             MessageBox.Show("Non è possibile connettersi al database: " & myerror.Message)
  43.             Application.Exit()
  44.  
  45.         Finally
  46.             MysqlConn.Dispose()
  47.         End Try
  48.  
  49.  
  50.     End Function
  51.  
  52.     Public Function _estrae_rubrica_dispari()
  53.         Dim myadapter As New MySqlDataAdapter("select * from  dynarc_rubrica_contacts;", MysqlConn)
  54.         Dim mydatateble As New DataTable
  55.         myadapter.Fill(mydatateble)
  56.  
  57.         MsgBox(mydatateble.Rows(10).Item("name"))
  58.     End Function
  59.  
  60.  
  61.  
  62.     Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
  63.  
  64.     End Sub
  65.     Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
  66.  
  67.     End Sub
  68.  
  69.     Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs)
  70.  
  71.     End Sub
  72.  
  73.     Private Sub RubricaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RubricaToolStripMenuItem.Click
  74.         Dim lines() As String = My.Resources.database_config.Split(Environment.NewLine)
  75.         Dim server As String = (lines(0).Split("=")(1))
  76.         System.Diagnostics.Process.Start("http://" & server & "/gestionale/Rubrica/")
  77.  
  78.     End Sub
  79.  
  80.     Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  81.  
  82.  
  83.  
  84.     End Sub
  85.  
  86.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  87.         Process.Start("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe")
  88.     End Sub
  89. End Class



ma  mi da  errore  e  non si connette  ,  (calcola che con il software per amministrare il db  ci entro e  ci razzolo  tranquillamente )

Warning    1    Function '_database_connect' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.    \Form1.vb    50    5    gestionale-web


Warning    2    Function '_estrae_rubrica_dispari' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.    \Form1.vb    58    5    gestionale-web



PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6404
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 15:44
Venerdì, 29/11/2013
Intanto le funzioni indicate non restituiscono valori ... a questo punto perché sono funzioni ?


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
faustf (Normal User)
Newbie


Messaggi: 7
Iscritto: 27/11/2013

Segnala al moderatore
Postato alle 17:34
Venerdì, 29/11/2013
mi dava errore perche ,  avevo cambiato alcune cose  sul db
scusate :)

adesso mi da un altro errore  ma provo a risolvere  ,  se no non spremo mai il mio povero gulliver :D  

se non ci riesco continuo a stressarvi :D  grazie  ancora a tutti


Ultima modifica effettuata da faustf il 29/11/2013 alle 17:40
PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo