Array globale

martedì 13 febbraio 2007 - 09.59

sasa72 Profilo | Newbie

Ciao,
qualcuno sa spiegarmi come faccio a definire una array globale in vb.net ?
se è di un tipo come ad esempio byte faccio cosi

Private Shared gCommand_ID As Byte

Public Shared Property Command_ID() As Byte
Get
Return gCommand_ID
End Get
Set(ByVal Value As Byte)
gCommand_ID = Value
End Set
End Property

ma se deve restituirmi un array di byte come si fa?

Vi prego aiutatemi non riesco a trovare alternative..
Grazie

Giamp72 Profilo | Junior Member

non è chiarissimo ciò che chiedi... ma provo a risponderti ugualmente..

Questo è il codice che ti serve?


Private Shared gCommand_ID() As Byte

Public Shared Property Command_ID() As Byte()
Get
Return gCommand_ID
End Get
Set(ByVal Value() As Byte)
gCommand_ID = Value
End Set
End Property
Giamp72

sasa72 Profilo | Newbie

cerco di spiegarmi meglio
finchè devo definire una variabile di tipo string globale il seguente codice funziona

Private Shared gCommand_Timeout As String

Public Shared Property Command_Timeout() As String
Get
Return gCommand_Timeout
End Get
Set(ByVal Value As String)
gCommand_Timeout = Value
End Set
End Property

ma ho bisogno di definire un array globale e se faccio cosi come hai detto tu che avevo già provato
quando vado ad assegnare il valore ad esempio

Me.gCommand_Len(0) = &H0

mi dà l'errore

An unhandled exception of type 'System.NullReferenceException' occurred in RS232.exe

Additional information: Object reference not set to an instance of an object.

Forse sbaglio nella set e get della proprietà?

Giamp72 Profilo | Junior Member

ma se + semplicemente dichiari nella tua classe

Public gCommand_ID() As Byte

potrai scrivere e leggere i valori attraverso la tua classe...

classe.gcommand(1)=1

num=classe.gcommand(2)

potrebbe andare?
Giamp72

sasa72 Profilo | Newbie

mi dà lo stesso errore di prima quando arriva all'assegnazione!

Giamp72 Profilo | Junior Member

ma hai tolto

Public Shared Property Command_Timeout() As String

e tutto il suo contenuto????

Giamp72

sasa72 Profilo | Newbie

si che l'ho tolto!!

Giamp72 Profilo | Junior Member

mi sembra molto strano perchè a me questo codice funziona benissimo.. te lo allego...
fammi sapere.
Giamp72
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