B4J Question Instruction Return

lucdrb

Active Member
Licensed User
Longtime User
When I run the following lines, I would like to use in another part of the program the result of Lastid

Sub LastID() As Int
Try
Dim LastID As Int = Main.SQL.ExecQuerySingleResult (requete)
Catch
Log (LastException)
End Try
Return LastID
End Sub

I've used the instruction return to do it, but in this code the instruction retrun rerun the sub.
Is it normal?
What should I do to return the result?

Regards

Luc
 

stevel05

Expert
Licensed User
Longtime User
You shouldn't have a variable with the same name as a Sub. Do you not get a stack overflow error?
 
Upvote 0

lucdrb

Active Member
Licensed User
Longtime User
OK thanks for your answer.
I've got another problem :)
The sub does not rerun but the return don't give anything.

I've got the following message now
(Exception) java.lang.Exception: java.lang.NumberFormatException: empty String

I try to sent the result in another module Is it the problem?

Luc
 
Upvote 0

lucdrb

Active Member
Licensed User
Longtime User
The calling code from the modification module

private idtype as INT

If typeTfMod Then
InstSql.NewType (1, TypeTextField.Text )
idtype = InstSql.GetLastIdType
End If

In the InstSql module

Sub GetLastIdType
requete = "select max(idtype) from type"
LastID
End Sub
Sub GetLastIdFormat
requete = "select max(idformat) from format"
LastID
End Sub
Sub GetLastIdNom
requete = "select max(idnominst) from nominst"
LastID
End Sub
Sub GetLastIdExplic
requete = "select max(idexplic) from explic"
LastID
End Sub


Sub LastID() As Int
Try
Dim Last_ID As Int = Main.SQL.ExecQuerySingleResult (requete)
Catch
Log (LastException)
End Try
Return Last_ID
End Sub

I hope it will help

Luc
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You need to pass requete to the lastID sub, and the lastID sub should have a variable in the signature:

B4X:
private idtype as INT

If typeTfMod Then
InstSql.NewType (1, TypeTextField.Text )
idtype = InstSql.GetLastIdType
End If

In the InstSql module

Sub GetLastIdType
requete = "select max(idtype) from type"
ID = LastID(requete)
End Sub

Sub LastID(requete as String) As Int
Try
Dim Last_ID As Int = Main.SQL.ExecQuerySingleResult (requete)
Catch
Log (LastException)
End Try
Return Last_ID
End Sub
 
Upvote 0
Top