Wish B4XPlusMinus addition (b4xPlusMinus default value)

rabbitBUSH

Well-Known Member
Licensed User
Erel, hello,

It appears that B4XPlusMinus does not have a means to set a default value. Or, I have not found the class member or method to set a default.

In the project I am working on user is to set values (say Day, Month, Year).

This is not to get the current but some arbitrary date the user has to supply.

What I found is that, if the user does not have to change a value (say day happens to be the first day of a month so, doesn't have to press the control) the value floats at Zero (this
B4X:
    [B]startday [/B]= SdayB4XPlusMinus1.SelectedValue
would be Zero if not directly changed). This mean that you get an error down the road when you try to so something with the values.

For instance :
B4X:
startdate = DateTime.DateParse(startmonth & "/" & startday &  "/" & startyear) ' convert entered date into ticks

The Parser complains because of the zero value (including in the 'year' slot). Obviously, if one did something bizarre like a division using one of those (date) numbers, it will bomb. But selections can be wide ranging so a division is not improbable. Perhaps a reasonable simple example would be : if one has to select the pH value in a water quality test, the default could be set at 7 with the range being set at 4 -> 10 with an increment of whatever. One assumes, then, that 7 would be the value that appears between the arrows of the control, so a change like this obviously will mean a bit more coding on your side (sorry).

Incidentally, if one presses the control to get a 2 and then go back to a 1, this is OK later on (obviously).

As said above, this is because there isn't a way to set a default (only the range,
B4X:
SdayB4XPlusMinus1.SetNumericRange(1, 31, 1)
and the increment.

Because "1" is the initial value of the range, this does not translate into a default value.

Obviously, the wish here, if I am not missing something, is for an extra parameter to SetNumericRange that would set a default value, therefore elimination of traps to be set in other parts of the project code. Not sure if one would then have to do anything in the Click event, but it seems unlikely.

Thanks, stay indoors don't starve, even unused toilet paper might have some nutrition. . . .


Thanks
 

rabbitBUSH

Well-Known Member
Licensed User
Thanks, Erel

Granted, but, that restricts you between 10 and 20, my example of 4 - 10 with a default selected value (7 in #1), then does not apply (in the same way as one can default a checkbox to CHECKED or UNCHECKED so the user can pass it by).

Perhaps, in terms of my email, and, more to the point is, and I realise now that it was not well expressed in #1 -
the control doesn't seem to treat 10, for instance, as the initial(ized)/ default value that is passed - so if you don't spin it to a value (as noted above say from 1 to 2 and back because you want 1) then it initialises as zero and passes zero on. So what I experienced was that as in your example in #2 the "default selected" value isn't 10 its zero. Again, unless I am missing something here.

I know that you understand and have digested my wish - so a last word and wish.....
B4XPlusMinus1.SetNumericRange(10, 20, 1, "default selected value")

appreciating everything you do .....
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4XPlusMinus1.SetNumericRange(10, 20, 1, "default selected value")
This is a very bad change. It will break all existing apps.

I'm sorry but I don't understand the problem.

Tested with this code:
B4X:
    B4XPlusMinus1.SetNumericRange(10, 20, 1)
    Log(B4XPlusMinus1.SelectedValue)
End Sub

Sub B4XPlusMinus1_ValueChanged (Value As Object)
    Log(Value)
End Sub
The initial value is set to 10.
 

rabbitBUSH

Well-Known Member
Licensed User
I'm sorry but I don't understand the problem.

Ok don't let's labour this one its a wish and #4 gives a warning about not doing this.

But since you made the comment above. Apologies if this example is pedantic but sometimes simple is pedantic.

As you note that you tested this as we all know and appreciate you do, I had those exact lines in the code as well.

SO, still at the risk of being pedantic the attached ZIP examples the issue (in a way attempting to answer your comment that I am responding to). Its extracted and adapted from the project itself. I was gong to put in a control about the pH example I made, but, hey, you might think I have too much time during lockdown on the farm here.

So, thanks for looking at this simple little thing, and, unless you have any further comment or clarity needed, lets close this off.

As I said it was just a wish, so no worries not a big thing good programing practice will take care of it.

???
 

Attachments

  • Erel-test.zip
    10.5 KB · Views: 290

rabbitBUSH

Well-Known Member
Licensed User
hello @Erel just FEEDBACK on this item nothing to do but note the following :

Dumbass ?? here has just found the solution to the wish -? oi vey ->
B4X:
SdayB4XPlusMinus1.SelectedValue = 6

OF COURSE Which means this works when you want to get the current day's date as a start "default".
B4X:
 SdayB4XPlusMinus1.SelectedValue = (DateTime.GetDayOfMonth (DateTime.Now))

AND
I guess this is also possible :
B4X:
SdayB4XPlusMinus1.SetNumericRange((DateTime.GetDayOfMonth (DateTime.Now)), DateUtils.NumberOfDaysInMonth, 1)

MINOR testing and log information shows this works Who would have thought. O! Erel.....
In my project those only work for the start date collection not an end date.

In the next day or so I will post a nonsense project (in the Android examples or questions) that demonstrates some of this, its a project that might show other B4X beginners how to do nonsense things to find their way with B4X - like the new member who was asking about where to start B4j or B4a or B4i etc..

AND
YOU already provided the solution before I asked, How Did You Do That?
?????
 
Top