Crashing script from t3h hell

I am so puzzled :S

Hello!

I've spent last couple of days programming a new project and it was going so well I was really enjoying the work.

And then, while testing one of the features it crashed. Nothing special, this happens while the script is in developement, so I went and checked it for mistakes. But to my amazement, after quite some time I couldn't locate the problem.

This is the bit where DesktopX Builder crashes in flames:

Code: vbscript
  1. Dim HKEY_entrynum
  2. Dim HKEY_written_value
  3. Dim HKEY_type
  4. Dim HKEY_visible 'is the entry visible or not (v-visible h-hidden)
  5. Dim bar_counter
  6. Dim file 'only file's name
  7. Sub Reading_HKEY(x)
  8. m = msgbox("Reading_HKEY"&x,0,"Executro]list ")
  9. Set Sh = CreateObject("WScript.Shell")
  10. ' Defining:
  11. ' -HKEY_written_value
  12. HKEY_written_value = Sh.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Forge7\FIncogniter\index")
  13. Set Sh = Nothing
  14. m = msgbox("Read HKEY_written value= "&HKEY_written_value,0,"Executro]list ")
  15. If HKEY_written_value = "" Or HKEY_written_value ="0|" Then
  16. m = msgbox("No data available for extraction.",0,"Executro]list ")
  17. Else
  18. If x=1 Then
  19. m=msgbox("create_list(1)",0,"Executro]list ")
  20. Call create_list(1)
  21. ElseIf x=2 Then
  22. m=msgbox("delete_list(2)",0,"Executro]list ")
  23. Call delete_list(2)
  24. ElseIf x=3 Then
  25. m=msgbox("delete_list(3)",0,"Executro]list ")
  26. Call delete_list(3)
  27. End If
  28. End If
  29. End Sub
  30. Sub create_list(x)
  31. bar_counter = 0 'resets bar counter (counts entrys created)
  32. 'DesktopX.Object("EntryBackground").height = 0 'resets height of the list parent object
  33. 'DesktopX.Object("EntryBackground").visible = True
  34. x=split(HKEY_written_value,"|")'segments HKEY to number of entrys and entrys data
  35. HKEY_entrynum = x(0) 'sets number of entrys
  36. 'DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys = HKEY_entrynum
  37. DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys = 0
  38. m = msgbox("Number of actual entrys = "&DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys,0,"Executro]list ")
  39. m = msgbox("Number of entrys in HKEY = "&HKEY_entrynum,0,"Executro]list ")
  40. 'If DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys = 0 Then
  41. Do
  42. m = msgbox("Just entered the loop",0,"Executro]list ")
  43. bar_counter = bar_counter+1
  44. 'splitting entry string to gather data
  45. y=split(x(HKEY_entrynum),"*")
  46. 'Getting wether entry is visible or not (v/h)
  47. HKEY_visible=y(0)
  48. 'Getting the type of entry
  49. HKEY_type=y(1)
  50. 'Getting full entry name
  51. HKEY_file=y(2)
  52. 'Getting only entry's name
  53. z = InStrRev(HKEY_file,"\","-1")'now x is the number where string needs to be cut
  54. q = Len(HKEY_file)
  55. file = Right(HKEY_file,(q-z))'This is only entry's name
  56. HKEY_entrynum = HKEY_entrynum - 1 'ensures that during next pass new entry will be managed
  57. 'now cloning objects:
  58. 'EntryParent*x
  59. DesktopX.Object("EntryParent*0").clone ("EntryParent*"&bar_counter), DesktopX.Object("EntryParent*0").left, (-DesktopX.Object("EntryParent*0").height+(bar_counter*DesktopX.Object("EntryParent*0").height))
  60. 'm = msgbox("HKEY_visible: "&DesktopX.ScriptObject("EntryParent*"&bar_counter).HKEY_visible,0,"Executor]list ")
  61. DesktopX.ScriptObject("EntryParent*"&bar_counter).HKEY_visible = HKEY_visible
  62. 'm = msgbox("HKEY_visible: "&DesktopX.ScriptObject("EntryParent*"&bar_counter).HKEY_visible,0,"Executor]list ")
  63. DesktopX.ScriptObject("EntryParent*"&bar_counter).HKEY_type = HKEY_type
  64. DesktopX.ScriptObject("EntryParent*"&bar_counter).HKEY_file = HKEY_file
  65. DesktopX.ScriptObject("EntryParent*"&bar_counter).file = file
  66. 'EntryChild*x
  67. DesktopX.Object("EntryChild*0").clone ("EntryChild*"&bar_counter), DesktopX.Object("EntryChild*0").left, DesktopX.Object("EntryChild*0").top
  68. DesktopX.Object("EntryChild*"&bar_counter).parent = DesktopX.Object("EntryParent*"&bar_counter)
  69. 'EntryToolboxMask*x
  70. DesktopX.Object("EntryToolboxMask*0").clone ("EntryToolboxMask*"&bar_counter), DesktopX.Object("EntryToolboxMask*0").left, DesktopX.Object("EntryToolboxMask*0").top
  71. DesktopX.Object("EntryToolboxMask*"&bar_counter).parent = DesktopX.Object("EntryParent*"&bar_counter)
  72. 'EntryToolbox*x
  73. DesktopX.Object("EntryToolbox*0").clone ("EntryToolbox*"&bar_counter), DesktopX.Object("EntryToolbox*0").left, DesktopX.Object("EntryToolbox*0").top
  74. DesktopX.Object("EntryToolbox*"&bar_counter).parent = DesktopX.Object("EntryToolboxMask*"&bar_counter)
  75. 'EntryText*x
  76. DesktopX.Object("EntryText*0").clone ("EntryText*"&bar_counter), DesktopX.Object("EntryText*0").left, DesktopX.Object("EntryText*0").top
  77. DesktopX.Object("EntryText*"&bar_counter).parent = DesktopX.Object("EntryChild*"&bar_counter)
  78. DesktopX.Object("EntryText*"&bar_counter).text = file
  79. 'EntryVisibility*x
  80. DesktopX.Object("EntryVisibility*0").clone ("EntryVisibility*"&bar_counter), DesktopX.Object("EntryVisibility*0").left, DesktopX.Object("EntryVisibility*0").top
  81. DesktopX.Object("EntryVisibility*"&bar_counter).parent = DesktopX.Object("EntryToolbox*"&bar_counter)
  82. If HKEY_visible = "v" Then
  83. DesktopX.ScriptObject("EntryVisibility*"&bar_counter).switcher = "v"
  84. DesktopX.ScriptObject("EntryVisibility*"&bar_counter).active = True
  85. DesktopX.Object("EntryVisibility*"&bar_counter).ExecuteCommand
  86. End If
  87. 'EntryType*x
  88. DesktopX.Object("EntryType*0").clone ("EntryType*"&bar_counter), DesktopX.Object("EntryType*0").left, DesktopX.Object("EntryType*0").top
  89. DesktopX.Object("EntryType*"&bar_counter).parent = DesktopX.Object("EntryChild*"&bar_counter)
  90. DesktopX.Object("EntryType*"&bar_counter).state = HKEY_type
  91. 'EntryRun*x
  92. DesktopX.Object("EntryRun*0").clone ("EntryRun*"&bar_counter), DesktopX.Object("EntryRun*0").left, DesktopX.Object("EntryRun*0").top
  93. DesktopX.Object("EntryRun*"&bar_counter).parent = DesktopX.Object("EntryToolbox*"&bar_counter)
  94. 'EntryRemove*x
  95. DesktopX.Object("EntryRemove*0").clone ("EntryRemove*"&bar_counter), DesktopX.Object("EntryRemove*0").left, DesktopX.Object("EntryRemove*0").top
  96. DesktopX.Object("EntryRemove*"&bar_counter).parent = DesktopX.Object("EntryToolbox*"&bar_counter)
  97. 'EntryFolder*x
  98. DesktopX.Object("EntryFolder*0").clone ("EntryFolder*"&bar_counter), DesktopX.Object("EntryFolder*0").left, DesktopX.Object("EntryFolder*0").top
  99. DesktopX.Object("EntryFolder*"&bar_counter).parent = DesktopX.Object("EntryToolbox*"&bar_counter)
  100. DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys = DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys+1
  101. Loop until HKEY_entrynum=0
  102. m = msgbox("Done compiling the list",0,"Executor]list ")
  103. x="1"
  104. y="1"
  105. z="1"
  106. m = msgbox("x ="&x&vbnewline&"y ="&y&vbnewline&"z ="&z,0,"Executor]list ")
  107. End Sub
  108. Sub delete_list(x)
  109. If DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys = 0 Then
  110. m = msgbox("(=0)number_of_actual_entrys = "&number_of_actual_entrys,0,"Executro]list ")
  111. Else
  112. m = msgbox("(<>0)number_of_actual_entrys = "&number_of_actual_entrys,0,"Executro]list ")
  113. 'y=split(HKEY_written_value,"|")'segments HKEY to number of entrys and entrys data
  114. 'HKEY_entrynum = y(0) 'sets number of entrys
  115. 'This is not hkey value but rather the real value!
  116. HKEY_entrynum = DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys
  117. If x = 3 Then
  118. 'HKEY_entrynum = HKEY_entrynum-1 ' I just removed this one
  119. End If
  120. m = msgbox("HKEY_entrynum = "&HKEY_entrynum,0,"Executro]list ")
  121. Do
  122. DesktopX.Object("EntryFolder*"&HKEY_entrynum).delete
  123. DesktopX.Object("EntryRemove*"&HKEY_entrynum).delete
  124. DesktopX.Object("EntryVisibility*"&HKEY_entrynum).delete
  125. DesktopX.Object("EntryRun*"&HKEY_entrynum).delete
  126. DesktopX.Object("EntryText*"&HKEY_entrynum).delete
  127. DesktopX.Object("EntryType*"&HKEY_entrynum).delete
  128. DesktopX.Object("EntryToolbox*"&HKEY_entrynum).delete
  129. DesktopX.Object("EntryToolboxMask*"&HKEY_entrynum).delete
  130. DesktopX.Object("EntryChild*"&HKEY_entrynum).delete
  131. DesktopX.Object("EntryParent*"&HKEY_entrynum).delete
  132. HKEY_entrynum = HKEY_entrynum-1
  133. DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys = DesktopX.ScriptObject("EntryBackground").number_of_actual_entrys-1
  134. Loop until HKEY_entrynum = 0
  135. If x = 3 Then
  136. m = msgbox("(1)Just deleted the list, now calling Reading_HKEY(1)",0,"Executro]list ")
  137. Call Reading_HKEY(1)
  138. End If
  139. End If
  140. If x = 3 Then
  141. m = msgbox("(pass one)(2)Just deleted the list, now calling Reading_HKEY(1)"&vbnewline&"x = "&x,0,"Executro]list ")
  142. If x = 3 Then
  143. m = msgbox("(pass two)(3)Just deleted the list, now calling Reading_HKEY(1)"&vbnewline&"x = "&x,0,"Executro]list ")
  144. Call Reading_HKEY(1)
  145. End If
  146. End If
  147. End Sub

(Some things are unnecessary, but I added them to see if they would help...)
Now it works like this, this script is assigned to an object and it is called by others depending on what needs to be done.

This is how it is supposed to work:
1. Sub delete_list(x) is called form another object.
2. Sub ends and calls Sub Reading_HKEY(1)
3. Sub ends and calls Sub create_list(x)
4. Sub ends and that concludes the operation.

However, when launched this happens:
1. Sub delete_list(x) is called form another object.
2. Sub ends and calls Sub Reading_HKEY(1)
3. Sub ends and calls Sub create_list(x)
*now watch closely
4. it doesn't call Sub delete_list(x) but it immediately jumps to somewhere around line(140) although it wasn't even supposed to do that. After that, despite the "If" regulation which should stop the flow, it calls Sub Reading_HKEY(1), and then after reaching the end DesktopX Builder crashes.

Now just to make me even more confused, sometimes it even works (if i try Calling different Subs outside the object) but ultimately it just crashes.

I tried all sorts of things, I even tried moving one sub to another object, even removing entire contents of the sub except the crucial part, and it still wouldn't work and crash in the same or similar manner.

Now can anyone find the problem/bug or at least suggest a solution? I can even send you entire program if you think that would help.

If anyone has any, and I mean any idea, please post it here, so I can try to fix this bug.

P.S. thank you for reading this :)
3,084 views 7 replies
Reply #1 Top
Have you cleared the DesktopX cache?
Reply #2 Top
I got nothing. The sub looks fine to me. If you want send it to me gmail account sirsmiley001 and I'll have a look at it. I'm always up for a challenge! ;)

