Android Question Object initialization issue with one version though not present in another!

shank_devdroid

Member
Licensed User
Longtime User
Dear Team,

I am developing applications for our Home Automation customers, i build the same code with different number of rooms as per the requirement of the customer.
Initially for single room, the code works fine, but when i increase the rooms and use the same code, i get
object not initialized.

Now to my understanding there are around 400 buttons which I are declared how can I initialize each one of them?
and it works for a single room quite smoothly, why it is not working for the same section when rooms are increased.
I am attaching the code and the screen shots for your reference.
B4X:
Private pnlHome As Panel
    Private ImageView1 As ImageView
    Private pnlLighting As Panel
    Private pnlMain As Panel
    Private pnlTempControl As Panel
    Private pnlTopBar As Panel
    Private ImageView2 As ImageView
    Private pnlSTB As Panel
    Private btnRoom1 As Button
    Private pnlEntertainment As Panel
    Private btnEntertainment As Button
    Private btnLightingControl As Button
    Private btnTempControl As Button
    Private btnSecurity As Button
    Private btnTelevision As Button
    Private pnlTelevision As Panel
    Private pnlSecurity As Panel
    Private pnlDVD As Panel
    Private pnlChnlList As Panel
    Private pnlSurveillance As Panel
    Private pnlEngMovies As Panel
    Private pnlHinEnt As Panel
    Private pnlHinNews As Panel
    Private pnlHinMovies As Panel
    Private pnlKannada As Panel
    Private pnlKids As Panel
    Private pnlMalayalam As Panel
    Private pnlMarathi As Panel
    Private pnlMusic As Panel
    Private pnlActive As Panel
    Private pnlPunjabi As Panel
    Private pnlOryBen As Panel
    Private pnlSports As Panel
    Private pnlTamil As Panel
    Private pnlTelugu As Panel
    Private pnlHD As Panel
    Private pnlDoordarshan As Panel
    Private pnlEngNews As Panel
    Private pnlEngEnt As Panel
    Private pnlSecurity_Control As Panel
    Private btnRoom2 As Button
    Private btnRoom3 As Button
    Private btnRoom4 As Button
    Private btnRoom5 As Button
    Private btnA1 As Button
    Private btnA2 As Button
    Private btnA3 As Button
    Private btnA4 As Button
    Private btnAllOff As Button
    Private btnCurtClose As Button
    Private btnCurtOpn As Button
    Private btnCurtStop As Button
    Private btnS1 As Button
    Private btnS2 As Button
    Private btnS3 As Button
    Private btnS4 As Button
    Private btnS5 As Button
    Private btnS6 As Button
    Private btnS7 As Button
    Private btnS8 As Button
    Private btnSetRGB As Button
    Private pnlBlue As Panel
    Private pnlGreen As Panel
    Private pnlRed As Panel
    Private pnlSetRGB As Panel
    Private sbrBlue As SeekBar
    Private sbrch01 As SeekBar
    Private sbrch02 As SeekBar
    Private sbrFan As SeekBar
    Private sbrGreen As SeekBar
    Private sbrRed As SeekBar
    Private btnDVD As Button
    Private btnSTB As Button
    Private btnACPwr As Button
    Private btnFanHM As Button
    Private btnFanLM As Button
    Private btnFanMM As Button
    Private btnTemp18 As Button
    Private btnTemp20 As Button
    Private btnTemp22 As Button
    Private btnTemp24 As Button
    Private btnTemp26 As Button
    Private btnTemp28 As Button
    Private btnTempCold As Button
    Private btnTempHot As Button
    Private btnSurveillance As Button
    Private btnTVDown As Button
    Private btnTVHome As Button
    Private btnTVLeft As Button
    Private btnTVMenu As Button
    Private btnTVMute As Button
    Private btnTVPwr As Button
    Private btnTVReturn As Button
    Private btnTVRight As Button
    Private btnTVSel As Button
    Private btnTVSource As Button
    Private btnTVUp As Button
    Private btnVolDec As Button
    Private btnVolInc As Button
    Private btnMute As Button
    Private btnSTBBack As Button
    Private btnSTBBlank1 As Button
    Private btnSTBCDec As Button
    Private btnSTBCInc As Button
    Private btnSTBDown As Button
    Private btnSTBFav As Button
    Private btnSTBGuide As Button
    Private btnSTBNum0 As Button
    Private btnSTBNum1 As Button
    Private btnSTBNum2 As Button
    Private btnSTBNum3 As Button
    Private btnSTBNum4 As Button
    Private btnSTBNum5 As Button
    Private btnSTBNum6 As Button
    Private btnSTBNum7 As Button
    Private btnSTBNum8 As Button
    Private btnSTBNum9 As Button
    Private btnSTBPower As Button
    Private btnSTBSel As Button
    Private btnSTBUp As Button
    Private btnSTBVolDec As Button
    Private btnSTBVolInc As Button
    Private btnTataSky As Button
   
    Private btnDVDEject As Button
    Private btnDVDFF As Button
    Private btnDVDFR As Button
    Private btnDVDMute As Button
    Private btnDVDPlay As Button
    Private btnDVDPwr As Button
    Private btnDVDSources As Button
    Private btnDVDVDec As Button
    Private btnDVDVInc As Button
   
   
    Private btnChActive As Button
    Private btnChDoordarshan As Button
    Private btnChEngEnt As Button
    Private btnChEngMovies As Button
    Private btnChEngNews As Button
    Private btnChHD As Button
    Private btnChHinEnt As Button
    Private btnChHinMovies As Button
    Private btnChHinNews As Button
    Private btnChKanada As Button
    Private btnChKids As Button
    Private btnChKnowledge As Button
    Private btnChMalyalam As Button
    Private btnChMarathi As Button
    Private btnChMusic As Button
    Private btnChOryBen As Button
    Private btnChPunjabi As Button
    Private btnChSports As Button
    Private btnChTamil As Button
    Private btnChTelugu As Button
    Private lblChnlList As Label
   
    Private btnActiveCooking As Button
    Private btnActiveDarshan As Button
    Private btnActiveDoordarshan As Button
    Private btnActiveEnglish As Button
    Private btnActiveFunLearn As Button
    Private btnActiveMusic As Button
    Private btnActiveRet As Button
    Private btnActiveSmrtGames As Button
    Private btnActiveVedicMat As Button
   
    Private btnAxn As Button
    Private btnCmdyCntrl As Button
    Private btnDiskvrytrbo As Button
    Private btnEngEntRet As Button
    Private btnFTv As Button
    Private btnFx As Button
    Private btnFxCrime As Button
    Private btnNdtvGood As Button
    Private btnStarWorld As Button
    Private btnTLC As Button
    Private btnZcafe As Button
   
    Private btnDDBangla As Button
    Private btnDDBharati As Button
    Private btnDDChandana As Button
    Private btnDDGyanDarshan As Button
    Private btnDDLoksabha As Button
    Private btnDDNational As Button
    Private btnDDNews As Button
    Private btnDDOriya As Button
    Private btnDDPodhigai As Button
    Private btnDDRajyasabha As Button
    Private btnDDSayadri As Button
    Private btnDDSports As Button
    Private btnDDUrdu As Button
    Private btnDDRet As Button
   
    Private btnFoxActn As Button
    Private btnHbo As Button
    Private btnMgm As Button
    Private btnMoviesnow As Button
    Private btnPix As Button
    Private btnStatmovies As Button
    Private btnWb As Button
    Private btnZeeStudio As Button
    Private btnEngMoviesRet As Button
   
    Private btnAljazeera As Button
    Private btnBBC As Button
    Private btnBloomberg As Button
    Private btnCnbc As Button
    Private btnCnn As Button
    Private btnCnnIbn As Button
    Private btnETNow As Button
    Private btnHhlintdy As Button
    Private btnNDTV24X7 As Button
    Private btnNDTVPrfit As Button
    Private btnTimesNow As Button
    Private btnEngNewsRet As Button
   
    Private btnZstudioHD As Button
    Private btnColorsHD As Button
    Private btnDiscvryHd As Button
    Private btnStrSprtHd1 As Button
    Private btnStrSprtHd2 As Button
    Private btnMtunesHd As Button
    Private btnMoviesNowHD As Button
    Private btnNatGeoHd As Button
    Private btnStrGldHd As Button
    Private btnStrMoviesHd As Button
    Private btnStrPlusHd As Button
    Private btnStrWrldHd As Button
    Private btnSonyHd As Button
    Private btnZeeTvHd As Button
    Private btnZeeCinemaHd As Button
    Private btnTenHd As Button
    Private btnSonySixHd As Button
    Private btnCnbcTv18Hd As Button
    Private btnLifeOkHd As Button
    Private btnHDRet As Button
   
    Private btnColors As Button
    Private btnSab As Button
    Private btnSaharaOne As Button
    Private btnSony As Button
    Private btnLifeOk As Button
    Private btnStarPlus As Button
    Private btnStarUtsav As Button
    Private btnBindas As Button
    Private btnZeeTv As Button
    Private btnZeeAnmol As Button
    Private btnV As Button
    Private btnHinEntRet As Button
   
    Private btnFilmy As Button
    Private btnSetMax As Button
    Private btnMoviesOk As Button
    Private btnStarGold As Button
    Private btnUtvAction As Button
    Private btnUtvMovies As Button
    Private btnZeeClasic As Button
    Private btnZeeCinema As Button
    Private btnPictures As Button
    Private btnHinMovRet As Button
   
    Private btnAajtak As Button
    Private btnCnbcAwaaz As Button
    Private btnIbn7 As Button
    Private btnIndiaTv As Button
    Private btnIndiaNews As Button
    Private btnNDTVIndia As Button
    Private btnNews24 As Button
    Private btnNewsLive As Button
    Private btnAbpNews As Button
    Private btnZeeBusns As Button
    Private btnZeeNews As Button
    Private btnNewsExprs As Button
    Private btnNewsNation As Button
    Private btnHinNwsRet As Button
   
    Private btnUdayaTv As Button
    Private btnUdayaMovies As Button
    Private btnETVKanada As Button
    Private btnTV9Kanada As Button
    Private btnUdayaMusic As Button
    Private btnUdayaVart As Button
    Private btnAsianetSuvarna As Button
    Private btnZeeKanada As Button
    Private btnKasturiTv As Button
    Private btnSuvarnaNws As Button
    Private btnUdayaComedy As Button
    Private btnSriSankaraTv As Button
    Private btnKanadaRet As Button
   
    Private btnCartNet As Button
    Private btnDiscKids As Button
    Private btnDisney As Button
    Private btnHungama As Button
    Private btnNick As Button
    Private btnPogo As Button
    Private btntoondisny As Button
    Private btnSonicNick As Button
    Private btnBabyTv As Button
    Private btnNickJr As Button
    Private btnDisnyJr As Button
    Private btnZq As Button
    Private btnKidsRet As Button
   
    Private btnNGC As Button
    Private btnFoxTraveler As Button
    Private btnNGCWild As Button
    Private btnDiscovery As Button
    Private btnAnimalPlanet As Button
    Private btnDiscScience As Button
    Private btnHistory As Button
    Private btnFoodFood As Button
    Private btnKhanaKajana As Button
    Private btnTopper As Button
    Private btnKnowledgeRet As Button
   
    Private btnSurya As Button
    Private btnKiran As Button
    Private btnAsianet As Button
    Private btnAsianetNws As Button
    Private btnAsianetplus As Button
    Private btnAsianetMovies As Button
    Private btnAmritaTv As Button
    Private btnMazhavilMan As Button
    Private btnKairaliTv As Button
    Private btnWeTv As Button
    Private btnKochuTv As Button
    Private btnManoramaNws As Button
    Private btnIndiaVison As Button
    Private btnJaihindTv As Button
    Private btnReporterTv As Button
    Private btnJeevanTv As Button
    Private btnMathrubhuminws As Button
    Private btnGodTv As Button
    Private btnShalomTv As Button
    Private btnMalyalamRet As Button
   
    Private btnEtvMarathi As Button
    Private btnZeeMarathi As Button
    Private btnMiMarathi As Button
    Private btnAboMajha As Button
    Private btnStarPravah As Button
    Private btnIBNLokmat As Button
    Private btnZee24Taas As Button
    Private btnZeeTalkies As Button
    Private btnSaamTv As Button
    Private btn9xJhakaas As Button
    Private btnJaiMaha As Button
    Private btnMarathiRet As Button
   
    Private btnMTV As Button
    Private btn9XM As Button
    Private btnZoom As Button
    Private btnE24 As Button
    Private btnUTVStars As Button
    Private btnSonyMix As Button
    Private btnMTunes As Button
    Private btnVH1 As Button
    Private btnMusicRet As Button
   
    Private btnAbpAnanda As Button
    Private btnEtvBangla As Button
    Private btnZeeBangla As Button
    Private btnAakashAath As Button
    Private btnStarJalsha As Button
    Private btn24Ghanta As Button
    Private btnSonyAath As Button
    Private btnSangeetBangla As Button
    Private btnJalsaMovies As Button
    Private btnZbanglaCinema As Button
    Private btnKolkataTv As Button
    Private btnETVOdia As Button
    Private btnTarrangTv As Button
    Private btnTarangMusic As Button
    Private btnOTv As Button
    Private btnSathak As Button
    Private btnPrathanaTv As Button
    Private btnOryBenRet As Button
   
    Private btnMh1 As Button
    Private btnZpunHarHim As Button
    Private btnPTCNews As Button
    Private btnPTCPunjabi As Button
    Private btnPTCChakde As Button
    Private btnETCPunjabi As Button
    Private btn9XTashan As Button
    Private btnPunjabiRet As Button
   
    Private btnStarSprt1 As Button
    Private btnStarSprt2 As Button
    Private btnStarSprt3 As Button
    Private btnStarSprt4 As Button
    Private btnTenSprts As Button
    Private btnTenCricket As Button
    Private btnTenAction As Button
    Private btnSonySix As Button
    Private btnSportsRet As Button
   
    Private btnSunTv As Button
    Private btnKTV As Button
    Private btnSunNews As Button
    Private btnSunMusic As Button
    Private btnChuttiTv As Button
    Private btnStarBijay As Button
    Private btnJayaTv As Button
    Private btnKalignarTv As Button
    Private btnRajTv As Button
    Private btnIsaiAruvi As Button
    Private btnAdithyaTv As Button
    Private btnPuthiyaThala As Button
    Private btnVasanthTv As Button
    Private btnmurasu As Button
    Private btnjayamax As Button
    Private btnSirippoli As Button
    Private btnPolimer As Button
    Private btnThanthiTv As Button
    Private btnMakkalTv As Button
    Private btnTamilRet As Button
   
    Private btnGeminiMovies As Button
    Private btnSakshiTv As Button
    Private btnZeeTelugu As Button
    Private btnGeminiTv As Button
    Private btnGeminiComedy As Button
    Private btnGeminiMusic As Button
    Private btnETVTelugu As Button
    Private btnETV2 As Button
    Private btnMaaTv As Button
    Private btnTv5 As Button
    Private btnTv9 As Button
    Private btnNTVNews As Button
    Private btnMaaMovies As Button
    Private btnMaaMusic As Button
    Private btnAbnAndhraJyothi As Button
    Private btnTNews As Button
    Private btnSVBC As Button
    Private btnBhaktiTv As Button
    Private btnSubhavaartha As Button
    Private btnTeluguReturn As Button
    Private btnSecuPanic As Button
    Private btnSecuUnArm As Button
    Private btnSecuDoorUnLock As Button
    Private btnSecuAway As Button
    Private btnSecuAtHome As Button
    Private btnSecuDoorLock As Button
   
    Private WebView1 As WebView
    Private btnSecurity_Control As Button
    Private pnlKnowledge As Panel

