DaveM
28 July 2020 03:14
1
This is probably a bit of a stupid question but how does someone increment the value of a label’s vie field?
It almost seems I have to use an intermediate variable because what I am seeing is slightly confusing. I’m coding this in a phone. Lol.
Label1.Value = integer(Label1.Value.ToInteger + 1).ToString
Is that the right way?
Is there a better way?
To add to that, if one part of that was a double/float, how to deal with that?
well … which version are you using ?
some of us old timers use the “old” not dot syntax which is more compact
Label1.Value = Str(Val(Label1.Value)+ 1)
it just wont autocomplete this stuff without a bit of … coaxing
But yes the longer one you posted is required OR a temporary variable because of how Xojo handles return results from functions
dim tmp as integer = Label1.Value.ToInteger + 1
Label1.Value = tmp.ToString
I really hate that .text became .value - makes the code feel nonsensical
Old:
Label1.text = Str( Val(Label1.text) + 1 ) )
New:
Label1.value = Str( Val(Label1.value) + 1 ) )
It just confuses the difference between the text and the value of a text variable …
DaveM
28 July 2020 07:00
4
That’s true, and what is “Value” anyway? Most would argue (self included) it would at least be numeric. But when I tried something earlier, I found out it was a boolean, in which case I would have expected that to be Checked
or similar.
Actually it is not a Boolean, it us a String:
https://docs.xojo.com/Label.Value
It is “the value” of the label aka its text.
Not to be confused with the “value” of a CheckBox:
https://docs.xojo.com/CheckBox.Value
While the text of a CheckBox is it’s “caption”.
But Label doesn’t have a “caption”, it has a “value”
Hooray!
I guess now you know why API 2 was not universally liked.
DaveM
28 July 2020 08:49
6
When I made that comment, it was actually in relation to a button. I was trying to play with the label value of a button and found that it’s Value
was in fact a boolean:
https://docs.xojo.com/BevelButton.Value
aBevelButton.Value = newBooleanValue
or
BooleanValue = aBevelButton.Value
Value depends on what kind of control it is
Its less clear IMHO
1 Like