Hi Erel,
I had finished jThaiDate Library ,but I need to know addtion in my case,I need imonth could to be as String or Int. Is there way?
P.S. In order that I could use Only DateTime without DateUtils or use the both of them.
B4X:
Public Sub ThaiMonth(imonth As String or imonth as Int ) As String
Select imonth
Case "January" or 1
Return "มกราคม"
Case "February" or 2
Return "กุมภาพันธ์"
Case "March" or 3
Return "มีนาคม"
Case "April" or 4
Return "เมษายน"
Case "May" or 5
Return "พฤษภาคม"
Case "June" or 6
Return "มิถุนายน"
Case "July" or 7
Return "กรกฎาคม"
Case "August" or 8
Return "สิงหาคม"
Case "September" or 9
Return "กันยายน"
Case "October" or 10
Return "ตุลาคม"
Case "November" or 11
Return "พฤศจิกายน"
Case "December" or 12
Return "ธันวาคม"
End Select
End Sub
Declare the parameter as a String and B4J will coerce a passed Int to a String.
Set up a Map with the numbers and month names as the keys and your Thai month strings as values.
Look up the passed value in the Map.
Public Sub ThaiMonth(imonth As Object) As String
If imonth Is String Then
Select imonth
Case "January"
Return "มกราคม"
Case "February"
Return "กุมภาพันธ์"
Case "March"
Return "มีนาคม"
Case "April"
Return "เมษายน"
Case "May"
Return "พฤษภาคม"
Case "June"
Return "มิถุนายน"
Case "July"
Return "กรกฎาคม"
Case "August"
Return "สิงหาคม"
Case "September"
Return "กันยายน"
Case "October"
Return "ตุลาคม"
Case "November"
Return "พฤศจิกายน"
Case "December"
Return "ธันวาคม"
End Select
Else
Dim imInt As Int = imonth
Select imInt
Case 1
Return "มกราคม"
Case 2
Return "กุมภาพันธ์"
Case 3
Return "มีนาคม"
Case 4
Return "เมษายน"
Case 5
Return "พฤษภาคม"
Case 6
Return "มิถุนายน"
Case 7
Return "กรกฎาคม"
Case 8
Return "สิงหาคม"
Case 9
Return "กันยายน"
Case 10
Return "ตุลาคม"
Case 11
Return "พฤศจิกายน"
Case 12
Return "ธันวาคม"
End Select
End If
End Sub
I'm sorry that my words make terrible,my English is still badly . The really, if I have one sub module which has input could be String or some type of parameter which isn't string or int,How to do? (It's alike using Overloading in Java's polymorphism)
B4X:
public void print(int a);
public void print(float a);
public void print(double a);
public void print();
P.S. I've no knowledge of Java,I cut them from a book.
You could try this, not elegant, and it cannot handle null parameters.
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim s As String = "a string"
Dim i As Int = 99
Dim f As Float = 9.87
Dim d As Double = 23456
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
' call with String
Log(a(s))
' call with Int (Integer)
Log(a(i))
' call with Float
Log(a(f))
' call with double
Log(a(d))
End Sub
Sub a(parm As JavaObject) As String
Dim t As String = parm.RunMethod("getClass",Null) 'get class of parm
Dim ti As Object = parm 'get parm real value floats are dodgy
Select t.SubString(t.LastIndexOf(".")+1) ' just want class name nor java.lang.....
Case "String"
Return "a String '" & ti ' handle a String here
Case "Integer"
Return "an Integer " & ti ' handle an Integer here
Case "Float"
Return "a Float " & ti ' handle a Float here
Case Else
Return "Unhandled type : " & t.SubString(t.LastIndexOf(".")+1) & " " & ti
End Select
End Sub
@agraham I agree in the original question making it String would suffice, but in post #9 question it implies you need to know the data type being sent.