Here I have used almost these many buttons, panels, seekbars and what not!
When I initialize it in the Activity_Create Section it doesn't throw error, but how many times should I initialize it?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Room_Change")
   
    Activity.LoadLayout("main")
   
'    Activity.LoadLayout("password")
    Socket1.Initialize("Socket1")
    Socket1.Connect("192.168.0.125",8081,2000)
    ProgressDialogShow("Loading...")
    DoEvents
'    Rm1Rval=0
    sbrRed.Initialize("sbrRed")
    sbrGreen.Initialize("sbrGreen")
    sbrBlue.Initialize("sbrBlue")
    pnlSetRGB.Initialize("pnlsetrgb")
    sbrFan.Initialize("sbrfan")
    sbrch01.Initialize("sbrch01")
    sbrch02.Initialize("sbrch02")
    btnA1.Initialize("a1")
    btnA2.Initialize("A2")

Please help me since the problem is untraceable for me, attaching the screenshot for the same.

B4X:
Sub btnRoom1_Click
    'Activity.LoadLayout("Home")
    'pnlHome.LoadLayout("Home")
'    btnLightingControl.SetBackgroundImage(LoadBitmap(File.DirAssets,"lighting.png"))
'    btnTempControl.SetBackgroundImage(LoadBitmap(File.DirAssets,"temp.png"))
'    btnEntertainment.SetBackgroundImage(LoadBitmap(File.DirAssets,"music-entertainment-psd-icon.png"))
'    btnSecurity.SetBackgroundImage(LoadBitmap(File.DirAssets,"security.png"))
    pnlHome.Visible=True
    pnlHome.BringToFront
    pnlMain.Visible=False
    pnlLighting.Visible=False
    pnlTempControl.Visible=False
    pnlEntertainment.Visible=False
    pnlTelevision.Visible=False
    pnlSTB.Visible=False
    pnlSecurity.Visible=False
    pnlDVD.Visible=False
    pnlChnlList.Visible=False
    pnlSurveillance.Visible=False
    pnlSecurity_Control.Visible=False
       
    Addr = "000"
