Is there a simpler way on breaking up an array from a reply from website?

Lostmymind

Banned
Is there a simpler way on breaking up an array from a reply from website?
Right now I go this route.
it does work but if the website changes or things get added then I have update the code. Is fine since it works but I would like it to auto change and add when there are changes to the website.
Here is the code…
B4X:
Dim HD As Float

 	 If parser.Parents.IndexOf("DeviceTextResponse") > -1 Then
		If Name = "DeviceText" Then 
			Device_txt.Text = Text.ToString
			Job2.Download2("https://www.energysmartwaterheater.com:443/latestHistoryGet.php", _
				Array As String("DeviceText", Device_txt.Text))
		End If
		
   Else If parser.Parents.IndexOf("TempResponse") > -1 Then
     If Name = "SetPoint" Then 
			Temp_Txt.Text = Text.ToString
		End If
	
		If Name = "Units" Then
			DegreesSign.Text = Text.ToString
		If DegreesSign.Text = "C" Then
				DegC = Temp_Txt.Text
				DegF = DegC*9/5+32				
			Else If DegreesSign.Text= "F" Then
				DegF = Temp_Txt.Text
				DegC = (DegF-32)*5/9
			End If
	End If
	
		If Name = "mode" Then
		If Text.ToString = "Standard" Then 
				Standard_Btn.text = True
			Else If Text.ToString = "Vacation" Then 
				Vacation_Btn.text = True
			Else If Text.ToString = "EnergySmart" Then 
				EnergySmart_Btn.text = True
			End If
	End If
	
	If Name = "Grid" Then
			If Text.ToString = "Disabled" Then
				Grid_on_btn.enabled = True
			Grid_on_btn.Visible = True
				Grid_off_btn.Enabled = False
				Grid_off_btn.Visible= False
			Else If Text.ToString = "Enabled" Then
			Grid_on_btn.enabled = False
				Grid_on_btn.Visible = False
				Grid_off_btn.Enabled = True
				Grid_off_btn.Visible= True
			End If
		End If
	
	If Name = "LeakDetect" Then
			LeakDetect_Txt.Text = Text.ToString
		End If
	
		If Name = "ModuleApi" Then 
		ModuleApi_Txt.Text = Text.ToString
		End If
	
		If Name = "ModFwVer" Then
			ModFwVer_Txt.Text = Text.ToString 
		End If
		
		If Name = "UpdateRate" Then
		UpdateRate_Txt.Text = Text.ToString
		End If
	
		If Name = "HotWaterVol" Then
			HotWaterVol_Txt.Text = Text.ToString
		End If
			
		If Name = "DryFire" Then
			DryFire_Txt.Text = Text.ToString
		End If
		
		If Name = "ElementFail" Then
			ElementFail_Txt.Text = Text.ToString
		End If
	
		If Name = "EcoError" Then
			EcoError_Txt.Text = Text.ToString 
		End If
	
		If Name = "SignalStrength" Then	
			SignalStrength_Txt.Text = Text.ToString 
		End If
	
		If Name = "UpperTemp" Then
			UpperTemp_Txt.Text = Text.ToString 
		End If
	
		If Name = "LowerTemp" Then	
			LowerTemp_Txt.Text = Text.ToString 
		End If
	
		If Name = "FaultCodes" Then
			FaultCodes_Txt.Text = Text.ToString 
		End If
	End If

any help would be great THANKS
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there a simpler way on breaking up an array from a reply from website?
It depends on the response format. In this case this is XML. You can create a more generic parser that will automatically add the values to a Map. However you will still need to update your app if you want to use a new field (or your program uses a field that no longer exists).
 
Upvote 0

Lostmymind

Banned
Else If parser.Parents.IndexOf("TempResponse") > -1 Then
Status_list.AddTwoLines(Name, Chr(9)& Chr(9)& Chr(9)& Chr(9)& Chr(9)& Chr(9)& Chr(9)& Chr(9)& Chr(9)& Chr(9)& Text.ToString)

Change my code over to this and still have the parser still take out the main ones I need for other parts of the program to run. made it simpler.

Thanks Erl
 
Upvote 0
Top