Designer Scripts

roarnold

Active Member
Licensed User
Longtime User
Morning

Can I not use the following:

- AutoScaleAll - Autoscales all layout views.
Example:
Code:
AutoScaleAll


I receive an error that it is looking for an "=" in the script.

Thanks,
R
 

lagore

Active Member
Licensed User
Longtime User
You do not have to set the rate before using autoscaleall as it will use the default

Sent from my HTC One X using Tapatalk 2
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Script code:
Code:

'All variants script
AutoScaleRate(0.3)
AutoScaleAll

/Code


Popup Error during compile:

Compiling code. 0.19
Compiling layouts code. Error
'=' expected.
Error File: 1.bal

Go to the designer script page to debug this error.

I am a bit confused on this as I have not used designer scripts in B4A.

Any ideas?

Thanks,
R
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I suspect you don't only have the autoscaleAll command in your script.
If you have something else there, check if it is for example a view, which is not in your chosen layout.
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
Can you either upload your app or create a small test app with the problem and upload it then we should be able to sort it out

Sent from my HTC One X using Tapatalk 2
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Code for Main module and Designer Code as well

Hi all, here is the code for my main module along with layout "1" that is essentially a log module. I am trying to keep my phone from crashing when I change orientations.

Code:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim hc As HttpClient
Dim URL As String
URL = "http://cowboy.ath.cx:851/walt/a2.php" 'a2 is authentication db
Dim HttpClient1 As HttpClient

Dim Pin As Int
Dim Company As Long
Dim result As String

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Button1 As Button
Dim EditText1 As EditText ' phone
Dim EditText2 As EditText ' company name
Dim EditText3 As EditText ' pin code
Dim Label1, Label2, Label3 As Label
Dim Fone As String
Dim txtUID As EditText
Dim txtpin As EditText
Dim txtCO As EditText
Dim chkRememberUID As CheckBox
Dim chkRememberPW As CheckBox
Dim cd As CustomDialog
Dim btn As Button
Dim Color As ColorDialog
Dim Orientation As String
End Sub
Sub btn_Click


cd.Show("", "Login", "", "", Null)

Log(txtUID)
Log(txtpin)
Log(txtCO)
Button1_Click


End Sub

Sub Activity_Create(FirstTime As Boolean)
If Activity.Width > Activity.Height Then
Orientation = "Landscape"
Else
Orientation = "Portait"
End If
If FirstTime Then
hc.Initialize("hc")
Activity.LoadLayout("1")
End If


Label2.Initialize("")
Label2.Text = "SINCADS Mobility App"
Label2.TextColor = Colors.DarkGray
Label2.TextSize = 18
Activity.AddView(Label2, 60dip, 0dip, 300dip, 40dip)

Label3.Initialize("")
Label3.Text = "@Cyber Storm technologies Group 2011 - 2012"
Label3.TextColor = Colors.DarkGray
Label3.TextSize = 13
Activity.AddView(Label3, 20dip, 380dip, 380dip, 40dip) ' this is label3 "SINCADS" footer

' Activity.Color
btn.Initialize("btn")
btn.Text = "Click for System Login"
Activity.AddView(btn,80dip,100dip,150dip,100dip)


Dim pnl1 As Panel
pnl1.Initialize ("")
cd.AddView(pnl1, 0, 30dip, 450dip, 200dip)


Dim lblUID As Label
lblUID.Initialize("")
lblUID.Text = "User Name: "
lblUID.TextSize = 16
pnl1.AddView(lblUID, 20dip, 5dip, 100dip, 40dip)


txtUID.Initialize("")
txtUID.Hint = "Enter User Name"
pnl1.AddView(txtUID, 110dip, 0dip, 165dip, 40dip)

Dim lblpin As Label
lblpin.Initialize("")
lblpin.Text = "Password: "
lblpin.TextSize = 16
pnl1.AddView(lblpin, 20dip, 50dip, 100dip, 40dip)


txtpin.Initialize("")
txtpin.Hint = "Enter Password"
txtpin.PasswordMode = True
pnl1.AddView(txtpin, 110dip, 45dip, 165dip, 40dip)

Dim lblCO As Label
lblCO.Initialize("")
lblCO.Text = "Company #: "
lblCO.TextSize = 16
pnl1.AddView(lblCO, 20dip, 85dip, 165dip, 40dip)


txtCO.Initialize("")
txtCO.Hint = "Enter Company #"
txtCO.PasswordMode = True
pnl1.AddView(txtCO, 110dip, 85dip, 165dip, 40dip)


