DX Coders, lend me your ears!

Hi, guys. I'm working on a widget that is like a code snipper(?). It allows you to compile all the snippets of code you frequently use into a list. When you l-click on an item in that list say "OnScriptEnter" it'll automatically copy the code:

Sub Object_OnScriptEnter

End Sub

into system clipboard. So you basically click and paste. I'm always opening up multiple text files where I keep my scripts (or even opening up web pages) and highlighting, copying, pasting, and I thought it would be easier and less cluttered to have a convenient place to grab them from. At the moment all the information in the lists are formatted (rss style) and written to a text file in Local Settings > Temp. I will ultimately make it attached to the widget in the object directory. I can also add codes in the textfile itself and when I load up the widget the list will be compiled with the additional changes, creating a text object for each new item.

Here's where I need your input. There will be three lists. A custom list where you put the ones you've constructed, a standard list with all the basic DX sub procedures and funtions, and a resource list where you put links to tutorials on the web or a file on your computer.
I've already compiled as many codes as I can think of for the DX standard list but can you guys tell me if I've left any out? Also, what DX/scripting resources on the web do you think should be included with the widget?

Please look over the lists and let me know what I should add.

Here's the DX standard list:

OnScriptEnter
OnScriptExit
OnStateChange (can easily be modified to OnStateChanged)
OnMouseEnter
OnMouseLeave
OnShow
OnMove
OnSize
OnDropFiles
OnDrag
OnDragFinish
OnSetFocus
OnKillFocus
OnChar
OnKeyDown
OnLButtonDown
OnRButtonDown
OnLButtonUp
OnRButtonUp
OnLButtonUpEx
OnRButtonUpEx
OnScreenChange
OnWorkAreaChange
Pop Up Menu
DesktopX Form
Font Form (One setup specifically for font options and how to apply them to text objects. Will be asking Vad_M for permission.)
Dialog Box- files (for browsing)
Dialog Box- folders (for browsing)
Widget Preferences (including OnPreferencesChange)
For each elem (just as an enumeration example)
Select Case (I use this alot)

I didn't include any for the ActiveX controls as most come with script wizards but let me know if there are any you feel should be included.

Here's the resource list so far:

DX User's Guide online
DX tutorials on WC
Wincustomize DX forums
Stardock DX forums
Wincustomize
W3Schools VBScript Reference
MSDN VBScript Reference

