Android Question Variable Read Only

Terradrones

Active Member
Hi All

I need help\push again please.

I am trying to Plot the Horizontal Alignment on the screen and declare my variables as follows:

B4X:
[/
    Dim ScreenX0, ScreenY0, ScreenW, ScreenH As Float
    Dim SheetX0, SheetY0, SheetW, SheetH As Double
    Dim ScaleX, ScaleY As Double

    Dim PntMinX, PntMaxX, PntMinY, PntMaxY, PntMaxMinX, PntMaxMinY, PntMeanX, PntMeanY As Float
    Dim Scaletype As Int    : Scaletype = 1            ' 0 = top > down        1 = bottom > up
   
    Dim X, Y As Double
    Type Point (X As Double , Y As Double)
    Dim PntNbMax As Int        : PntNbMax = 500
    Dim Pnt(PntNbMax) As Point
    'Dim P As Point
    Dim Panel2 As Panel
    Dim cnvDrawing As Canvas
    Dim Label61, Label60 As Label
]

When I want to add data to "Pnt", it tells me that it is Read Only:

[CODE=b4x][/
Sub InitScale
    Dim i As Int
   
    ScreenX0 = 5dip
    ScreenY0 = 5dip
    ScreenW = Panel2.Width - 2 * ScreenX0
    ScreenH = Panel2.Height - 2 * ScreenY0


    For i = 1 To CGlobals.NumbAlign
        [B]Pnt(i-1).X =  CGlobals.WK2(1, i + 3500)[/B]
        [B]Pnt(i-1).Y = CGlobals.WK2(2, i + 3500)[/B]
    Next

    PntMinX = CGlobals.WK2(1, i + 3500)
    PntMaxX = CGlobals.WK2(1, i + 3500)
    PntMinY = CGlobals.WK2(2, i + 3500)
    PntMaxY = CGlobals.WK2(2, i + 3500)
    For i = 1 To CGlobals.NumbAlign
        PntMinX = Min(PntMinX, CGlobals.WK2(1, i + 3500))
        PntMaxX = Max(PntMaxX, CGlobals.WK2(1, i + 3500))
        PntMinY = Min(PntMinY, CGlobals.WK2(2, i + 3500))
        PntMaxY = Max(PntMaxY, CGlobals.WK2(2, i + 3500))
    Next
    PntMaxMinX = PntMaxX - PntMinX
    PntMaxMinY = PntMaxY - PntMinY
    PntMeanX = (PntMaxX + PntMinX) / 2
    PntMeanY = (PntMaxY + PntMinY) / 2

    ScaleX = ScreenW / PntMaxMinX
    ScaleY = ScreenH / PntMaxMinY
   
    If ScaleX > ScaleY Then
        ScaleX = ScaleY
        SheetW = PntMaxMinY * ScreenW / ScreenH
        ScaleX = ScaleY
        SheetX0 = PntMeanX - SheetW / 2
        If Scaletype = 0 Then
            SheetY0 = PntMinY
        Else
            SheetY0 = PntMaxY
            ScaleY = -ScaleY
        End If
    Else
        ScaleX = ScaleY
        SheetX0 = PntMinX
        SheetH = PntMaxMinX * ScreenH / ScreenW
        ScaleY = ScaleX
        If Scaletype = 0 Then
            SheetY0 = PntMeanY - SheetH / 2
        Else
            ScaleY = -ScaleY
            SheetY0 = PntMeanY + SheetH / 2
        End If
    End If
End Sub
]

Its there were the Code is Bold.

Thanks
Michael
 

Terradrones

Active Member
Hi William, sorry about the Code Tags....I have been doing it in the dark...we are sitting 3 times a day up to 4 hours without electricity!

In CGlobals I keep all my Design Parameters (Horizontal Alignment, Vertical Alignment, Tin Model, etc.), as I use them in calculations throughout the Program.

CGlobals.WK2(1, i + 3500) = Easting of Point of Intersection
CGlobals.WK2(1, i + 3500) = Northing of Point of Intersection

When I use the following Code, it gives me an error message of "Read Only":

Pnt(i-1).X = CGlobals.WK2(1, i + 3500)

I am trying to read all the Eastings and Northings of my Horizontal Alignment into an Array (Pnt()), so that I can plot it.

Thanks
Michael
 
Upvote 0

emexes

Expert
Licensed User
When I want to add data to "Pnt", it tells me that it is Read Only:

This is B4A, right (not B4J) ?

When I try this in B4A 11.80 :

B4X:
'    For i = 1 To CGlobals.NumbAlign
'        Pnt(i-1).X =  CGlobals.WK2(1, i + 3500)
'        Pnt(i-1).Y = CGlobals.WK2(2, i + 3500)
'    Next

Log("Pnt.Length = " & Pnt.Length)
Log("Pnt(0).X = " & Pnt(0).X)

For i = 1 To PntNbMax
    Pnt(i-1).X = Rnd(-100, 101)
    Pnt(i-1).Y = Rnd(-100, 101)
Next

Log("Pnt(0).X = " & Pnt(0).X)

then there is no read-only error, just the expected:

Log output:
Logger connected to:  HMD Global Nokia C01 Plus
--------- beginning of main
--------- beginning of system
** Activity (main) Create, isFirst = true **
Pnt.Length = 500
Pnt(0).X = 0
Pnt(0).X = -89
** Activity (main) Resume **
 
Upvote 0

emexes

Expert
Licensed User
When I use the following Code, it gives me an error message of "Read Only":

Pnt(i-1).X = CGlobals.WK2(1, i + 3500)

If the error is still happening - in B4A, correct? - then my next tack would be to try narrow it down to which part of the assignment is triggering the error, eg:

B4X:
Dim TmpDbl As Double = CGlobals.WK2(1, i + 3500)    'or whatever type WK2 is
Pnt(i - 1) = TmpDbl
 
Upvote 0

Terradrones

Active Member
Hi All

I changed my approach and changed Pnt(i).X and Pnt(i).Y to X(i) and Y(i). I will look at the original problem again later when I have time. Now I am pushed for time to finish this Land Surveying Program.
 
Upvote 0
Top