Integer increment

linusfishing

Member
Joined
Jun 6, 2005
Messages
15
Programming Experience
Beginner
Hello, I need to know how to increase my integer everytime it has been get.
I have declared testing as integer = 0

Public ReadOnly Property ID() As String

Get

Return testing.ToString

End Get

End Property


Help is much appreciated.

 
tomhosking said:
Surely:

Public ReadOnly Property ID() As String

Get

Return testing.ToString
testing +=1

End Get

End Property
So with the method that you've provided, the next time it gets this ID, the integer should have already increased by 1 right? It seems like it isn't really working well for me. Is it alright for me if i "dim testing as Integer" on the top? Or is that affecting me?

Linus
 
The following works fine for me:

VB.NET:
[size=2][color=#0000ff]Public[/color][/size][size=2] [/size][size=2][color=#0000ff]Class[/color][/size][size=2] Form1

[/size][size=2][color=#0000ff]Inherits[/color][/size][size=2] System.Windows.Forms.Form

[/size]PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
TextBox1.Text = id()
 
EndSub
 
Public test AsInteger = 0
 
PublicReadOnlyProperty id()
 
Get
 
id = test
 
test += 1
 
EndGet
 
EndProperty
 
EndClass
 
tomhosking said:
Surely:

Public ReadOnly Property ID() As String

Get

Return testing.ToString
testing +=1

End Get

End Property

in vb.net once it reaches the Return keyword it exits the current sub/function/property so all you need to do is move the testing += 1 so it's before the Return testing.ToString line like:

VB.NET:
[color=#0000ff]Public[/color] [color=#0000ff]ReadOnly[/color] [color=#0000ff]Property[/color] ID() [color=#0000ff]As[/color] [color=#0000ff]String

[/color][color=#0000ff]Get

[/color] testing += 1
[color=#0000ff]Return[/color] testing.ToString

 [color=#0000ff]End[/color] [color=#0000ff]Get

[/color][color=#0000ff]End[/color] [color=#0000ff]Property[/color]

and then it will work fine for ya
 
Back
Top