B4A Library [Class]ClsWheel Input wheels

Attached you find a new CLASS ClsWheel.

It allows to display different data input screens with wheels.

What can be done ?
You can define nine different types of Wheel input screens:
  • DATE a date input : year / month / day
    A default value can be defined or Now, the current date.
    The returned value has the current DateFormat.
  • TIME_HM a time input : hour / minute
    A default value can be defined or Now, the current time.
    The returned value has the current TimeFormat.
  • TIME_HMS a time input : hour / minute / second
    A default value can be defined or Now, the current time.
    The returned value has the current TimeFormat.
  • DATE_TIME a date + time input : year / month / day / hour / minute
    A default value can be defined or Now, the current date and time.
    The returned value has the current DateFormat and TimeFormat.
  • CUSTOM a custom input with user defined input values.
    The number of side by side wheels is user defined (max. 5 wheels).
    A default value can be defined.
    A specific separation character can be defined, a blanc character is default.
  • INTEGER positive and negative integers
  • INTEGER_POS only positive integers
  • NUMBER positive and negative numbers
  • NUMBER_POS only positive numbers
Main functions:
Initialize initializes the wheel class Note: the Initialize routine hasone more parameter cContinusScrolling As Boolean (since version 1.3) .
Example :
whlDate.Initialize(Me, Activity, "Enter date", 3, Null, 24, 0, True)
Me = calling module, the current
Activity =
Enter date = title of the input
3 = number of wheels, this number is used only for CUSTOM input types
Null = no input data, set internally
24 = text size
0 = DATE input type
True = continus scrolling

Show show the input wheel(s)
Example :
whlDate.Show(lblSelection, "11/22/2001")
lblSelection = Label which gets the result
11/22/2001 = Default value to preset the wheels

Show2 show the input wheel(s)
Example :
whlCustum.Show2("whlCustom", "")
"whlCustom" = EventName
"" = no default value
The event is called 'Closed'.
The event routine in the calling module, for the example, must be
Sub whlCustom_Closed(Canceled As Boolean, Selection As String)

The width and height are defined by the program according to the font size.

If the width or the height exceed the screen width or height the font size is downscaled.

You can change most of the colors.

Needs the Reflection library.

Bug reports and suggestions are welcome.

I hope that the code is enough self explanatory, but if you want more explanations I can add them.
Anyway the best way to know what can be done is to test it.

PS. There is no logic in the custom input screen just to demonstrate the possibility.

Best regards.


EDIT: 2020.11.25 Version 2.7
Amended warning in line 946: Comparison of Object to other types will fail if exact types do not match.
EDIT: 2015.04.29 Version 2.0
Added a Tag property

EDIT: 2017.06.27 Version 2.6
Replaced DoEvents by Sleep(0)
Needs B4A version 7.00+

EDIT: 2017.03.30 Version 2.5
Amended the wish expressed HERE
Different font sizes for title and wheels.
With long titles, the font size of both, title and wheels, was reduced.
Now only the title font size is reduced.

EDIT: 2017.03.28 Version 2.4
Amended the error reported HERE
Problem with +/- in number wheels

EDIT: 2015.09.22 Version 2.3
Amended the error reported in post #185

EDIT: 2015.05.10 Version 2.2
Amended the variable declaration problem reported in post #175

EDIT: 2015.05.10 Version 2.1
Amended the timer problem reported in post #170

EDIT: 2014.09.09 Version 1.9
Added number wheels INTEGER, INTEGER_POS, NUMBER, NUMBER_POS wheels
Amended day scroll problem reported in post #141

EDIT: 2014.04.21 Version 1.7
Amended OutOfMemory problem reported HERE.

EDIT: 2013.09.15 Version 1.6
Added min MinYear and NumberOfYears properties to adapt the years to select

EDIT: 2013.08.08 Version 1.5
Added StartScroll and EdnScroll events

