B4A Library [Class]ClsWheel Input wheels

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
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: 260
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: 188
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

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:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…