why doesn't my scripts gets refreshed??

Hi,

i have a main page on my desktop which sets the path of en axternal reference in the comments of my object "EFB clock"

-> If i check that in properties it really get changed...
-> but the other objects using this pat as a ref doesn't handle this unless i manually disable/enable the script...

What can i do about this? can I restart an objects script from another object's script?

my code of the button which doesn't update

Code: vbscript
  1. ' VBScript "Include" routine
  2. Sub Include(sInstFile)
  3. On Error Resume Next
  4. Dim oFSO, f, s
  5. Set oFSO = CreateObject("Scripting.FileSystemObject")
  6. If oFSO.FileExists(sInstFile) Then
  7. Set f = oFSO.OpenTextFile(sInstFile)
  8. s = f.ReadAll
  9. f.Close
  10. ExecuteGlobal s
  11. End If
  12. Set oFSO = Nothing
  13. Set f = Nothing
  14. End Sub
  15. Sub writetosubmenu()
  16. desktopx.object("Submenu Title Text").text = desktopx.object("Text Main Button2").text
  17. For i=1 To 32
  18. If i<=nrsubbutton2 Then
  19. desktopx.object("SubButton"&i).visible = True
  20. desktopx.object("Text SubButton"&i).text = subbutton2(i-1,0)
  21. desktopx.object("SubButton"&i).command = subbutton2(i-1,1)
  22. Else
  23. desktopx.object("SubButton"&i).visible = False
  24. End If
  25. Next
  26. End Sub
  27. Sub Object_OnLButtonDown(x, y)
  28. desktopx.object("Submenu").visible = False
  29. Include(desktopx.object("EFB Clock").comments)
  30. writetosubmenu()
  31. End Sub


Note: I allready checked if it got the (efb clock) comment correctly by writing that to ("Submenu Title Text").text which works and makes it completly understandable for me...
11,368 views 17 replies
Reply #1 Top
So, you are calling the include file on Left Button down. Personally, I call it from
Object_OnScriptEnter but, not sure how you are using it.

To reference a script from another object you would use something like this but, you may have to put the include function in the calling object?

Code: vbscript
  1. Call Include(DesktopX.ScriptObject("EFB Clock").Comments)
Reply #2 Top
I've choosen to include on left button down to get a refresh of the script each time I click the related object

two other objects are changing the path used in the include function -> so the same looking objects can act as different menus, related to what is written in the external config file... (which just contains a list of arrays and variables)
Reply #3 Top
Ahh, that helps. Also, my code is wrong up there. You need to reference the script object before the function/sub.

Code: vbscript
  1. Dim myScript: Set myScript = DesktopX.Object("CallingObjectName").Comments
  2. Call DesktopX.ScriptObject("EFB Clock").Include(myScript)
Reply #4 Top
I get :

Code: vbscript
  1. Sub Object_OnLButtonDown(x, y)
  2. Dim myScript: Set myScript = DesktopX.Object("EFB Clock").Comments
  3. Call DesktopX.ScriptObject("Choice2").Include(myScript)
  4. 'desktopx.object("Submenu").visible = False
  5. writetosubmenu()
  6. End Sub


gives:

Object required: '[string: "C:\Documents and Set"]'
Line: 33
Code:
(not available)

I think it is running against my personal knowledge of vb which i am doing
Reply #5 Top
Where do i put the script?
in the code which wrote above?

I just used EFB clock to pass the path of my config files to the other subjects, the clock doesn,t has any script on it...

Choice 1 & 2 overwrites the clocks comment and they change the text & params of the objects used as menubuttons

some of these buttons contains the script which i originally posted above...

if i change


Code: vbscript
  1. desktopx.object("Submenu Title Text").text = desktopx.object("EFB Clock").comments

into
Code: vbscript
  1. desktopx.object("Submenu Title Text").text = desktopx.object("EFB Clock").comments


I can see that the path of the file yo include is really updated...
So the sub writetosubmenu() is executed again on the mouseclick...
but for some reason it doesn't use the new path to write to the submenu buttons...
altough it overwrites the buttons with the data of the first used config file
Reply #6 Top
i mean
change
Code: vbscript
  1. desktopx.object("Submenu Title Text").text = desktopx.object("EFB Clock").comments

into
Code: vbscript
  1. desktopx.object("Submenu Title Text").text = desktopx.object("EFB Clock").comments
Reply #7 Top
It sounds like you're getting the path issue. This crops up in regular scripts. You need to use the ShortPath Property to correct it.

Putting this into your include statement might fix it.
Code: vbscript
  1. Set oFSO = CreateObject("Scripting.FileSystemObject")
  2. oFPATH= oFSO.GetFile(sInstFile)
  3. sInstFile=oFPATH.ShortPath
  4. If oFSO.FileExists(sInstFile) Then
