Deklaration von Variablen

  • VB.NET
  • .NET (FX) 4.0

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von Schamash.

    Deklaration von Variablen

    Hallo zusammen,

    eigentlich eine einfache Sache....

    Ich möchte eine Klassenvariable definieren.

    Quellcode

    1. Private P_P_Zaehler As Integer
    2. Public Property PP_Zaehler As Integer
    3. Get
    4. Return P_P_Zaehler
    5. End Get
    6. Set(ByVal Value As Integer)
    7. P_P_Zaehler = Value
    8. End Set
    9. End Property
    10. Dim _Zaehler As Integer = P_P_Zaehler ' funzt nicht



    P_P_Zaehler bekommt beim Aufruf des Fensters den richtigen Wert.
    Leider klappt die Zuweisung beim _Zaehler nicht.

    Warum?

    Quellcode

    1. Dim _Zaehler As Integer = 4 'funzt


    Dirk
    _Zaehler müsste PP_Zaehler sein und nicht P_P_Zaehler. P_P_Zaehler ist eine Private Variablen in der Klasse
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    ist malwieder das Problem mit Code ohne Context.

    Weil

    VB.NET-Quellcode

    1. Public Class Class1
    2. Private P_P_Zaehler As Integer
    3. Public Property PP_Zaehler As Integer
    4. Get
    5. Return P_P_Zaehler
    6. End Get
    7. Set(ByVal Value As Integer)
    8. P_P_Zaehler = Value
    9. End Set
    10. End Property
    11. Dim _Zaehler As Integer = P_P_Zaehler ' funzt wunderbar!
    12. End Class
    funzt wunnebar - was soll daran nicht funzen?

    Bitte beachten: Dies ist eine Frage an den TE - andere Antworter können ja nur mutmassen, was der TE wohl gemeint haben mag, als er behauptete, es würde net funzen.

    VB.NET-Quellcode

    1. Public Class Class1
    2. Private P_P_Zaehler As Integer
    3. Public Property PP_Zaehler As Integer
    4. Get
    5. Return P_P_Zaehler
    6. End Get
    7. Set(ByVal Value As Integer)
    8. P_P_Zaehler = Value
    9. End Set
    10. End Property
    11. End Class
    12. Public Class Main
    13. Dim test As New Class1
    14. Dim _Zaehler1 As Integer = test.P_P_Zaehler ' funzt Nicht!
    15. Dim _Zaehler2 As Integer = test.PP_Zaehler ' funzt wunderbar!
    16. End Class

    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."

    ErfinderDesRades schrieb:

    Das ist nun dein Code - es ist nicht der vom TE.


    Das ist korrekt. Ich hatte deinen Beitrag schon verstanden. Wollte dem TE aber zeigen wie es funktionieren könnte.
    Quasy als ergänzung zu deinem Code
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."