Storage 1 = Count
Storage 2 = Counts
I tried to combine or join Some of the lists of values from Count and Counts together using this:
Dim saves, u
Dim saves, i
saves=JSON.parse(localStorage.BrgDst)
For i=0 To UBound(saves)
If saves[i].Count Then
Numb = (saves[i].Count)
RFa =(saves[i].RiseFall)
currentRecord=i
For u = UBound(saves) To 0 Step -1
If saves[u].Counts Then
RFb =(saves[u].RiseFallX)
currentRecord=u
Dim saves(), datix
datix={PNB: Numb, MRa: RFa, MRb: RFb}
saves=JSON.parse(localStorage.BrgDst)
saves.push(datix)
localStorage.BrgDst=JSON.stringify(saves)
End If
Next u
End If
Next i
This is what I want
-
RiseFall = -3.822 RiseFallX = 3.821
-
RiseFall = -0.617 RiseFallX = 0.617
-
RiseFall = 0.363 RiseFallX = -0.364
But this is what I get
-
RiseFall = -3.822 RiseFallX = 3.821
-
RiseFall = -3.822 RiseFallX = 0.617
-
RiseFall = -3.822 RiseFallX = -0.364
-
RiseFall = -0.617 RiseFallX = 3.821
-
RiseFall = -0.617 RiseFallX = 0.617
-
RiseFall = -0.617 RiseFallX = -0.364
-
RiseFall = 0.363 RiseFallX = 3.821
-
RiseFall = 0.363 RiseFallX = 0.617
-
RiseFall = 0.363 RiseFallX = -0.364
Is this possible
Thanks
Will.
Solved (After lots of time, trial and error)
Dim Ax=[]
Dim Saves, i
Dim Saves, u
`Saves=JSON.parse(localStorage.BrgDst)`
For i = UBound(Saves) To 0 Step -1
If Saves[i].Counts Then
Ax.push(Saves[i].RiseFallX)
currentRecord=i
End If
Next
For u =0 To UBound(Saves)
If Saves[u].Count Then
Numc=(Saves[u].Count)
RFb=(Saves[u].RiseFall)
RFc=CDbl((Ax[u])) ''Imported RF values
currentRecord=u
Dim Saves(), datv
datv={CTP: Numc, Ra: RFb, Rh: RFc, Rt: Rfd}
Saves=JSON.parse(localStorage.BrgDst)
Saves.push(datv)
localStorage.BrgDst=JSON.stringify(Saves)
End If
Next
Hi William,
Can you please explain what the 2 statements
Dim saves, i
Dim saves, u
mean? As far as I know you can
A) only declare a variable once - declaring a variable with the same name twice doesnāt make sense to me. If it works, I would expect that āsavesā contains the value of āuā after these 2 statements, and the first one is obsolete.
B) the syntax of the Dim statement allows to provide a simple value - are āiā and āuā these simple values? Then again, why assigning both to the same variable āsavesā ?
Kind regards
Thomas
Thanks for pointing that out Thomas, it seems I can Dim as many Saves as I like and everything works all the same anyway? (Just copy and pasting for speed) Iām an amateur hobbyist who codes for my own profession and if something works iāll use it.
Thanks
Will.
Hi Will,
Iāll test what really happens with 2 DIM statements for the same variable.
In other basic versions this would create an error message. If the system doesnāt generate an error, the only alternative I can think of is that the 2nd statement just overwrites the first one - in other words, you might as well remove the first one, without any difference to the rest of the program.
But maybe more important: what are āiā and āuā ? Are they variables you have used somewhere else in your code? And whatās the purpose of these DIM statements? They define a variable āsavesā but according to the language description a comma and a 2nd variable name are not allowed, so I really donāt know what the ā ,iā and ā ,uā parts of the statements are supposed to do.
Kind regards
Thomas
Hi Thomas, I more than likely have used both u and i somewhere previously in the code (App is at 75 forms now). I was under the impression that u and i were being used in the for loops to count out the values stored in the LocalStorage array. Count is the numerical order of the values stored in RiseFall. and Counts is the numerical order for the values stored in RiseFallX.
Because Iām saving to another āDimāedā variable just for the iteration (Numc, RFb, RFc) and possible calculations within the loop āSavesā or u or i serve no real purpose to me apart from making the loop work and getting the values stored back into LocalStorage.
Hi William,
I ran a little test here.
I was wrong about the syntax of the DIM statement - you can actually define multiple variables in 1 Dim statement like you do, so
Dim saves, u
defines 2 variables, āsavesā and āuā as you also found out.
If you define the same variable name again in another Dim statement (like you do with āsavesā), AppStudio doesnāt complain, but it only defines the same variable again. So thereās still only one āsavesā variable. I had expected a message saying āduplicate variable declarationā or similar.
Kind regards
Thomas
1 Like
Oh and 1 more thing: having a āDimā statement inside a loop is a bad idea - like you have in your 2nd loop.
1 Like
Ok Thomas, Thanks for your help and expertise, ānotedā with regards to the Dim statement within a loop
Will.