EDIT: 2013.06.14 Version 1.4
Modified OK event to Closed event post#37
Amended screen color problem post#36
Amendet getSeparationText error post #41

EDIT: 2013.06.12 Version 1.3
Mofied property routines.
Added Show2 for raising an event when clicking the OK button
Added optional continus scrolling

EDIT: 2013.05.28 Version 1.2
Amended the bug reported in post #32

EDIT: 2012.12.15 Version 1.1
Amended the reported bugs.
 

Attachments

  • Time_input.jpg
    Time_input.jpg
    32.9 KB · Views: 2,262
  • Custom_input.jpg
    Custom_input.jpg
    45.3 KB · Views: 2,179
  • ClsWheelV2_5.zip
    19.1 KB · Views: 464
  • ClsWheelV2_7.zip
    19.3 KB · Views: 478
Last edited:

klaus

Expert
Licensed User
Longtime User
Try to uncomment lines 408 and 409
B4X:
objWheel(i).RunMethod3("scrollTo", 0, "java.lang.int", ScrollPos(i), "java.lang.int")
DoEvents
in the ClsWheels module.
These two lines will then be three times.
I can only reproduce your problem when I Initialize the wheel each time.
The workaround above seems to solve the problem.

Best regards.
 

stefanoa

Active Member
Licensed User
Longtime User
Try to uncomment lines 408 and 409
B4X:
objWheel(i).RunMethod3("scrollTo", 0, "java.lang.int", ScrollPos(i), "java.lang.int")
DoEvents
in the ClsWheels module.
These two lines will then be three times.
I can only reproduce your problem when I Initialize the wheel each time.
The workaround above seems to solve the problem.

Best regards.
nothing.. same problem
 

stefanoa

Active Member
Licensed User
Longtime User
Can you post either your project or a smaller one that produces the problem.
In my programs I can't reproduce it.

Best regards.
In this way (lines 404-415) seems to work correctly:
B4X:
For i = 0 To WheelNb - 1
        objWheel(i).RunMethod3("scrollTo", 0, "java.lang.int", ScrollPos(i), "java.lang.int")
        DoEvents
        objWheel(i).RunMethod3("scrollTo", 0, "java.lang.int", ScrollPos(i), "java.lang.int")
        DoEvents
        objWheel(i).RunMethod3("scrollTo", 0, "java.lang.int", ScrollPos(i), "java.lang.int")
        DoEvents
        objWheel(i).RunMethod3("scrollTo", 0, "java.lang.int", ScrollPos(i), "java.lang.int")
        DoEvents
        DoEvents
        DoEvents
    Next
 

mr23

Active Member
Licensed User
Longtime User
Klaus, would you consider making my contribution to your library available to all, as a revision to your official library?
I added a type '5', DIGITS, whereby one can set up a Wheel definition for a digital number up to 5 digits, and specify a decimal point location.
It is used as shown below. The value here is ClsWheel does the work for converting a decimal number to 'internal' representation (as would be done for a CUSTOM), and returns the number in the result that can be used directly without converting back.
I adjusted Version number to 1.7.

B4X:
Sub Globals
    Private whlTTTdT As ClsWheel ' declare a wheel for a 4 digit Temp with decimal point between 3rd and 4th digits

Sub Activity_Create(FirstTime As Boolean)
    whlTTTdT.Initialize(Me, Activity, "Enter Temp", 4, Null, 18, 5, True)
    whlTTTdT.SetDecimalPosition(1)

' example usage
Sub Label4_Click
    Dim s As String = Round2(fTemp,1)
    'whlTTTdT.Show(Label4,s)
    whlTTTdT.Show2("whlTTTdT",s)
End Sub

Sub whlTTTdT_Closed(Canceled As Boolean, Selection As String)
    If Canceled = False Then
        fTemp = (Selection*1)  ' store value somewhere
        Label4.Text = Selection ' or whatever
    Else
    End If
End Sub

Documented contribution on my Blog
 