Something I've been doing lately is scripting a text object at each step which has helped in debugging.
Reply #3 Top

Have you cleared the DesktopX cache?
End of quote


Nope, how do I do that?

Just sent you the mail SirSmiley, hope you'll find the solution.
Reply #4 Top

Have you cleared the DesktopX cache?



Nope, how do I do that?
End of quote


Try reading CorkyO's article found here. WWW Link

It's a good idea to clear the cache whenever DesktopX crashes as can occur when writing and debugging scripts. The desktopx cache is where the current theme is kept and when it becomes buggy DX tends to crash. Clearing the cache solves this problem.
Reply #5 Top
Heh I actually once traced this folder (current theme) because I was curious where DX extracted desktops ^^

Anyhow, i cleared the cache, but my dear project blazed into a fireball again...
Reply #6 Top
The error that seems to crash it is line 63 subscript 1 but, this for some reason happens on removing (trying to remove) the last item from the list. The last item on delete re-writes it's properties to the index registry key with 0 then the crash occurs.
I'm thinking it's getting caught in a redundant loop somewhere?

Maybe try deleting or setting the index to null ("") if the number of actual entry's does equal zero and change it to an else if index > 0 for the next step that contains the do loop.

Maybe think about changing those bottom three if statements into a nested if statement or a step statement like While Wend?
Reply #7 Top
Your post seems to make a lot of sense, I'll try your advice tomorrow, today I'm busy with new year party organization :D happy new year to all!