getting code to work again

Lostmymind

Banned
trying to get some code that work in past for me but now I can not get it to work with new version of Android. Here is the code to create and write to a file.

If File.Exists(File.DirInternal, "Device.txt") = True Then
Device_txt.Text = File.ReadString(File.DirInternal, "Device.txt")
Job2.Download2("http://www.energysmartwaterheater.com/latestHistoryGet.php", _
Array As String("DeviceText", Device_txt.Text))

Else If File.Exists(File.DirInternal, "Device.txt") = False Then
File.writestring(File.DirInternal,"Device.txt", "123456")
Device_txt.Text = File.ReadString(File.DirInternal, "Device.txt")
End If

Worked great in my old code but now can not get it to work.
I did try to just write the file and post to the screen but no luck. not sure if I need to add something new or not with the new android Ver 4.2.1
 

Lostmymind

Banned
changed to code to be simple.

I took everything out and just have the file to create the file.

File.writestring(File.DirInternal,"Device.txt", "123456")

and then just to try to read it back.

Device_txt.Text = File.ReadString(File.DirInternal, "Device.txt")

All I get is a blank text box.
 
Upvote 0

Lostmymind

Banned
Erel, here is how I load the Layouts...

code
'This loads in the primary layout for the tabs and screens groups.
Activity.LoadLayout("Main")
'This is to set up the tabs on the program screen.
tabPic1 = LoadBitmap(File.DirAssets, "53-house.png")
tabPic2 = LoadBitmap(File.DirAssets, "GreenHome.png")
Main.AddTabWithIcon ("Home", tabPic1, tabPic2, "Home") '0 page
tabpic3 = LoadBitmap(File.DirAssets, "title_information_icon_edit.png")
tabPic4 = LoadBitmap(File.DirAssets, "GreenStatus.png")
Main.AddTabWithIcon ("Status", tabpic3, tabPic4, "Status") '1 page
tabPic5 = LoadBitmap(File.DirAssets, "title_service_icon_edit.png")
tabPic6 = LoadBitmap(File.DirAssets, "GreenSettings.png")
Main.AddTabWithIcon ("Settings", tabPic5, tabPic6, "Settings") '2 page
Main.AddTab ("Debug", "Debug_Scroll") '3 page
Debug_scroll.Panel.LoadLayout ("Debug")
/code

I do not see where I would load in the Layout twice. unless the name of the tab and the file name is the same could that be a problem?
 
Upvote 0

Lostmymind

Banned
Here is the code and got the posting write.

B4X:
Sub Process_Globals
   
   Dim DegF As Int = 0
   Dim DegC As Int = 0
      
End Sub

Sub Globals
   
   'all on Home view screen
   
   Dim Decrease_btn As Button
   Dim Degrees_Btn As Button
   Dim degreeC_view As ImageView
   Dim degreeF_view As ImageView
   Dim Device_txt As Label
   Dim EnergySmart_Btn As Button
   Dim Grid_Btn As Button
   Dim ImageView1 As ImageView
   Dim Increase_Btn As Button
   Dim Label1 As Label
   Dim Refresh_Btn As Label
   Dim Standard_Btn As Button
   Dim Summit_Btn As Button
   Dim Temp_Txt As EditText
   Dim Vacation_Btn As Button
   Dim Home_Pnl As Panel
'________________________________

   'all on Logon view screen
   
   Dim Login_Btn As Button
   Dim Logon_Pnl As Panel
   Dim NewUser_Btn As Button
   Dim Password_Txt As EditText
   Dim UserName_Txt As EditText
   
'________________________________

   'all on Main view screen (Tabhosting screen)
   
   Dim Main As TabHost
   
'________________________________

   'all on Settings view screen
   
   Dim ChangeUser_btn As Button
   Dim GridQuestion_Btn As Button
   Dim Setting_Pnl As Panel