Attachments

  • ClsWheel.bas
    31.7 KB · Views: 147
Last edited:

mr23

Active Member
Licensed User
Longtime User
That works, except for two points.

The getSelection at 1009 doesn't preserve the digits to the right of the decimal point, and the decimal point, if the number is an integer. Since the InitDefaultValues side requires them, I feel getSelection should output them as well.

Such as:
B4X:
Selection = Selection / Power(10, cDigitsToTheRight)
If Not(Selection.Contains(".")) Then
    Selection = Selection & "."
    For i = 1 To cDigitsToTheRight
        Selection = Selection & "0"
    Next
End If


Your solution also requires the caller to supply the DP & DigitsToTheRight even if n.0 in the DefaulValue supplied; I used the setDecimalPosition to avoid all users of this functionality always having to format the numbers to the desired setting. Technically I do need to enforce a consistent value in a display (if I use a label as the source), but if supplied from a float or double then I have to format to a string,nDigits before passing to ClsWheel.
 

klaus

Expert
Licensed User
Longtime User
I was not aware that you wanted a specialized function with fixed format.
I will introduce a FixedFormat mode.
I will also add different number inputs:
INT : positive and negative integers
INT_POS : only positive integers
NUMBER : positive and negative numbers
NUMBER_POS : only positive numbers

Did you notice that you can change the decimal point position by touching the desired position ?
This will, of course, be disabled in the FixedFormat mode.

Best regards.
 

mr23

Active Member
Licensed User
Longtime User
If I enter 65.34 as text into it, with FF off, digitsright=0, it puts 653.4 on the wheels, and outputs 653.4
if I enter 65.34, FF on, digits right=1, 653.4 to the wheels, outputs same.

I tried, but was unable to move the decimal. I'm not sure of the gesture to accomplish it.

Attached a project zip. I had put your zip file contents into a library called ClsWheel17b.
 

Attachments

  • ClsWheel17test.zip
    8.8 KB · Views: 142
Last edited:

AubreyPCR

Member
Licensed User
Longtime User
Klaus,

Thank you for releasing this. Most of the whizzy stuff is in libs, source code is always welcome as it assists with learning curve. You have assisted greatly so far in my B4A learning, thank you.

The date/time selection seems exactly what I am looking for, it looks very nice. I have two things to ask though.

First is, could this selection mechanism be used within the confines of the CustomDialog (or a home rolled equivalent), and if so, how would one go about it ? For aesthetic reasons I would like to keep my dialogs and data selection popups looking the same through out the app. Sample source code would be the nicest answer ;)

The second question relates to the return value from a DATE_TIME wheel. Is there a reason why it returns a different format datetime string than was passed, ie you cannot use the return from a datetime as the default value, eg class expects format "MM/dd/yyyy HH:mm" but returns "MM/dd/yyyy / HH:mm". I can see in the code where the string is contructed but I was wondering if it was done for a reason I didn't understand.

One last point, the demo app fails on my phone. Its because my locale is IE with a default date format of dd/MM/yyyy and you pass a default value in the format MM/dd/yyyy. Inserting the lines
B4X:
DateTime.DateFormat = "MM/dd/yyyy"
DateTime.TimeFormat = "HH:mm"
before calling the show method fixes the demo app. The second line is because GetTimeHM returns HH:mm:ss if that is default format. I understand you cant please everybody but I needed to be sure of what was returned in order to parse it properly.

Thank you again for sharing your code.

Regards

Edit:
A more elegant solution for the GetTimeHH might be to change last few lines of the sub to read something like
B4X:
    If Time2.Length > 5 Then
     Time2 = Time2.SubString2(0, 5)
   End If
   Return Time2
 
Last edited:

Espinosa4

Active Member
Licensed User
Longtime User
Hello everybody,

