Android Question Using too many if conditions

wasro

Member
There are about 400 if conditions in my project.
When it was 150 it was ok but then it gives an error.
What should I do? I think there is something about the cache.
Thanks for your help

I'm sorry I'm using translation
 

Attachments

  • Adsız.png
    Adsız.png
    17.4 KB · Views: 63
Last edited:

wasro

Member
If Label6.Text="1" Then
bas.text=" TAVLA"
Label1.text="ZAR"
Label2.text="OYUN"
Label3.text="YENMEK"
Label4.text="MARS"
Label5.text="KAPI"



Else

If Label6.Text=" 2 " Then
bas.text=" PARA "
Label1.text=" KAĞIT "
Label2.text=" DOLAR "
Label3.text=" SATINALMA "
Label4.text=" ÜLKE "
Label5.text=" KAZANMAK "

Else
If Label6.Text=" 3 " Then
bas.text=" MOUSE "
Label1.text=" FARE "
Label2.text=" BİLGİSAYAR "
Label3.text=" KLAVYE "
Label4.text=" TUŞ "
Label5.text=" KLİK "

Else
If Label6.Text=" 4 " Then
bas.text=" OJE "
Label1.text=" TIRNAK "
Label2.text=" RENK "
Label3.text=" SÜRMEK "
Label4.text=" ASETON "
Label5.text=" MANİKÜR "

Else
If Label6.Text=" 5 " Then
bas.text=" KAFATASI "
Label1.text=" BEYİN "
Label2.text=" SAÇ "
Label3.text=" KEMİK "
Label4.text=" ARKEOLOJİ "
Label5.text = "KAZI"


it continues like this
 
Upvote 0

wasro

Member
My English is very poor and I use the translation. Actually, I wanted to make a taboo game, but in the first post it gives the error in the picture.
all codes in one module. Did you ask that
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
If Label6.Text="1" Then
bas.text=" TAVLA"
Label1.text="ZAR"
Label2.text="OYUN"
Label3.text="YENMEK"
Label4.text="MARS"
Label5.text="KAPI"



Else

Cripes , How about using a select statement.
B4X:
select label6.text

case "1"
  do something (in a function)
 
  case "2"
  do something else ( in a function)
 
 end select
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
OR, you could hold all of the data in a text file. for example, "yourgamedata"
Each line in the textfile should the comma separated text.
Then load this into a map of maps.

Then
B4X:
Sub initdata
   ' gamedata is a global variable defined as a map
    gamedata.Initialize
    Private datalst As List = File.ReadList(File.DirAssets,"yourgamedata")

   ' Assumes the first line of the file is the header line, else set to 0
    For i = 1 To datalst.size-1
        Private v As String = i
        Private thisrow() As String = Regex.Split(",",datalst.Get(i))
        gamedata.Put(v,CreateMap("bas":thisrow(0),"label1":thisrow(1),"label2":thisrow(2),"label3":thisrow(3),"label4":thisrow(4),"label5":thisrow(5)))
    Next
End Sub

Sub dosomething
   ' assumes label6 contains a number else you will get an empty map
    Private fields As Map = gamedata.getdefault(label6.text,CreateMap())
    bas.text= fields.GetDefault("bas","")
    Label1.text=fields.GetDefault("label1","")
    Label2.text=fields.GetDefault("label2","")
    Label3.text=fields.GetDefault("label3","")
    Label4.text=fields.GetDefault("label4","")
    Label5.text=fields.GetDefault("label5","")
End Sub
 
Upvote 0

wasro

Member
shell\src\b4a\tabum\com\main_subs_0.java:8233: error: code too large for try statement
catch (Exception e) {
^
OR, you could hold all of the data in a text file. for example, "yourgamedata"
Each line in the textfile should the comma separated text.
Then load this into a map of maps.

Then
B4X:
Sub initdata
   ' gamedata is a global variable defined as a map
    gamedata.Initialize
    Private datalst As List = File.ReadList(File.DirAssets,"yourgamedata")

   ' Assumes the first line of the file is the header line, else set to 0
    For i = 1 To datalst.size-1
        Private v As String = i
        Private thisrow() As String = Regex.Split(",",datalst.Get(i))
        gamedata.Put(v,CreateMap("bas":thisrow(0),"label1":thisrow(1),"label2":thisrow(2),"label3":thisrow(3),"label4":thisrow(4),"label5":thisrow(5)))
    Next
End Sub

Sub dosomething
   ' assumes label6 contains a number else you will get an empty map
    Private fields As Map = gamedata.getdefault(label6.text,CreateMap())
    bas.text= fields.GetDefault("bas","")
    Label1.text=fields.GetDefault("label1","")
    Label2.text=fields.GetDefault("label2","")
    Label3.text=fields.GetDefault("label3","")
    Label4.text=fields.GetDefault("label4","")
    Label5.text=fields.GetDefault("label5","")
End Sub

Is there a sample project for this?

"case" also gave this error. I couldn't.

shell\src\b4a\tabum\com\main_subs_0.java:8233: error: code too large for try statement
catch (Exception e) {
^
 
Upvote 0

Peter Simpson

Expert
Licensed User
But I couldn't manage.
Couldn't manage what exactly?

Using an SQLite database is what I would personally recommend you to use, there's no need to use If/Case etc. SQLite is simple enough to implement and there are lots of developers on here that can help you to create and manage your database if you ask the correct questions on the forum...
 
Upvote 0
Top