chkRememberUID.Initialize("")
chkRememberUID.Text = "Remember UID"
pnl1.AddView(chkRememberUID, 85dip, 120dip, 210dip, 40dip)


chkRememberPW.Initialize("")
chkRememberPW.Text = "Remember PW"
pnl1.AddView(chkRememberPW, 85dip, 155dip, 210dip, 40dip)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Button1_Click

Dim btn As Button
btn = Sender 'Fetch the actual button that raised this event.
CurrentTask = btn.Tag 'Take the object from its Tag property.

Dim request As HttpRequest

request.InitializeGet(URL & "?Fone=" & txtUID.Text & "&pincode=" & txtpin.Text & "&company=" & txtCO.Text & "&edit=Register")

Log(request)
If hc.Execute(request, 1) = False Then Return 'Will be false if their is already a running task (with the same id).
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)

ProgressDialogHide

result = Response.GetString ("UTF8") ' Convert the response to a string
Log(result)


StartActivity(SelectionList)


End Sub
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Code for Main module and Designer Code as well

Hi all, here is the code for my main module along with layout "1" that is essentially a log module. I am trying to keep my phone from crashing when I change orientations.

Code:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim hc As HttpClient
Dim URL As String
URL = "http://cowboy.ath.cx:851/walt/a2.php" 'a2 is authentication db
Dim HttpClient1 As HttpClient

Dim Pin As Int
Dim Company As Long
Dim result As String

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Button1 As Button
Dim EditText1 As EditText ' phone
Dim EditText2 As EditText ' company name
Dim EditText3 As EditText ' pin code
Dim Label1, Label2, Label3 As Label
Dim Fone As String
Dim txtUID As EditText
Dim txtpin As EditText
Dim txtCO As EditText
Dim chkRememberUID As CheckBox
Dim chkRememberPW As CheckBox
Dim cd As CustomDialog
Dim btn As Button
Dim Color As ColorDialog
Dim Orientation As String
End Sub
Sub btn_Click


cd.Show("", "Login", "", "", Null)

Log(txtUID)
Log(txtpin)
Log(txtCO)
Button1_Click


End Sub

Sub Activity_Create(FirstTime As Boolean)
If Activity.Width > Activity.Height Then
Orientation = "Landscape"
Else
Orientation = "Portait"
End If
If FirstTime Then
hc.Initialize("hc")
Activity.LoadLayout("1")
End If


Label2.Initialize("")
Label2.Text = "SINCADS Mobility App"
Label2.TextColor = Colors.DarkGray
Label2.TextSize = 18
Activity.AddView(Label2, 60dip, 0dip, 300dip, 40dip)

Label3.Initialize("")
Label3.Text = "@Cyber Storm technologies Group 2011 - 2012"
Label3.TextColor = Colors.DarkGray
Label3.TextSize = 13
Activity.AddView(Label3, 20dip, 380dip, 380dip, 40dip)

' Activity.Color
btn.Initialize("btn")
btn.Text = "Click for System Login"
Activity.AddView(btn,80dip,100dip,150dip,100dip)


Dim pnl1 As Panel
pnl1.Initialize ("")
cd.AddView(pnl1, 0, 30dip, 450dip, 200dip)


Dim lblUID As Label
lblUID.Initialize("")
lblUID.Text = "User Name: "
lblUID.TextSize = 16
pnl1.AddView(lblUID, 20dip, 5dip, 100dip, 40dip)


txtUID.Initialize("")
txtUID.Hint = "Enter User Name"
pnl1.AddView(txtUID, 110dip, 0dip, 165dip, 40dip)

Dim lblpin As Label
lblpin.Initialize("")
lblpin.Text = "Password: "
lblpin.TextSize = 16
pnl1.AddView(lblpin, 20dip, 50dip, 100dip, 40dip)


txtpin.Initialize("")
txtpin.Hint = "Enter Password"
txtpin.PasswordMode = True
pnl1.AddView(txtpin, 110dip, 45dip, 165dip, 40dip)

Dim lblCO As Label
lblCO.Initialize("")
lblCO.Text = "Company #: "
lblCO.TextSize = 16
pnl1.AddView(lblCO, 20dip, 85dip, 165dip, 40dip)


txtCO.Initialize("")
txtCO.Hint = "Enter Company #"
txtCO.PasswordMode = True
pnl1.AddView(txtCO, 110dip, 85dip, 165dip, 40dip)