'    sbrRed.Initialize("sbrRed")
    sbrRed.Value = Rm1Rval
    sbrGreen.Value = Rm1Gval
    sbrBlue.Value = Rm1Bval
    pnlSetRGB.Color=Colors.RGB(Rm1Rval,Rm1Gval,Rm1Bval)
   
    sbrFan.Value = Rm1Fspd
    sbrch01.Value = Rm1Ch0val
    sbrch02.Value = Rm1Ch1val
   
    If Rm1Ap1Sw = 0 Then
        Dadd = "a0"
        btnA1.SetBackgroundImage(LoadBitmap(File.DirAssets,"a1-up.png"))
        Else
        Dadd = "a1"
        btnA1.SetBackgroundImage(LoadBitmap(File.DirAssets,"a1-dwn.png"))
    End If
    If Rm1Ap2Sw = 0 Then
        Dadd = "b0"
        btnA2.SetBackgroundImage(LoadBitmap(File.DirAssets,"a2-up.png"))
    Else
        Dadd = "b1"
        btnA2.SetBackgroundImage(LoadBitmap(File.DirAssets,"a2-dwn.png"))
    End If
    If Rm1Ap3Sw = 0 Then
        Dadd = "c0"
        btnA3.SetBackgroundImage(LoadBitmap(File.DirAssets,"a3-up.png"))
    Else
        Dadd = "c1"
        btnA3.SetBackgroundImage(LoadBitmap(File.DirAssets,"a3-dwn.png"))
    End If
    If Rm1Ap4Sw = 0 Then
        Dadd = "d0"
        btnA4.SetBackgroundImage(LoadBitmap(File.DirAssets,"a4-up.png"))
    Else
        Dadd = "d1"
        btnA4.SetBackgroundImage(LoadBitmap(File.DirAssets,"a4-dwn.png"))
    End If
   
    Select Case Rm1Scn
        Case 0
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 1
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-dwn.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 2
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-dwn.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 3
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-dwn.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 4
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-dwn.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 5
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-dwn.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 6
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-dwn.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 7
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-dwn.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-up.png"))
        Case 8
            btnS1.SetBackgroundImage(LoadBitmap(File.DirAssets,"s1-up.png"))
            btnS2.SetBackgroundImage(LoadBitmap(File.DirAssets,"s2-up.png"))
            btnS3.SetBackgroundImage(LoadBitmap(File.DirAssets,"s3-up.png"))
            btnS4.SetBackgroundImage(LoadBitmap(File.DirAssets,"s4-up.png"))
            btnS5.SetBackgroundImage(LoadBitmap(File.DirAssets,"s5-up.png"))
            btnS6.SetBackgroundImage(LoadBitmap(File.DirAssets,"s6-up.png"))
            btnS7.SetBackgroundImage(LoadBitmap(File.DirAssets,"s7-up.png"))
            btnS8.SetBackgroundImage(LoadBitmap(File.DirAssets,"s8-dwn.png"))
    End Select
    Select Case Rm1Drp
        Case 0
        Case 1
        Case 2
    End Select
    If Rm1Acpwr = 0 Then
    btnACPwr.SetBackgroundImage(LoadBitmap(File.DirAssets,"acpower-up.png"))
    Else
     btnACPwr.SetBackgroundImage(LoadBitmap(File.DirAssets,"acpower-dwn.png")) 
    End If
    Select Case Rm1AcMod
        Case 0
        btnTempHot.SetBackgroundImage(LoadBitmap(File.DirAssets,"modeh-up.png"))
        btnTempCold.SetBackgroundImage(LoadBitmap(File.DirAssets,"modec-up.png"))   
        Case 1
        btnTempHot.SetBackgroundImage(LoadBitmap(File.DirAssets,"modeh-up.png"))
        btnTempCold.SetBackgroundImage(LoadBitmap(File.DirAssets,"modec-dwn.png"))   
        Case 2
        btnTempHot.SetBackgroundImage(LoadBitmap(File.DirAssets,"modeh-dwn.png"))
        btnTempCold.SetBackgroundImage(LoadBitmap(File.DirAssets,"modec-up.png"))   
        End Select
    Select Case Rm1AcTmp
        Case 0
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-up.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-up.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-up.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-up.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-up.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-up.png"))
        Case 18
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-dwn.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-up.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-up.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-up.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-up.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-up.png"))
        Case 20
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-up.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-dwn.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-up.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-up.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-up.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-up.png"))
        Case 22
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-up.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-up.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-dwn.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-up.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-up.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-up.png"))
        Case 24
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-up.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-up.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-up.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-dwn.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-up.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-up.png"))
        Case 26
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-up.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-up.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-up.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-up.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-dwn.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-up.png"))
        Case 28
            btnTemp18.SetBackgroundImage(LoadBitmap(File.DirAssets,"18-up.png"))   
            btnTemp20.SetBackgroundImage(LoadBitmap(File.DirAssets,"20-up.png"))
            btnTemp22.SetBackgroundImage(LoadBitmap(File.DirAssets,"22-up.png"))
            btnTemp24.SetBackgroundImage(LoadBitmap(File.DirAssets,"24-up.png"))
            btnTemp26.SetBackgroundImage(LoadBitmap(File.DirAssets,"26-up.png"))
            btnTemp28.SetBackgroundImage(LoadBitmap(File.DirAssets,"28-dwn.png"))
    End Select
   
    Select Case Rm1AcFspd
        Case 0
            btnFanLM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanlowmode-up.png"))   
            btnFanMM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanmediummode-up.png"))
            btnFanHM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanhighmode-up.png"))
        Case 1
            btnFanLM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanlowmode-dwn.png"))   
            btnFanMM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanmediummode-up.png"))
            btnFanHM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanhighmode-up.png"))
        Case 2
            btnFanLM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanlowmode-up.png"))   
            btnFanMM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanmediummode-dwn.png"))
            btnFanHM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanhighmode-up.png"))
        Case 3
            btnFanLM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanlowmode-up.png"))   
            btnFanMM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanmediummode-up.png"))
            btnFanHM.SetBackgroundImage(LoadBitmap(File.DirAssets,"fanhighmode-dwn.png"))
            End Select
    If Rm1TvPwr = 0 Then
   
    Else
   
    End If
    If Rm1StbPwr = 0 Then
   
    Else
   
    End If
           
