Errore Function

giovedì 29 novembre 2007 - 11.56

ape81 Profilo | Newbie

ciao,
sto lavorando in VB.net, VisualStudio 200,Crystal Report, MySQL2005

Ho creato una Form dove e' possibile visualizzare piu' report.
Per compattare il codice ho creato questa funzione:

Function CReport(ByVal id As String)

Dim oCrystalReport As New ReportClass

oCrystalReport.FileName = id
oCrystalReport.Load()
oCrystalReport.SetDatabaseLogon("......", "*******")
oCrystalReport.VerifyDatabase()
'--- Set Crystal Viewer to point at oCrystalReport ---
CRselect.Visible = True
CRselect.ReportSource = oCrystalReport
CRselect.ShowFirstPage()

End Function

a questa funzione passo il valore dei file .rpt (id) che voglio visualizzare.
funziona tutto ma sull' End Function mi si genera un errore che per ora non mi crea problemi ma vorrei capire di che si tratta. l'errore e' il seguente:

"Function “CReport” doesn’t return a value on all code paths. A null reference exception could occur at run time when the result is used."

grazie.
elisa

sanbiz Profilo | Senior Member

>ciao,
>sto lavorando in VB.net, VisualStudio 200,Crystal Report, MySQL2005
>
>Ho creato una Form dove e' possibile visualizzare piu' report.
>Per compattare il codice ho creato questa funzione:
>
>Function CReport(ByVal id As String)
>
> Dim oCrystalReport As New ReportClass
>
> oCrystalReport.FileName = id
> oCrystalReport.Load()
> oCrystalReport.SetDatabaseLogon("......", "*******")
> oCrystalReport.VerifyDatabase()
>'--- Set Crystal Viewer to point at oCrystalReport ---
> CRselect.Visible = True
> CRselect.ReportSource = oCrystalReport
> CRselect.ShowFirstPage()
>
>End Function
>
>a questa funzione passo il valore dei file .rpt (id) che voglio
>visualizzare.
>funziona tutto ma sull' End Function mi si genera un errore che
>per ora non mi crea problemi ma vorrei capire di che si tratta.
>l'errore e' il seguente:
>
>"Function “CReport” doesn’t return a value on all code paths.
>A null reference exception could occur at run time when the result
>is used."
>
L'errore è dovuto al fatto che una Function si aspetta di restituire un valore ed infatti dovresti specificare una cosa del genere


Private Function CReport(ByVal id As String) as String/Integer/ecc.
..
...
....
Return mioValoreDiRitorno
End Function

Nel tuo esempio sarebbe più corretto definire una Sub

Private Sub CReport(ByVal id As String)
..
...
....
End Sub

--
Sandro Bizioli
http://blogs.dotnethell.it/sandro/

totti240282 Profilo | Guru

Perchè usi una funzione a cui non trasferisci nessun risultato,e lui te lo segnala,non è proprio un errore,diciamo segnalazione.
C'è solo un capitano !!!!!!

ape81 Profilo | Newbie

Ok.
Grazie mille.
Devo usare...
Private sub()
.....
end sub

ciao
elisa
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