Can you help me please?
After execute the clsWheel class I need change a label.text value. Here the code.
B4X:
Sub BtnCambioFecha_Click
    Dim F As Long
        LblSabDom.Text = ""
        WhlDate.Show(EdtFecha,EdtFecha.Text)
        WhlDate.SetBackgroundColor(Colors.Red)
        WhlDate.SetWindowLineColor(Colors.Blue)
        WhlDate.SetWindowColor(Colors.ARGB(96, 0, 0, 255))
        F = DateTime.DateParse(EdtFecha.Text)
        If DateTime.GetDayOfWeek(F) = 7 Then
            LblSabDom.Text = "* SÁBADO *"
        End If
        If DateTime.GetDayOfWeek(F) = 1 Then
            LblSabDom.Text = "* DOMINGO *"
        End If
End Sub

But After I executed WhlDate.show the code F=Datetime... etc is omitted.

Cheers
Espinosa
 

klaus

Expert
Licensed User
Longtime User
@AubreyPCR
1) No, the class is not designed for this.
2) Date and time are returned in the format of your code.
If you set DateTime.TimeFormat = "hh:mm"
even whlTimeHMS.Show(lblSelection, "10:15:25") will return "10:15" because that's the format you defined.

The example program is just a demo program, the definition of the DateTime.DateFormat in the demo program is there to show that the returned value is given in this format.
Internally, the class uses a fixed format transparent to the user.

Best regards.
 

klaus

Expert
Licensed User
Longtime User
@Espinosa4
Be aware that the ClsWheels class is NOT a modal object.
This means that when you call Sub BtnCambioFecha_Click all the code in the routine is run and does not wait the return from the class.
If you want to manage the returned result you must use an event routine with something like this:
B4X:
Sub btnEvent_Click
    whlCustom.Show2("whlCustom", lblCustom.Text)
End Sub

Sub whlCustom_Closed(Canceled As Boolean, Selection As String)
    If Canceled = False Then
        Activity.Title = Selection
    Else
    End If
End Sub
Best regards.
 

Espinosa4

Active Member
Licensed User
Longtime User
Thank you again klaus for your patience and for spending your time replying my doubts :)

I understand now. I thought when I was reading a document from here that all was modal except the resident modules.

Thanks you
Best regards
Espinosa
 
Last edited:

AubreyPCR

Member
Licensed User
Longtime User
@AubreyPCR
1) No, the class is not designed for this.
2) Date and time are returned in the format of your code.
If you set DateTime.TimeFormat = "hh:mm"
even whlTimeHMS.Show(lblSelection, "10:15:25") will return "10:15" because that's the format you defined.

The example program is just a demo program, the definition of the DateTime.DateFormat in the demo program is there to show that the returned value is given in this format.
Internally, the class uses a fixed format transparent to the user.

Best regards.

Klaus,

Thanks for clearing that up. I had expected the returned string to match the wheel layout, my mistake.
On the CD, I managed to shoehorn a version of your sample in to a CD. It sort of works but doesnt set the default date correctly when loading or "auto scroll" when selecting. I am guessing this is something to do with the fact that the CD is not visible when the "init default values" is run (as I have to execute wheel.show before CD.show). That level of complexity is too much for me so I had to abandon it.

Regards.
 

SueHale

Member
Licensed User
Longtime User
Hi Klaus,
Thank-you for making your Class available, looks excellent.
I have set up a simple Custom wheel layout that as a test comprises of A - F as single characters.
These have been able to select and displayed on a label with no problem.
Does the selection made get returned as a number, say for example 0-5 for A-F
I was wishing to use this to load a certain file depending on the user selection made.
With regards
Sue.
 

klaus

Expert
Licensed User
Longtime User
Does the selection made get returned as a number, say for example 0-5 for A-F
No this kind of treatment is too specialized.
Why not use 0 - 5 as strings ?

You could also use an event (with Show2) that will be raised when the user leaves the wheels object.
Insides the event routine you could transform A-F to 0-5 and set it to the label.

Best regards.
 
Last edited:
Top