'_____________________________________

   'all on Status view screen
   Dim Status_Pnl As Panel
   Dim DisplayFwVer_Txt As Label
   Dim DryFire_Txt As Label
   Dim EcoError_Txt As Label
   Dim ElementFail_Txt As Label
   Dim FaultCodes_Txt As Label
   Dim Grid_Txt As Label
   Dim GridCmd_txt As Label
   Dim HotWaterVol_Txt As Label
   Dim LeakDetect_Txt As Label
   Dim LowerTemp_Txt As Label
   Dim MasterDispFail_Txt As Label
   Dim MasterFwVer_Txt As Label
   Dim MaxSetPoint_txt As Label
   Dim Mode_Txt As Label
   Dim ModFwVer_Txt As Label
   Dim ModuleApi_Txt As Label
   Dim SetPoint_Txt As Label
   Dim SignalStrength_Txt As Label
   Dim TankSensorFail_Txt As Label
   Dim Units_Txt As Label
   Dim UpdateRate_Txt As Label
   Dim UpperTemp_Txt As Label
   Dim WifiFwVer_Txt As Label
   
'_____________________________________

   'all on Status view screen (Scrollscreen)
   
   Dim Status_scroll As ScrollView
   
'________________________________________

   'all on Debug_Scroll
   
   Dim Debug_scroll As ScrollView
   Dim Clear_btn As Button
   Dim Debug_txt As Label
'______________________________________

   'Theses dim setting are for the program it self to run and work.
   
   Dim tabPic1, tabPic2, tabpic3, tabPic4, tabPic5, tabPic6  As Bitmap
   Dim Job1, Job2, Job3, Job4 As HttpJob
   Dim parser As SaxParser
   
   
   
End Sub
Sub Activity_Create(FirstTime As Boolean)
   
   'This loads in the primary layout for the tabs and screens groups.
   
   Activity.LoadLayout("Main")
   
   'This is to set up the tabs on the program screen. 
   
   tabPic1 = LoadBitmap(File.DirAssets, "53-house.png")
   tabPic2 = LoadBitmap(File.DirAssets, "GreenHome.png")
   Main.AddTabWithIcon ("Home", tabPic1, tabPic2, "Home1") '0 page
   tabpic3 = LoadBitmap(File.DirAssets, "title_information_icon_edit.png")
   tabPic4 = LoadBitmap(File.DirAssets, "GreenStatus.png")
   Main.AddTabWithIcon ("Status", tabpic3, tabPic4, "Status") '1 page
   tabPic5 = LoadBitmap(File.DirAssets, "title_service_icon_edit.png")
   tabPic6 = LoadBitmap(File.DirAssets, "GreenSettings.png")
   Main.AddTabWithIcon ("Settings", tabPic5, tabPic6, "Settings") '2 page
   Main.AddTab ("Debug", "Debug_Scroll") '3 page
   Debug_scroll.Panel.LoadLayout ("Debug")
   
   ' This starts the memory of the Temp settings until it is read from the web on start up.
   
   If FirstTime Then 
      DegF = 70
      degreeC_view.Visible = False
      degreeF_view.Visible = True
      DegC = (DegF-32)*5/9
   End If
   
      
   'Job1.Initialize("JobGetDevice", Me)
   'Job2.Initialize("JobGetTemp",Me)
   'Job3.Initialize("JobPost",Me)
   'Job4.Initialize("JobgetHistory",Me)
   'parser.Initialize
   
   File.writestring(File.DirInternal,"Device.txt", "123456")
   
   
   'If File.Exists(File.DirInternal, "Device.txt") = True Then
      '   Device_txt.Text = File.ReadString(File.DirInternal, "Device.txt")
      'Job2.Download2("http://www.energysmartwaterheater.com/latestHistoryGet.php", _
      '   Array As String("DeviceText", Device_txt.Text))
         
   'Else If File.Exists(File.DirInternal, "Device.txt") = False   Then
   '   File.writestring(File.DirInternal,"Device.txt", "123456")
   '   Device_txt.Text = File.ReadString(File.DirInternal, "Device.txt")
     'End If
   
      
End Sub
Sub Activity_Pause (Finishing As Boolean)
   
End Sub
Sub Activity_Resume

   UpdateUi
   
End Sub
Sub Decrease_btn_Click
   
   DegF = DegF - 1
   DegC = DegC - 1
   UpdateUi
   
End Sub
Sub Increase_Btn_Click
   
   DegF = DegF + 1
   DegC = DegC + 1
   UpdateUi
   
End Sub