chkRememberUID.Initialize("")
chkRememberUID.Text = "Remember UID"
pnl1.AddView(chkRememberUID, 85dip, 120dip, 210dip, 40dip)


chkRememberPW.Initialize("")
chkRememberPW.Text = "Remember PW"
pnl1.AddView(chkRememberPW, 85dip, 155dip, 210dip, 40dip)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Button1_Click

Dim btn As Button
btn = Sender 'Fetch the actual button that raised this event.
CurrentTask = btn.Tag 'Take the object from its Tag property.

Dim request As HttpRequest

request.InitializeGet(URL & "?Fone=" & txtUID.Text & "&pincode=" & txtpin.Text & "&company=" & txtCO.Text & "&edit=Register")

Log(request)
If hc.Execute(request, 1) = False Then Return 'Will be false if their is already a running task (with the same id).
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)

ProgressDialogHide

result = Response.GetString ("UTF8") ' Convert the response to a string
Log(result)


StartActivity(SelectionList)


End Sub
/Code

Designer script:

'All variants script
AutoScaleRate(0.3)
AutoScaleAll

/code
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Place the loadlayout outside of the {if firstTime}. Perhaps this is the issue.
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
MC 73.

I think it is outside of the If FirstTime statement so do I need to make it a separate sub?

I think the example showed to place it as the first thing it runs when it comes into the Activity_Create.

So, bit confused........

Appreciate the help, MC.

Ron
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
No, it is inside the if.
Loading the layout in firstTime, can lead to initialization errors. I suggest you take it out of the if, perhaps it will solve other problems you noticed upon orientation changes.
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
MC,

Sorry, maybe I am a bit dense. Take the Activity.Layout"1" out of the IF statement and load it before or after it has run the IF statement? I only ask in that the guides show it differently.

If you get a chance, could you take that portion of my "Main" code I posted here and demonstrate what you mean? I would be grateful if you could take a few mins to do this.

I appreciate your help in advance,
Ron
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem when you load a layout only If FirstTime = True Then the layout will be loaded only once when you run the program the first time after is has been killed.
If then you change the orientation of the device the layout will NOT be loaded because the Activity is paused and reloaded again the program runs Activity_Create again and in that case FirstTime = False.
Your Activity_Create routine should look like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If Activity.Width > Activity.Height Then
        Orientation = "Landscape"
    Else
        Orientation = "Portait"
    End If
    If FirstTime Then
        hc.Initialize("hc")
    End If
    Activity.LoadLayout("1")
What do you have in the"1" layout file ?
You load a layout file and also define views in the code and add them to the activity why ?

In what guide did you see it differently ? It doesn't matter if it's before or after If FirstTime = True Then / End If but it must not be insides.

You should read this thread Android Process and activities life cycle.
Or chapter 9 Process and Activity life cycle in the Beginner's Guide.

It would be much easier to help if you posted your project as a zip file (IDE menu Files / Export As Zip) so we could test it in the same conditions as you do.

When you post code please use the code tags with the # button.

Best regards.
 
Last edited:
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Evening,

The question I have is the error in the designer. Any ideas about it and what I put there is okay or not?

Thanks,
R
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Evening,

The question I have is the error in the designer. Any ideas about it and what I put there is okay or not?

Thanks,
R

Since autoScaleAll shouldn't produce an error, I have to agree with Klaus. You could try posting your bal file and perhaps your source, in order to see what's going on. I usually encounter such errors when I write something wrong in the designer script, while you say that you only use the autoscaleall statement.
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Yes I did, and showed that at the top. I will try again and if all else fails I will post it all for you to review further.

Thanks,
R
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Evening,

1.bas has only a label and a button that are behind the scenes used for specific reasons.

I added the recommended IF statement per Klaus and company, but receive the following error for designer script in 1.bas

Compiling code. 0.12
Compiling layouts code. Error
'=' expected.
Error File: 1.bal

Go to the designer script page to debug this error.


The only thing I have in the designer script is "autoScallAll" under the all variants scripts at top.

Thanks,
R
 
Upvote 0

roarnold

Active Member
Licensed User
Longtime User
Evening,

Enclosed is the zip file. I only placed the mentioned code from you all in the main module and in the .bas for main which is "1".

Appreciate the help,
Ron
 

Attachments

  • NFC7zipedcode.zip
    19.5 KB · Views: 276
Upvote 0
Top