Sub CStr(o As Object) As String
Return "" & o
End Sub
Sub CInt(o As Object) As Int
Return Floor(o)
End Sub
Sub CLng(o As Object) As Long
Return Floor(o)
End Sub
Dim strValue As String
Dim Result As Float
strValue = "100"
Result=Sqrt(strValue)
Msgbox("The square root of " & strValue & " is " & Result,"")
@Jost aus Soest :
Elegant, simplicity, Nice, i use these from now on
Hi,If you know the content of a string is a number, there is no need to convert it to an integer or float if you are going to use it in calculations.
Am I missing something.? See below code:
B4X:Dim strValue As String Dim Result As Float strValue = "100" Result=Sqrt(strValue) Msgbox("The square root of " & strValue & " is " & Result,"")
Dim Waiting_Time As EditText
Dim Waiting_Time_Int As Int
Dim tmpString As String
----------------------------
tmpString = Waiting_Time.Text
Waiting_Time_Int = tmpString + 1
tmpString = Waiting_Time_Int
Waiting_Time.Text = tmpString
java.lang.NumberFormatException: Invalid double: ""
Installing file.
PackageAdded: package:ce3.arsham.CE3RVCtrl
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_tmr1_tick (B4A line: 195)
Waiting_Time_Int = tmpString + 1
java.lang.NumberFormatException: Invalid double: ""
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:248)
at java.lang.Double.parseDouble(Double.java:295)
at ce3.arsham.CE3RVCtrl.main._tmr1_tick(main.java:789)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Waiting_Time.Text=Waiting_Time.Text+1
If IsNumber(Waiting_Time.Text) then
Waiting_Time.Text=Waiting_Time.Text+1
Else
Log(Waiting_Time.Text &" is not a number")
End If