Android Question CallSubDelayed vs CallSub and returns values

Sergio Haurat

Active Member
Licensed User
Longtime User
CallSubDelayed, CallSubDelayed2 and CallSubDelayed3 not return a value as they do CallSub, CallSub2 and CallSub3. This is a bug or just not possible to return values from other modules
 

thedesolatesoul

Expert
Licensed User
Longtime User
It is not a bug, it is by design.
When you use CallSubDelayed, it does not execute the sub straight away but waits till the current code execution thread is empty and starts processing messages. The sub is actually called much later, so it is not even possible for the value to be available at the time of the call.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Erel, please do not be angry, I previously asked a question, I search in the forum, see examples and I do everything possible to resolve it without asking. I did not find an answer using the internal search engine, or externally using Google.

I apologize for asking so many queries at the moment, I am developing a project. With my experience in VB6 and VB.NET I find the vast majority resolved but not others.

It is really appreciated the effort made with B4A again so I apologize if I question becomes annoying
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
The question is based on the following:

Main Activity:
B4X:
Dim varClass as MyClass
varClass.Initialize("This is a name", "String", 1)

MyModule
B4X:
Public Sub CompareParam2vsParam3(objDataType As Object) As String
  Dim strObjName As String
  strObjName = GetType(objDataType)
  strObjName = strObjName.Replace("java.lang.", "")
  Return strObjName
End Sub

MyClass
B4X:
Public Sub Initialize(Name As String, DataType As String, DefaultValue As Object)
  Dim strDataTypeDefaultValue As String
  strDataTypeDefaultValue = MyModule.CompareParam2vsParam3(ObjDataType)
  If DefaultValue = Null OR DataType <> strDataTypeDefaultValue Then
      'ERROR TypeMismatch
        ' The data type and default value does not match.
    Else
        strDataType = DataType
    End If
End Sub

At line MyModule.CompareParam2vsParam3(ObjDataType) in MyClass, stops and log is:

Error occurred on line: 90 (MyClass)
java.lang.NullPointerException
at anywheresoftware.b4a.B4AClass$ImplB4AClass.getActivityBA(B4AClass.java:20)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:633)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:298)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:237)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:116)
at ar.com.sysprofile.rtrating.main.afterFirstLayout(main.java:98)
at ar.com.sysprofile.rtrating.main.access$100(main.java:16)
at ar.com.sysprofile.rtrating.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)

For this reason I tried with other functions, like CallSubDelayed2. But now I know, does not return data CallSubDelay2 by design
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Sergio,

looking at your code snippet I see that the errant line reads:
strDataTypeDefaultValue = MyModule.CompareParam2vsParam3(ObjDataType)
but parameter ObjDataType is never cited before; should it be DefaultValue instead?

Umberto
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Hi Sergio,

looking at your code snippet I see that the errant line reads:
strDataTypeDefaultValue = MyModule.CompareParam2vsParam3(ObjDataType)
but parameter ObjDataType is never cited before; should it be DefaultValue instead?

Umberto

Hello, that was the error when you copy and paste from the code project. Now I comment in more detail in the following response to Erel.

DefaultValue real variable, which is a parameter of the sub.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
What is the purpose of this code?

Erel , good morning . The code is part of a clone for B4A 'm doing this.

http://msdn.microsoft.com/en-US/library/System.Data(v=vs.110).aspx

I find that there are several ways to read data but not all return the same result , in my case , SQL and MySQL libraries. SQL is handled with a variable of type Cursor , on the other hand , MySQL a type List variable.

I asked if there is any way to make a Cast from List to Cursor. It seems that not because I received no reply .

Then I proposed a challenge for someone with experience to do a Framework data management , I saw not interested .

Then I told myself , Do it yourself , and here I am , with 70 % of the code ready but with some difficulty finding equivalences with my development experience ( I'm 40 and I started to develop in Basic for DOS at 14 years old , developed in Visual Basic 1 to 6 , and today , I make developments . NET . ) .

In this case, the code , I'm doing that when you define a data type for a column and want to define a default value, is the same type of data.

With great humility, I apologize to you for attempting to do in trying to understand what I write, I speak Spanish and use Google Translator to communicate with you. There are times when you certainly read something that may seem the wrong way or expressed with anger, the spirit is not being rude, it is the limitation of using this tool.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I find that there are several ways to read data but not all return the same result , in my case , SQL and MySQL libraries. SQL is handled with a variable of type Cursor , on the other hand , MySQL a type List variable.
I don't recommend you to use the MySQL library. You should either use RDC or the PHP based solution.

Check DBUtils.ExecuteMemoryTable. You can create a similar method that reads the data from a different source and returns a List of arrays.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Erel, I saw the components that you tell me, also tried. The problem I find is that returns a variable of type List and not a Cursor type (or similar and manipulable as with Cursor type), the variable data type Cursor I find it more practical to manipulate columns referring to the name, not the column number and I have to know, if 0 is the row of column names or data, to name a facility when developing.

DBUtils is really great, works great, has many facilities but uses SQL as a data manager.

My idea is that the manipulation of the data, since the construction of columns, data type, whether it is read only and many other properties and methods. Everything is executed in memory, reading multiple sources and types of data " would ".

A generic example of my proyect is:
B4X:
Dim dsDataSet as DataSet'< This would be the database , which contains the tables
dsDataSet.Initialize

Dim dtTable As DataTable
dtTable.Initialize
dtTable.TableName = "MyTable"

Dim dtColumn as Column
dtColumn.Initialize
dtColumn.ColumnName = "Column1"
dtColumn.DataType = "String"

dtTable.AddColumn(dtColumn)
dtTable.AddRow("Bla bla bla")

'TODO
dtTable.LoadXML(file)
dtTable.LoadText(file, delimiter, bln1stlinecols)
dtTable.LoadOTHER(params)

dsDataSet.Add (dtTable)

DataSet is not really necessary, that is if you want to manipulate more than one table at a time.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Erel, when finished with the development I would like to share with the community. I will indicate if there are steps to follow to do so. I know that the documentation is part of the publication. The Good, all documentation in English of each property and method is copied from the original source.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…