Thanks.
12,550 views 63 replies
Reply #1 Top
Looks pretty thorough. The only thing I can think of is Message Boxes to go with your Input Boxes (Dialog Box).
Reply #2 Top
The basic WMI Calls would come handy, too.
Reply #3 Top
I'm not familiar with WMI yet so you'll have to provide some codes for me c242. Please, (They'll be credited)

Input boxes and message boxes, okay. You think I should put them in the OnLButtonUp procedure so the user can test them easily or in a separate sub like Sub mySub so they can be called from anywhere?


Reply #4 Top
I think they probably belong in a separate sub but, it's probably a matter of preference?

People can use the WMI Code Creator for WMI. Then again I still haven't wrapped my mind around it.
Reply #5 Top
As for WMI: WMI DX Tutorial

This sounds really good.

Maybe the RIGHT-CLICK REPLACEMENT stuff i wrote about a little while back, i use that alot. There seem to be a lot of things i use over and over.

What i end up doing is "importing" the widget that has X in it and copy/paste it out, then delete the widget etc. I do have some text files that have some standard code.

One thing i use a lot is the mouse click stuff. I think i need to get out of the habit of putting my code in every button/object, and keeping it all in 1 main object. VAD_M does that alot, and its really great coding wise. Its just not how i learned so i have to re-learn my brain to use this way. It would make changes a lot easier, as all the code would be in one location. Some of my items have code in 30 places. Thats not the best idea.

I think the community here is really pushing DX coding, its great. The DX SCRIPT MANUAL that Thomassen did is great, and this goes right into that as well.

I really hope that the tutorials are helping to being people into DX(ing).

Reply #6 Top
RomanDA, I know that when I do any websites I have libglobal.inc with all the common functions (encrypted of course) so that we can reference that guy over and over again and just update in one spot.  I am pretty sure that DX can support the same type of thing.
Reply #7 Top
I was leaning towards separate subs too.

Thanks for the link DA and the kick in the head; I forgot about your tut. Do you mind if I put some of your scripts into the widget? (with credit) The first part that pulls the computer name, domain name, and user name I think is enough to get a user started. Then maybe a link in the resources list to a good site about WMI.

Right click replacement, just read your tut. This seems like a handy piece of code to include. I'm going to need to include the codes from steps 1-4 if you don't mind?

I think i need to get out of the habit of putting my code in every button/object, and keeping it all in 1 main object.


I'm doing that alot now, too.

Reply #8 Top
If its in a Tutorial, its for anyone to use.. Im good with that.

As for a common code, i need to see about making an external script file, i have never done that, can it be encoded as well? So no one can just take that file and see what it does? Does that code get complied into the Gadget or does it stay a separate file?

If it only exists on my machine, that could solve a LOT of these issues. Make one common file with all the functions in i normally use, then just append that into my code and I can then call all the functions/subs i want.

Reply #9 Top
Thank you.

I've never used external scripts either. I only know what Brad wrote in his tutorial but that was almost a year ago and I don't know whether or not they worked all the issues of code protection out.
Reply #10 Top
I don't think external files are compiled into the gadget.
I found a free activeX that runs as service allowing you to access your vbscript functions from any app. Haven't downloaded & tested it but, definitely sounds great for enhancing desktopX IMO.

If it only exists on my machine, that could solve a LOT of these issues. Make one common file with all the functions in i normally use, then just append that into my code and I can then call all the functions/subs i want


Just started doing this for vbscript files. It saves a lot of time being able to call functions with a line or two of code instead of having to re-write functions and sub's.

Reply #11 Top
sVis, love the title of this post!   
Reply #12 Top
There are some others I could think of like writing/reading ini-files / the registry or sorting text alphabetically . Could send to You if You want.
Reply #13 Top
I tried using external scripts for a "functions" library, doesn't work.

When you run the object.SetScript("script") it stops all further script processing in the object, and the only script to run in from the "Script" file.

What I tried (and worked) was to make an object called "RomanDAs_Functions" and added several functions in to it (using the WMI Tutorial I did) and then made an object to call these functions from the "RomanDAs_Functions" object. Its a little long on the code lines, but it works great.

The idea would be to have this one object with all your "common" functions in it, then just call them from the other objects you need to use them in.

Example (object RomanDA_Functions)
Function Get_PCName()
Get_PCName = ""
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set CompInfo = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer In CompInfo
PCName = objComputer.Name
Next
Get_PCName = PCName
End Function

Then in the text object where i want to pull the PCName i would use:
 object.text = "ComputerName: " & desktopx.ScriptObject("RomanDA_Functions").Get_PCName & vbnewline


This works really well. I also made a function to read the WMI's Hard Drive Info:
Dim Drive_Count, Drive_TotalSpace(100), Drive_FreeSpace(100), Drive_UsedSpace(100)
Dim Drive_FileSystem(100), Drive_Description(100), Drive_Type(100), Drive_VolumeName(100)
Dim Drive_Letter(100)

Sub GetDriveInfo()
Drive_Count = 0
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set DriveInfo = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objDrive In DriveInfo
Drive_Count = Drive_Count + 1
Drive_Letter(Drive_Count) = objDrive.DeviceID
Drive_TotalSpace(Drive_Count) = objDrive.Size
If objDrive.Size > 1 Then
Drive_TotalSpace(Drive_Count) = FormatNumber((objDrive.Size/1048576),2)
end if
Drive_FreeSpace(Drive_Count) = objDrive.FreeSpace
If objDrive.FreeSpace > 1 Then
Drive_FreeSpace(Drive_Count) = FormatNumber((objDrive.FreeSpace/1048576),2)
end if
Drive_UsedSpace(Drive_Count) = objDrive.Size - objDrive.FreeSpace
If Drive_UsedSpace(Drive_Count) > 1 Then
Drive_UsedSpace(Drive_Count) = FormatNumber((Drive_UsedSpace(Drive_Count)/1048576),2)
end if
Drive_FileSystem(Drive_Count) = objDrive.FileSystem
Drive_Description(Drive_Count) = objDrive.Description
Drive_Type(Drive_Count) = objDrive.DriveType
Drive_VolumeName(Drive_Count) = objDrive.VolumeName
Next
End Sub

Then in the Text Object i would use a call like:
Call desktopx.ScriptObject("RomanDA_Functions").GetDriveInfo()
For x = 1 To desktopx.ScriptObject("RomanDA_Functions").Drive_Count
object.Text = object.Text & vbnewline &_
desktopx.ScriptObject("RomanDA_Functions").Drive_Letter(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_TotalSpace(x) & "KB" &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_FreeSpace(x) & "KB" &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_UsedSpace(x) & "KB" &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_FileSystem(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_Description(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_Type(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_VolumeName(x)
Next

This is just one way to do things.
The goal would be to keep the "RomanDA_Functions" up-to-date with all your most used code.
You could make it point to an object that has 0 Visibility, and then it could be added to any project.

This also makes your code "compile" and encrypt into your EXE, so your code is avail, but protected.


Another way would be to have a function call in DX:
object.IncludeScript("C:\code\RomanDA_Functions.VB")

This would just LOAD into the current object the code from that VB file.
This could be a problem with compiling, encrypting, etc.
But the DX Programmers would need to add this function to DX.
Maybe we call all ask nicely? Maybe make it so that when it compiles an EXE it LOADS that code into the actual object and then encodes it there???

Just some alternatives.
Reply #14 Top
There are some others I could think of like writing/reading ini-files / the registry or sorting text alphabetically . Could send to You if You want.


Ah! Reading/writing text files. Seeing as how I'm doing that alot with this widget it should be useful. Yes, please send them, and thank you! Gotta go now.

If anyone else has some useful pieces of codes to lend, send 'em over via PM or email. (Don't forget to tell me what they are, though)
Reply #15 Top
BUMP of the day
Reply #16 Top
A code snippet gadget sounds like a great idea! Any generic snippet would be would be useful. Sliders / Scrollbars are one thing I think of I didn't see listed.

You can include more than one script in your DX script using a custom include function.

For WMI, there is a very handy tool called Scriptomatic. Check it out for examples of how to access anything WMI has to offer.


Reply #17 Top

You can include more than one script in your DX script using a custom include function.

When you run the object.SetScript("script") it stops all further script processing in the object, and the only script to run in from the "Script" file.


Zubaz is confused
Reply #18 Top
I agree with Zubaz.. omg what am i saying..

How can you "INCLUDE" content with a "custom include function"??? Can we see a sample?
Reply #19 Top
They are a bit hard to see, but my post above has two links in it!

The deal with object.SetScript is that it is a DesktopX function, from the DesktopX namespace. Its behavior is set, and it is such that it will allow essentially a single complete replacement script. This was a workaround to the fact that it is hard to save a backup from the DesktopX editor and every once in a while you are really glad you saved your script to an external file.

But for real, traditional 'Include' functionality we can use a custom function in the main script. This function works not as an extension of DesktopX, but rather a capability of vbscript itself, and does not replace, but inserts text.
Reply #20 Top
rabid,

can you show me this line? Im not seeing it.
Reply #21 Top
In reply number 16, click on the words 'custom include function' or 'Scriptomatic'.


EDIT r#21: Hope that helps.
Reply #22 Top
oops.. moron here.. lol
THANKS!! thats the same (or similar to) the one i use in ASP.

The Q is, does this file have to be there (same location) when its RUN as an EXE or does it compile it into the code???

That is the big drawback to making gadgets with external scripts.
Reply #23 Top
Thanks for stopping by rabidrobot.

Sliders / Scrollbars


Those tend to include setting up the objects first. I'm aiming more for scripts that the user can easily start using without having to explain setting the parent/child relationships and such. I think that might be one the user would add to their custom list instead.


How about resources? Any favorite sites you guys find useful?
Reply #24 Top
well answered my own question.

Tried using the above "code" to import my functions into Dx, then compiled it as a gadget.
It looks for the external script.

Would need a way to encrypt that info somehow. I did it in my HC PRO by making it all link into a database that was protected, wonder if that could work.

Im sure there is a way to encrypt a text file, and decrypt it as well.
But this makes it more complicated.

You would need to package the .VBS file with your gadget, and encrypt it first, then have the corresponding decryper in the gadget to read the file with. This could still be done because you would only need to encrypt the VBS file when you make changes.

Will have to look into this one.

I do like the idea that it can read all my functions into the object, but i think using the method i talked about before where you have a single object with all your functions in it, and then call them from that object. It gets compiled with the widget/gadget making external scripts not needed to be ZIPPED into the EXE.

Still has potential.
Reply #25 Top


Thanks for stopping by rabidrobot.


Glad to be here! I love the idea of a snippet tool, particularly one with DesktopX in mind from the start. I can understand the idea coming from you sViz, because I know from your many tutorials you enjoy both sharing knowledge and aiding the community selflessly.

A snippet widget, which I imagine as a tool serving up handy snippets to the--as you say--beginner, exemplifies this spirit of coorperative community and exploration of shared interests.

The very spirit in which I joined in this discussion, providing information that I personally spent many hours uncovering, deducing, working on, and in this case even writing up to try and kick off the Community DesktopX wiki.

And the very spirit--in some ways not unlike those wonderful and woefully overlooked tutorials of yours, sViz--in which it has been so graciously recieved.