Sub Degrees_Btn_Click
   
   'code to hold the button on true or false depending on the degrees setting you want.
   
   
End Sub

Sub UpdateUi
   
   Temp_Txt.Text = DegF
   
   'If Degress_Btn.Text = True Then
    ' Temp_Txt.Text = DegC
     'DegF = DegC*9/5+32
   'Else If Degress_Btn.Text = False Then
   '  Temp_Txt.Text = DegF
    '  DegC = (DegF-32)*5/9
   'End If
   
   
End Sub
Sub Host_TabChanged
   
   Dim DB As Float
   
      
   Activity.Title = "Current Tab = " & Main.CurrentTab 
   
   If Main.CurrentTab = 0 Then
      Device_txt.Text = File.ReadString(File.DirInternal, "Device.txt")
      
   End If

   
   If Main.CurrentTab = 1 Then
      DisplayFwVer_Txt.Text = ""
      DryFire_Txt.Text = "" 
      EcoError_Txt.Text = "" 
      ElementFail_Txt.Text = ""
      FaultCodes_Txt.Text = ""
      Grid_Txt.Text = ""
      GridCmd_txt.Text = ""
      HotWaterVol_Txt.Text = ""
      LeakDetect_Txt.Text = ""
      LowerTemp_Txt.Text = ""
      MasterDispFail_Txt.Text = ""
      MasterFwVer_Txt.Text = ""
      MaxSetPoint_txt.Text = ""
      Mode_Txt.Text = ""
      ModFwVer_Txt.Text = ""
      ModuleApi_Txt.Text = ""
      SetPoint_Txt.Text = ""
      SignalStrength_Txt.Text = ""
      TankSensorFail_Txt.Text = ""
      Units_Txt.Text = ""
      UpdateRate_Txt.Text = ""
      UpperTemp_Txt.Text = ""
      WifiFwVer_Txt.Text = ""
   End If

   
   
      
End Sub
 
Upvote 0

Lostmymind

Banned
Sorry Klaus I have tried to zip up and post it but I exceeded the limit of the zip file.
 
Upvote 0

Lostmymind

Banned
What is in the layout files "Debug_Scroll" and "Debug" ?
the Debug_scroll is a scrollview and the debug is the text window. in that window gives me the web replies in a string format to make sure the communication is working.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I suppose Main is the TabHost view in the Main layout file.
You load two layout files "Debug_Scroll" and "Debug" what do you have in there.
What is the size of your image files ?
Are those making the zip file so big, or do you have other big files in the projects File folder ?

Best regards.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Coming back to your first question.
This code works:
B4X:
Sub Globals
    Dim edtTest As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    edtTest.Initialize("")
    Activity.AddView(edtTest, 10dip, 10dip, 150dip, 50dip)
End Sub

Sub Activity_Resume
    File.WriteString(File.DirInternal, "Device.txt", "123456")
    
    edtTest.Text = File.ReadString(File.DirInternal, "Device.txt")
End Sub
Best regards.
 
Upvote 0

Lostmymind

Banned
Klaus here is the code.
 

Attachments

  • problemincode.zip
    197.9 KB · Views: 209
Upvote 0

klaus

Expert
Licensed User
Longtime User
There are some mistakes in your code.

1) In the home1 layout:
Device_txt.Left = 400
Device_txt.Top = 1000
so you wont see anything, I put the values to 0.

2) In the Debug_Scroll layout:
Debug_Scroll.Left = -200
the left quarter of the ScrollView would be hidden.

3) In Debug layout:
the background is transparent but the underlying background is black and the text color is black too so you won't see anything too.
Do you really want the Vertical alignment beeing CENTER_VERTICAL ?

4) In the Main layout:
you use AutoScaleAll, you shouldn't use it with none standard layout variants.
In your case there there is no problem because you reset the layout.

5) It is no good practice to use Main as a view name. Main is also the name of the Main module could be confusing.

Attached a modified version.

Best regards.
 

Attachments

  • problemincode_new.zip
    201.4 KB · Views: 217
Upvote 0

Lostmymind

Banned
Thanks for the helpful tips. still have a long way to understand stuff. slowly getting there.


Klaus
 
Upvote 0
Top