How To Get Item/Value of a List HELP

ferdztech

Member
Licensed User
Longtime User
How To Get/fetch The item/element of a list , i used split function, Is there any solution, so that i can assign each value to a variable :BangHead:

B4X:
Sub ParseData

        Dim strBuffer As String 
   Dim strWatt As String
   Dim strVA As String 
   Dim strVAR As String
   Dim strPF As String
   Dim strVolt As String
   Dim strAmp As String
   Dim strKwPs As String
   Dim strKwHr As String
   Dim myDevID As String

        Dim myPowList As List

        myPowList.Initialize  

'WATT:0.0,VA:0.0,VAR:0.4,PF:0.0000,VOLT:244.6,AMP:0.0000,KW/S:0.0000 D3
'strBuffer="WATT:0.0,VA:0.0,VAR:0.4,PF:0.0000,VOLT:244.6,AMP:0.0000,KW/S:0.0000 D3"

strBuffer="WATT:14.6,VA:17.9,VAR:9.8,PF:0.8183,VOLT:238.9,AMP:0.0755,KW/S:0.0146 D1"

myDevID=s.Right(strBuffer,1)  
myDevID=myDevID.Trim 

strBuffer=strBuffer.Replace(":","")  
strBuffer=strBuffer.Replace(" ","")
strBuffer=strBuffer.Replace("WATT","")
strBuffer=strBuffer.Replace("VOLT","")
strBuffer=strBuffer.Replace("VAR","")
strBuffer=strBuffer.Replace("VA","")
strBuffer=strBuffer.Replace("PF","")
strBuffer=strBuffer.Replace("AMP","")
strBuffer=strBuffer.Replace("KW/S","")
strBuffer=strBuffer.Replace("R","")
strBuffer=s.Left(strBuffer,strBuffer.length-2)  

Log(strBuffer) '14.6,17.9,9.8,0.8183,238.9,0.0755,0.0146

myPowList.AddAll(Array As String(s.Split(strBuffer," ")))    

'I Getting Error here , Cant fetch/get each item of a list
strWatt=myPowList.Get(0) 
strVA =myPowList.Get(1) 
strVAR =myPowList.Get(2) 
strPF =myPowList.Get(3) 
strVolt =myPowList.Get(4) 
strAmp =myPowList.Get(5)
strKwPs =myPowList.Get(6)

Thanks..
 

Mahares

Expert
Licensed User
Longtime User
Try this code. It will display each value individually:
B4X:
Dim MyValue() As String
Dim strBuffer As String
strBuffer="WATT:14.6,VA:17.9,VAR:9.8,PF:0.8183,VOLT:238.9,AMP:0.0755,KW/S:0.0146 D1"
MyValue=Regex.Split(",",strBuffer)
MyValue(0)=MyValue(0).SubString(MyValue(0).IndexOf(":")+1)
MyValue(1)=MyValue(1).SubString(MyValue(1).IndexOf(":")+1)
MyValue(2)=MyValue(2).SubString(MyValue(2).IndexOf(":")+1)
MyValue(3)=MyValue(3).SubString(MyValue(3).IndexOf(":")+1)
MyValue(4)=MyValue(4).SubString(MyValue(4).IndexOf(":")+1)
MyValue(5)=MyValue(5).SubString(MyValue(5).IndexOf(":")+1)
MyValue(6)=MyValue(6).SubString(MyValue(6).IndexOf(":")+1)
MyValue(6)=MyValue(6).SubString2(0,MyValue(6).Length-3)

Msgbox(MyValue(0) & CRLF &MyValue(1) & CRLF &MyValue(2) & CRLF &MyValue(3) _
& CRLF & MyValue(4) & CRLF &MyValue(5)& CRLF &MyValue(6) ,"")
This will give you: 14.6 17.9 9.8 0.8183 238.9 0.0755 0.0146
 
Upvote 0
Top