End Sub


Screenshot_2016-09-12-15-36-34.png

Screenshot_2016-09-12-15-36-43.png
Screenshot_2016-09-12-15-36-50.png
 

LucaMs

Expert
Licensed User
Longtime User
Uhm... too many buttons and panels, I think... most likely you should use more than one Activity.

However, it is simple, you must initialize a button (or any other view) in the code only if you have not already loaded it via a layout.

So if btnA3 was created by the designer and then it is part of your Main layout, you must not initialize it in the code.

In addition, it is perhaps not so obvious, nor is it necessary to declare a button (created by the Designer) if it is not used but only the relative event routine is used .
 
Last edited:
Upvote 0

shank_devdroid

Member
Licensed User
Longtime User
Hi @LucaMs
Thanks for the update, I have copy pasted the designer files to the files folder of this project since I need
to redevelop the app again and again for different customers.

The buttons are created in the designer hence I am not initializing it in the Activity_Create sub of the Automation named layout.
The Main layout calls the Automation layout.
Why this is happening?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi @LucaMs
Thanks for the update, I have copy pasted the designer files to the files folder of this project since I need
to redevelop the app again and again for different customers.

The buttons are created in the designer hence I am not initializing it in the Activity_Create sub of the Automation named layout.
The Main layout calls the Automation layout.
Why this is happening?

