Passaggio riferimenti

lunedì 11 gennaio 2010 - 14.48

iif Profilo | Expert

Ciao, è possibile richiamare una sub passando come riferimento il nome del form?
Vi posto l'esempio:
Sub CaricaAnagrafica(ByVal xIDPers, ByRef Chiamante)
Using miaConnessione As New OleDb.OleDbConnection(Connessione.ConnectionString)
Dim command As New OleDb.OleDbCommand("Select * From TPers Where ID=" & xIDPers, miaConnessione)
Attendi(True)
miaConnessione.Open()
Dim Lettore As OleDb.OleDbDataReader = command.ExecuteReader()
Lettore.Read()
Chiamante.txtMatricola.Text = Lettore("Matricola").ToString()
Chiamante.txtNome.Text = Lettore("Nome").ToString()
Chiamante.txtOre.Text = Lettore("PlanOre").ToString()
Chiamante.txtProgressivo.Text = Lettore("ID").ToString()
Chiamante.txtCap.Text = Lettore("Cap").ToString()
Chiamante.txtCitta.Text = Lettore("Citta").ToString()
Chiamante.txtIndirizzo.Text = Lettore("Indirizzo").ToString()
Chiamante.txtMail.Text = Lettore("PostaElettronica").ToString()
Chiamante.txtCodFisc.Text = Lettore("CodFisc").ToString()

For x = 0 To Lettore("Glav").ToString.Length - 1
If Lettore("Glav").ToString.Substring(x, 1) = "L" Then
Chiamante.Lun.Checked = True
ElseIf Lettore("Glav").ToString.Substring(x, 1) = "M" Then
Chiamante.Mar.Checked = True
ElseIf Lettore("Glav").ToString.Substring(x, 1) = "W" Then
Chiamante.Mer.Checked = True
ElseIf Lettore("Glav").ToString.Substring(x, 1) = "G" Then
Chiamante.Gio.Checked = True
ElseIf Lettore("Glav").ToString.Substring(x, 1) = "V" Then
Chiamante.Ven.Checked = True
ElseIf Lettore("Glav").ToString.Substring(x, 1) = "S" Then
Chiamante.Sab.Checked = True
ElseIf Lettore("Glav").ToString.Substring(x, 1) = "D" Then
Chiamante.Dom.Checked = True
End If
Next
Lettore.Close()
End Using
Attendi(False)

End Sub

Grazie.

AntCiar Profilo | Expert

Ciao

Certo che s può fare.
Devi specificare anche il tipo

es: .... byref chiamante as Form2
Cristian Barca

Jeremy Profilo | Guru

Ciao Fabio.
Aggiungo che non è necessario specificare la clausola ByRef in quanto in .Net viene passato comunque tutto come riferimento(e non come valore) ad eccezione di variabili di tipo primitivo(parti integranti del linguaggio) quali String, Integer etc... ....... e se posso darti un consiglio imposta nei tuoi progetti futuri OptionStrict On così da evitare associazioni tardive che potrebbero creari errori di conversione a run-time.

Facci sapere....
Ciao

iif Profilo | Expert

Grazie per le risposte, ho provato come avete detto nelle risposte, mi dice che non trova il campo txtmatricola

AntCiar Profilo | Expert

Ciao
Questo è un problema di "visibilità"
Imposta la visibilità di txtmatricola a "public"

Cristian Barca

iif Profilo | Expert

Funziona, grazie.
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5