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,268
  • Custom_input.jpg
    Custom_input.jpg
    45.3 KB · Views: 2,186
  • ClsWheelV2_5.zip
    19.1 KB · Views: 473
  • ClsWheelV2_7.zip
    19.3 KB · Views: 487
Last edited:

SueHale

Member
Licensed User
Longtime User
Hi Klaus,

Thank-you for taking the time to explain one possible solution. I now think that on asking the question totally confused things.
I used your Wheel class to select the name of an audio file and this button code to load and play it.

B4X:
Sub Button1_Click
Dim MediaPlayer1 As MediaPlayer
MediaPlayer1.Initialize( )
    'Load MP3 files
    Select lblSelection.text
    Case "Harp"
        MediaPlayer1.Load(File.DirAssets, "harp.mp3")
    Case "Meep"
        MediaPlayer1.Load(File.DirAssets, "road.mp3")
    Case "Cartoon"
        MediaPlayer1.Load(File.DirAssets, "toon.mp3")
    Case "Chimes"
        MediaPlayer1.Load(File.DirAssets, "chimes.mp3")
    Case "Bongo"
        MediaPlayer1.Load(File.DirAssets, "temple.mp3")
    Case "Guitar"
        MediaPlayer1.Load(File.DirAssets, "suspense.mp3")
    Case "Tada"
        MediaPlayer1.Load(File.DirAssets, "tada.mp3")   
    Case "Saxaphone"
        MediaPlayer1.Load(File.DirAssets, "suspense.mp3")
    Case "Siren"
        MediaPlayer1.Load(File.DirAssets, "siren.mp3")   
    End Select
    MediaPlayer1.Play
       
End Sub

With regards
Sue.
 

klaus

Expert
Licensed User
Longtime User
If I understand now your question, did you want to get the position back ?
If this is the case I don't want to add it because it's only useful for one wheel.
If you have several wheels there would be different positions for each wheel.

In your case if the names in the wheel would have been the same as the generic names of the audio files you could have used:
MediaPlayer1.Load(File.DirAssets, lblSelection.Text & ".mp3")
But it's not the case.

Instead of using a Button to start the playing the file you could use an event for the wheel when the user clicks the OK button.

Best regards.
 
Last edited:

antonomase

Active Member
Licensed User
Longtime User
Hi,

When using clsWheel whith dateTime, I have an error "interval must be larger than 0" at line 752 (in debug mode)

The second time (in mode release), I have an error Unparseable date 11/22/2001 10:15" at java line 686
 

antonomase

Active Member
Licensed User
Longtime User
I try to change a label containing a chrono (lblTime.Text = "3:54")

My code
B4X:
Globals
    Dim lblTime as Label
    Dim whlTime As ClsWheel

Sub Activity_Create(FirstTime As Boolean)
    InitWheelChrono   
End Sub

Sub InitWheelChrono
    Dim lstChr(2) As List
    Dim i As Int
    lstChr(0).Initialize
    lstChr(1).Initialize
    For i=0 To 5
        lstChr(0).Add(i)
    Next
    For i= 0 To 9
        lstChr(1).Add("0" & i)
    Next
    For i= 10 To 59
        lstChr(1).Add(i)
    Next

    whlTime.Initialize(Me, Activity, "Time", 2, lstChr, 40, 4, True)
    whlTime.SetSeparationText(":")
End Sub

Sub lblTime_Longclick
    whlTime.Show2("whlTime", lblTime.Text)
End Sub

Sub whlTime_Closed(Canceled As Boolean, Selection As String)
    ' It works
End Sub

Each time I display the wheel, it is set to 5:59 instead to be displayed to the lblTime.Text value (e.g. 2:48)

Can you help me ?
Thanks
 

klaus

Expert
Licensed User
Longtime User
Change the InitWheelChrono like this:
B4X:
Sub InitWheelChrono
    Dim lstChr(2) As List
    Dim i As Int
    lstChr(0).Initialize
    lstChr(1).Initialize
  
    For i=0 To 5
        lstChr(0).Add(NumberFormat(i, 1, 0))
    Next

    For i = 0 To 59
        lstChr(1).Add(NumberFormat(i, 2, 0))
    Next

    whlTime.Initialize(Me, Activity, "Time", 2, lstChr, 40, 4, True)
    whlTime.SetSeparationText(":")
End Sub
The Custom wheel needs strings, but in your case you have Integers
 

moster67

Expert
Licensed User
Longtime User
Hi Klaus,

Thank you for this class. I am trying out the different solutions available here on the forum to use a wheel-view.

I have a problem with your class when I want to set the initial value (defaulvalue) of the wheel. I read earlier in this thread, this class was not meant for numbers but nevertheless, I will post my problem for you anyway :)

B4X:
Sub InitWheelData
   
    Dim mylist(1) As List
    mylist(0).Initialize
    mylist(0).Clear
   
'    if model="SS" then (50000 to 1000000) *divide with 1000 in list
    For x = 50 To 1000 Step 25
        mylist(0).Add(x)
    Next
   
    whlCustomSingle.Initialize(Me, Activity, "Select Bitrate", 1, mylist, 24, 4, True)
    whlCustomSingle.Show(lblTranscodingBitrateValue, "350")

    'whlCustomSingle.Show(lblTranscodingBitrateValue, lblTranscodingBitrateValue.Text)
   
End Sub

As you can see, in my case, "mylist" is not producing numbers strictly one after one (such as 1,2,3 etc) but I use an interval of 25.

How could I modify this part in the class

B4X:
If WheelNb = 1 Then
          ScrollPos(0) = lblHeight *(WheelContent(0).IndexOf(DefaulValue) + WheelContentNb(i))


to get "defaulvalue" positioned and working correctly in the wheel?

Thanks!
 

moster67

Expert
Licensed User
Longtime User
Works perfect. Much better to adjust code in origin instead of modifying the class-code.

Thank you Klaus.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi Klaus!
First of all my compliments! Very good and useful work!

Only a question.
It's possible to customize the class in order to dispay a horizontal wheel?
 

klaus

Expert
Licensed User
Longtime User
Answer to the question of Johan Schoeman here.
Klaus, downloaded ClsWheel. When I start it and click on "Select date" the default date being displayed is 2013 September 21
Remove line 110 in the Main code :
whlDate.Initialize(Me, Activity, "Enter date", 3, Null, 24, 0, True)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Don't know if it is the right/correct solution but if you call/add "show_today" from/to SUB Activity_Resume in WheelView (the only line of code that I have in this sub) then it seems to solve the problem. Have not had a failed start of day, month, year in any of the wheels despite numerous attempts.
 

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't understand.
Are you speaking about ClsWheels or derezs' WheelView library.
The project you posted is not refered to the ClsWheels class so I can't help you.
I understoud that you were speaking about my ClsWheels class, when you posted this post, but your code has nothing to with it, and now I am confused ?
 

klaus

Expert
Licensed User
Longtime User
It's hardcoded in the Main module, which is only an example code, not in the Class.
You can change it in your application, you can show any date you want.
In the whlDate.Show method the first parameter is the view where the result will be shown and the second parameter is a String with the date to show when you call the wheel. In the example code it's a string variable with a given date format just as an example. If you set an empty string as the date parameter the wheel shows today.
Examples, where lblDate is the Label where the result is displayed:
B4X:
whlDate.Show(lblDate, dateEditText) ' date is a string variable
whlDate(lblDate, "21-09-2013") ' date is a fixed string
whlDate.Show(lblDate, lblDate.Text) ' date is the current date in the lblDate Label
whlDate(lblDate, "") ' date is today
 
Top