Problem using xojo script

Class1 has a string property , “companyName” that I am trying to update via xojoscript

Dim myclass As new Class1

dim mycompany as String=“Test Co”
Dim scriptsource As String = “myclass.companyName=” + chr(34) + mycompany + chr(34)
Dim script As New XojoScript
app.myscript=script
app.myscript.Context =myclass
app.myscript.Source = scriptsource
app.myscript.Run
Window1.Title=myclass.companyName
Break

myclass.companyName is always blank

any help would be appreciated.

TIA

Tim

Dim scriptsource As String = "myclass.companyName=" + chr(34) + mycompany + chr(34)

should be:

Dim scriptsource As String = "companyName=" + chr(34) + mycompany + chr(34)

Thanks Eli that did the trick

Now I am trying fill a text filed that has an “=” in it

Full_Name=left(Full_Name,3) + “-” + Full_Name //// works fine
custom_AddressScript =Full_Name + “=” +left(Full_Name,3) + “-” + Full_Name

The above works but I get the results of Full_Name + “=” +left(Full_Name,3) + “-” + Full_Name
which makes sense but when I try wrap the cmd with quotes custom_AddressScript =“Full_Name + “=” +left(Full_Name,3) + “-” + Full_Name” which is what I want.

I get an UndefinedOperator error for the =

any help would be appreciated.

TIA

Tim

You need to double the double quotes within the string:

custom_AddressScript = "Full_Name + ""="" +left(Full_Name,3) + ""-"" + Full_Name"

Two remarks about posting questions:

  • New questions not related to the original question should be posted in a new thread.
  • Please format source code by wrapping it with the code tags. It is the button with the empty sheet and the <> brackets. It makes it much easier to grasp the code.

Thanks for the info,
Should I move/ start a new thread?
When using custom_AddressScript = "Full_Name + ""="" +left(Full_Name,3) + ""-"" + Full_Name"
unfortunately custom_AddressScript ends up

Full_Name + "=" +left(Full_Name,3) + "-" + Full_Name

and needs to be Full_Name=left(Full_Name,3) + "-" + Full_Name

Thanks

custom_AddressScript = “Full_Name=left(Full_Name,3) + " + “””-""" + " + Full_Name"

Thanks Peter that seem to do it.

Now I just need to add an EndofLine so I can add more commands to the custom_AddressScript

In such cases, it might be advisable to use a constant and insert placeholders. Then in code, replace the placeholders with the actual data. This method benefits readability and reduces the chance of errors, especially if you happen to have longer code blocks.

Also, when using constants you don’t need to double-quote.