Do you mean to say that you upload the layout "Main" in Activity_Create and you upload the layout "Automation" at a later time?

It should work, but you can not have two or more loaded layout at the same time.
https://www.b4x.com/android/forum/threads/how-to-remove-layout-at-runtime.21701/


Moreover, I had not looked at the last picture; in that case, the file a2_up.png is missing in DirAssets (it was not added in the Files Tab).
 
Upvote 0

shank_devdroid

Member
Licensed User
Longtime User
Yes in the Main layout, I upload the first layout which is for password, once the password authentication is done,
I load the Automation layout by calling the StartActivity() and CallSubDelayed() methods,
B4X:
Log("login successful")
                Msgbox("Login Successful", "HURRAY!!!")
                resetAllPassword
                StartActivity(Automation)
                CallSubDelayed(Automation, "Activity_Create")               
               
                               
            Else
                Log("Wrong password!!")
                Msgbox("Wrong Password!! Please enter again!", "OOPSS!!")
[\CODE]

Okay I will add them still the problem exists, How is it possible when we just copy paste the designer file in a new project
and copy the respective code and compile it, only 20% code needs to change when we add the rooms.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
StartActivity(Automation)
CallSubDelayed(Automation,
"Activity_Create")
You should not call Activity_Create, just use StartActivity. In its Activity_Create routine you should load the Automation layout, of course, and its views must be declared there, not in the Main Activity.


Okay I will add them still the problem exists, How is it possible when we just copy paste the designer file in a new project
and copy the respective code and compile it, only 20% code needs to change when we add the rooms.
To have also the activity code, not only the layout, you can share the activity:
https://www.b4x.com/android/forum/threads/shared-code-modules.40747/
 
Upvote 0

shank_devdroid

Member
Licensed User
Longtime User
Hi @LucaMs

One more question, in terms of share modules what should I share?
Can we share the .bals, files like images/icon images etc?

Please need your help in this.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Okay thanks for the information :)
Please suggest what files can I share in the directory

Thank you so much in advance!
I think you should use the shared folder to share code modules (utilities) and classes.

You can also share an Activity; when you add it to your new project you can watch at the Log Tab to know which files are missing and add them "manually".
I think that in this case you could create your own [ActivityName]_Files folder, maybe inside to an higher level folder (SharedActivities_Files). Unfortunately, you must mantain updated these files manually, but it could be a good "solution".
 
Upvote 0
Top