Reply #9 Top
To make it easy (i hope)

Can you stop/start the script of an other object?
Reply #10 Top
No. They way you're trying to do it should work.
This might have no effect on it but, it should be an Include Function not a sub procedure.
Reply #11 Top
I made a function iso a sub... no change... it just looks like the include function doesn't refresh...

this is what i have now in the script...
I don't use the call because it gave me an error... I am sure I implemented it wrongly!

Code: vbscript
  1. ' VBScript "Include" routine
  2. Function Include(sInstFile)
  3. On Error Resume Next
  4. Dim oFSO, f, s
  5. Set oFSO = CreateObject("Scripting.FileSystemObject")
  6. oFPATH= oFSO.GetFile(sInstFile)
  7. sInstFile=oFPATH.ShortPath
  8. If oFSO.FileExists(sInstFile) Then
  9. Set f = oFSO.OpenTextFile(sInstFile)
  10. s = f.ReadAll
  11. f.Close
  12. ExecuteGlobal s
  13. End If
  14. Set oFSO = Nothing
  15. Set f = Nothing
  16. End Function
  17. Sub writetosubmenu()
  18. desktopx.object("Submenu Title Text").text = desktopx.object("Text Main Button6").text
  19. For i=1 To 32
  20. If i<=nrsubbutton6 Then
  21. desktopx.object("SubButton"&i).visible = True
  22. desktopx.object("Text SubButton"&i).text = subbutton6(i-1,0)
  23. desktopx.object("SubButton"&i).command = subbutton6(i-1,1)
  24. Else
  25. desktopx.object("SubButton"&i).visible = False
  26. End If
  27. Next
  28. End Sub
  29. Sub Object_OnLButtonDown(x, y)
  30. desktopx.object("Submenu").visible = False
  31. Include(desktopx.object("EFB Clock").comments)
  32. writetosubmenu()
  33. End Sub


If there was a nice include function for jscript I would throw vbscript away!
Reply #12 Top
Look under the System Namespace section. If you're just reading the file in I'm sure you could use System.SimpleRead(path, param) to do this from jscript.
Reply #13 Top
No, because the file contains parameters where i need to work with...
But it was a good idea-> i can use this somewhere else in my application...
I am going to try the switching of config file with a if/case statement...
Reply #14 Top
I wrote var s to the text of an new object for testing now...
the include function seems to do what it has to...

Might it be the ExecuteGlobal statement? doesn't it allow to overwrite my variables? when recalling the function?

If in my ext file_a x=2 and in file_b x=3 won't it overwrite x??
For me it should like if you say
Dim x
x=2
x=3
the result will be that x=3... or am i messing up my languages??
Reply #15 Top
Was just thinking about that today.
According the the WSH SDK it should overwrite the variables.
Reply #16 Top
The same script translated to jscript does work... Your tip helped me anyway... I am not a pro-programmer... I startted analyzing my include function founded what globalexecute did and that eval could do that in Jscript...

I don't understand why the documentation is build in vbscript, jscript is so much better documented (ex w3schools.com)& looks much more powerfull which makes it a clear language to me!! Now my script works and I am saving lots of lines in my script now! Thanks a lot!!

For info:

Code: javascript
  1. function Include(filelocation){
  2. loca=System.SimpleRead(filelocation, 1);
  3. this.eval(loca);
  4. }
  5. function writetosubmenu(buttonnr){
  6. DesktopX.Object("Submenu Title Text").Text = DesktopX.Object("Text Main Button"+buttonnr).Text;
  7. for(i=1;i<=32;i++){
  8. if(i<=this.eval("subbutton"+buttonnr).length){
  9. DesktopX.Object("SubButton"+i).Visible = 1
  10. DesktopX.Object("Text SubButton"+i).Text = (this.eval("subbutton"+buttonnr)[i-1][0]).toUpperCase()
  11. DesktopX.Object("SubButton"+i).Command = this.eval("subbutton"+buttonnr)[i-1][1]}
  12. else{
  13. DesktopX.object("SubButton"+i).Visible = 0
  14. }}}
  15. function Object_OnLButtonDown(x, y){
  16. Include("C:/SFAC_EFB/config/fileloc.js");
  17. Include(file[DesktopX.Object("EFB Clock").Comments][0]);
  18. Include("C:/SFAC_EFB/config/bin/writefunctions.js");
  19. DesktopX.Object("Submenu").Visible = 0;
  20. writetosubmenu(2);
  21. }
Reply #17 Top
Hey, that's good. I've run into this issue today while working on a Language Files Function. I'm thinking in VBS it may be an UTF-8 issue.

VBScript is most likely used going back to the original development year of DesktopX. It is also easier than javascript and many people are familiar with VBA. Not a programmer either and just starting to learn javascript because of additional power that it can provide in DesktopX.