Comatose 290 Taboo Programmer Team Colleague

Almost sounds like you are needing answers to a homework assignment, but since I give every one the benefit of the doubt, here are the answers to those questions:

A static variable allows the variable to maintain it's previous value through repeated raises of an event. Meaning that, if you have a variable say "X" and you have a command button. If you add the code snippit to the command button:

x = x + 1
msgbox x

If the variable X is NOT Static, you should always get the same response (which in this case would be one), because every time the event finishes (every time the code in the button is done running) it destroys all the local variables. So, Every time you click the button, the variable gets re-created, as nothing, and then has 1 added to nothing. It doesn't take a math teacher to know that 1 plus nothing is 1. So, it will always be one, because it's always erased when the code is done.

However, Should the variable be "static" then it will keep it's value until the program terminates, or the value is over-written by the programmer. If, in the code above, the variable X where to be static, then it would constantly add 1 to X's previous value. So, the first time you click the button, it would show 1, the second time, 2, and so forth and so on. Basically, static allows the variable to keep it's value …

Comatose 290 Taboo Programmer Team Colleague

Basically, you are trying to create a new qpfile object (er a variable of the qpfile type). The bad news, is that qpfile was installed on the 98 box, but doesn't appear to be installed on the XP box. The other viable problem, is that if the qpfile program was installed on the XP box, perhaps the ocx's or dll's needed for the creation of the qpfile type are not registered. Perhaps you can find those on the 98 box, and copy them to the XP box as well?

Comatose 290 Taboo Programmer Team Colleague

Don't be silly. Open the process with a file handle, and you can write data to it that way. For instance:

# /* Open The Program (Just Like A File) Piping Data To It (For Writing) */
open (FH, "| /path2/install/program");

     # /* Actually Write To The Process */
     print FH "Y\n";

close(FH);

It will obviously be more complicated than that... but if you change the path and program to your install program, and follow through it step by step, you'll be good to go.

Comatose 290 Taboo Programmer Team Colleague

Well, I don't know the application's setup on how it would need the data to be sent to it.... I can certainly give you some code however, to open up and read excel files into VB. Actually sending that data to the other program with sendkeys is a meticulous task. For example, if, on the keyboard, you would press TAB to go to the next field in your software, then you would have to have VB send the TAB, and then the paste, and to move to the next field another TAB. Basically, with sendkeys, you are telling VB to pretend that it is sitting at the keyboard, sending keystrokes to the other application (typing a heck of a lot faster than any of us :eek: ). You have to take into consideration every step that you would normally do yourself, and make the VB Program handle all of those steps.

If You look at the WordNotepad.zip file attached above, you'll see the sendkeys line does only 1 thing. It sends just a ctrl-v (^v) which is the windows keyboard shortcut for paste. In your program, however, it will be much much more complex. If you are just pasting data to notepad, it's no big deal, but to do step by step what you need to (what you want to do) requires intimate knowledge of the software you are sending the data to. Does that make sense?

Comatose 290 Taboo Programmer Team Colleague

;)

Comatose 290 Taboo Programmer Team Colleague

Certainly, however there are some things to consider. If the program in discussion is run from a DOS prompt (meaning, it's a DOS based program, so, it shouldn't really have a "windows" window.), then you'll have to get creative. DOS Prompts, in my experience don't work well with sendkeys, so you would need to copy the data to the clipboard, and then send an "alt space ep" ("% ep", which is alt, space, e [for edit] and p [for paste]) to paste the data from the clipboard to the DOS prompt or DOS Based Program.

If you are working in a windows based program, for example, transfering data from excel to quicken or something crazy, you could absolutely create an instance of the excel object, load the spreadsheet of your choice, read in the data from the cells, and transfer that information to another windows based program no problem. Let me know if you need any further assistance in this matter.

Comatose 290 Taboo Programmer Team Colleague

While you are playing the game, hit cntrl-alt-delete, it will load task manager, but more importantly, will bring you back to windows While The Game Is Still Running!
Once Back in windows, click start, go to run, and type in cmd. You will get a black box window (a dos prompt), type in (at the black window) netstat. Take all the information it gives you, and either post it here, or e-mail me all that data. I'll sift through it, and find the server and port needed for this program.

Comatose 290 Taboo Programmer Team Colleague

Would It be possible to attach the project as a .zip file, with any needed files?

Comatose 290 Taboo Programmer Team Colleague

It doesn't look like that's correct. I ran a port scan on the server: xaoswow.servegame.com, and that port doesn't show up as being open. At the same time, the web page shows a green box, meaning the server is up. Either you have the port wrong, or the server wrong.

Comatose 290 Taboo Programmer Team Colleague

The page is 8080, but I don't think the port for the game is.

Comatose 290 Taboo Programmer Team Colleague

I'll tell you what, you need to either A) Ask the Admin What PORT it runs on (or if you know what port it is, that's cool. You could always be connected to the game, go to a DOS prompt, and run NetStat, and give me the statistics of it.) Once I know the PORT and the Server IP, I'll build you one using Sockets, which will connect to the Game Port of the server, and not just to see if the box itself is up or down.

Comatose 290 Taboo Programmer Team Colleague

*Nods*

Comatose 290 Taboo Programmer Team Colleague

Mkay, And The Updated Version, Which is still not perfect and contains some minor flaws, but does exactly what you want. You may need to copy the tray.ocx to your windows\system32 folder, or just replace the one in the project with the one in the zipped folder... either way, the program works like a charm for me.

Comatose 290 Taboo Programmer Team Colleague

As Far As I'm Concerned, .NET is the Bane of Windows Programming. I'd Rather Write An Entire App For Windows in ASM :eek:

Comatose 290 Taboo Programmer Team Colleague

Wow, Cain, Thanks for that. However, The Forum is "Visual Basic" and to my knowledge (even with the use of wine on a wicked system) VB will NOT Run on a *nix box. I've tried. So, Should the thread be related to merely checking a server's status, that would be awesome, but this is a windows computer programming forum.

Comatose 290 Taboo Programmer Team Colleague

For Additional Fun, Add A Timer Control To Do This Every 10 Seconds

Comatose 290 Taboo Programmer Team Colleague

Yes, But it's a lot more detailed and complex than you might think. Basically, I've devised a way using the API (StretchBlt) That shows how you can copy an image from a picture box, to another picturebox, changing size from one to the other. A Few things to note, is that the quality diminishes during this process (quality of the picture) AND the picture must be visible in order to copy from it. This project loads an image into form2, and when you click the button, makes form2 visible (makes the picture visible), and then copies it to the picturebox on form1, and then hides form2.

As you can see, this would be intensive on the processor, and probably take up quite a bit of RAM. I'm still devising a way to use objects or API Calls to specific graphic programs that would allow for better picture quality and faster processing, but for now, this is how to use the stretchblt API.

Comatose 290 Taboo Programmer Team Colleague

The easiest solution is to shell a ping command, and redirect the output to a temporary file. Open the Temporary file, and have your VB Program read in the lines (compare using instr) and check if there is a timeout, or if there is a response from the server. If there is a response from the server, naturally, the server is up. If you get, instead, a ping timout, then the server is down. If you really want to get fancy about it, you could try to connect the server on port 80 (the web page port), rip apart the HTML, and have it figure if the image is Red or Green. The first option is clearly easier, and is just as effective. Let me know if you need any further assistance in this.

Comatose 290 Taboo Programmer Team Colleague

He's absolutely correct, but beyond that, you may want to have a look at the setforegroundwindow, setactivewindow, and the setfocus API calls. Basically, this is to ensure that the window you are trying to send keys to is the active window. It MUST be the active window, in fact. The sendkeys command is just like a person sending data from the keyboard. So, if you would normally have to press tab, say, 3 times to make the "run" button become the button of focus, you would have to sendkeys 3 tabs in order to make that button the focus. If you need a list of the special codes (such as enter and tab) check out this site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthsendkeys.asp

Comatose 290 Taboo Programmer Team Colleague

I'm still not sure what you mean.... you have an EXE file that launches an app. You want to EDIT the EXE to change what app it launches?

Comatose 290 Taboo Programmer Team Colleague

The Zip is Invalid or corrupt... Please reattach the .zip in a new post to this thread. Thanks.

Comatose 290 Taboo Programmer Team Colleague

Ultimately, the concept differs depending on your application. If Word was LAUNCHEDwith YOUR Application, Then you can use the API Call "Waitforsingleobject" or (if your program doesn't need to do anything while word is launched) you can use WSH with shell and the .run method. With the latter, you can make it wait until the app launched is closed before proceeding to the next line of code!

The alternatives to either, is a bit more messy (these are the only options I know of if word was NOT launched by YOUR Application), is to use the "findwindow" API Call in a timer control and search for the class name of word. You could also use the findwindow API Call, and instead of the class name for word, use the title in the titlebar of the window. This is not a good way, because if an instance of word is already running, you'll have to figure out which one to close. If you know what is in the titlebar, it's easy enough, but knowing the title bar caption isn't very easy, because it can change depending on the file name and other variable factors. Certainly you can loop through all of the running instances, but figuring out which one to close (assuming more than 1 copy of word is running) is uh, well, you get the point.

The other option, not much easier, is to enumerate the process list, search for the word executable file, grap it's PID (process …

Comatose 290 Taboo Programmer Team Colleague

Assuming you are using a database program, and not something sick like flat files :eek:

Comatose 290 Taboo Programmer Team Colleague

Oh Yeah, It's On!!!!

The Concept of how it works is this: The VB Program Makes A Batch File, Starts A Timer, And then runs the batch file. The timer searches for a specific file, every 100 MS... just exits the sub if it does not find it, but if it does find it, then the timer knows the batch file is done running (The last line of the batch file is to create this "flag" file). The Batch file Creates two files, the flag file (to signal the VB Timer control that the batch file has finished), and a results file. The results file is the output of a dir /a/s/b command, using redirection to create a new file with all it's output. Basically, the results file contains a list of paths to the extention in question. So, the vb app (when the timer sees the flag file) stops the timer, removes the flag file, removes the batch file, opens the results file for reading, loads the data into a listbox, and then deletes the results file. Whew! I've commented the code completely so you can see it line by line, but having a basic overview of what's going on helps a great deal.

Comatose 290 Taboo Programmer Team Colleague

Aw Crap! Here's Part of it:

in a Module (you'll also need to declare the registry API's, But There Are Too many API'S in my project to sift through):

Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const REG_MULTI_SZ = 7
Public Const ERROR_MORE_DATA = 234
Public Const KEY_READ = &H20019
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003

public Function EnumRegistryKeys(ByVal hKey As Long, ByVal KeyName As String) As Collection
    Dim Handle As Long
    Dim length As Long
    Dim index As Long
    Dim subkeyName As String
    
    ' initialize the result collection
    Set EnumRegistryKeys = New Collection
    
    ' Open the key, exit if not found
    If Len(KeyName) Then
        If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, Handle) Then Exit Function
        ' in all case the subsequent functions use hKey
        hKey = Handle
    End If
    
    Do
        ' this is the max length for a key name
        length = 260
        subkeyName = Space$(length)
        ' get the N-th key, exit the loop if not found
        If RegEnumKey(hKey, index, subkeyName, length) Then Exit Do
        
        ' add to the result collection
        subkeyName = Left$(subkeyName, InStr(subkeyName, vbNullChar) - 1)
        EnumRegistryKeys.Add subkeyName, subkeyName
        ' prepare to query for next key
        index = index + 1
    Loop
   
    ' Close the key, if it was actually opened
    If Handle Then RegCloseKey Handle
        
End Function

Public Function EnumRegistryValues(ByVal hKey As Long, …
Comatose 290 Taboo Programmer Team Colleague

If You Are Wanting To Retrieve A List of those options, for a given file, you are going to need to know a lot about the registry (a lot more than I can explain here). If you are already registry proficient, then, for a .doc file, for example, you might start by looking at: HKEY_CLASSES_ROOT\.doc, the "default" value for that, is a pointer, to another key in HKCR, in my case, Word.Document.8. So, you would then have to navigate to: HKEY_CLASSES_ROOT\Word.Document.8, and then check out the "shell" key. At this point, you'll have to "enumerate" all of the subkeys of the shell subkey, to give you a list of menu options. If you open one of the subkeys, you'll see that the tree nests even further, and if you open, say "New" you'll see a "command" subkey, which will reference the path and EXE to the file to launch in case of a click to "New".

Truth is, it's a real pain to do this, mostly because of the enumeration of the registry. This isn't the easiest thing in the world to do, but you would need the API Calls:
RegEnumKey, RegEnumKeyEx, and RegEnumValue (For The Values In The Keys). You Might Need RegOpenKeyEx, and RegCloseKey Too (Since I Think They Have To Be Opened Before You Can Enumerate Them). I Wrote A Program That Does This As A Part of it's functionality, but the Project in it's entirety isn't fully functional, So I won't be posting it. …

Comatose 290 Taboo Programmer Team Colleague

If you have the label's in a control array, it's easy enough to make a function in the click event of the label, and have it change the label to the number in the textbox.... You might consider checking out the attached project, which makes a textbox dragable, so that you can drag the entered number to the label in question. Let me know if this helps any.

Comatose 290 Taboo Programmer Team Colleague

I would actually go with a control array of picture box's. This way, you could use pictures in the box's to represent the numbers, and if you wanted to give different styles or themes, it would be a breeze. If that seems a bit too complicated, go with the labels...

Comatose 290 Taboo Programmer Team Colleague

Do you mean the target of a shortcut, or the target of an EXE?

Comatose 290 Taboo Programmer Team Colleague

what do you mean by a list of possible actions? Something like the "open with" menu, or something like the properties menu?

Comatose 290 Taboo Programmer Team Colleague

No Problems, I know you'll help me when I need it! You could leave your code the same as what you posted above, only change the write #1 command to a print #1, and you'll remove the quotes :).

Comatose 290 Taboo Programmer Team Colleague

Alright...

Read Over This Code (It's Fully Commented) and you can pick out what you need, so that you can add it to your project and have it work the way you want it to. Right now, it (the wordnotepad) copies all the text in a word document (in this program, the path is the same as the running project [meaning the word document should be in the same folder], and it's name is test.doc), launches notepad, waits until it see's that notepad is loaded, and then sends it a paste command using Sendkeys.

This Method, however, is still not ideal. The reason, is because there are a lot of restrictions in place for it. You have to make sure that notepad is visible, and that it is the active (foreground) window. This also doesn't take into account any popup windows, or programs that might jump to the front of all the applications because of some event. Granted, (on my PC at least) once the VB app sees the notepad window, the sendkeys is almost immediate (before the form loads, in fact), but keep in mind that the possiblity for being interrupted and throwing the whole system out of whack does exist with the sendkeys method. Nevertheless, I have attached a project that shows how that can be done.

The Best Alternative That I have Found thus far, is to create a word instance, and use the "saveas" method to save the word document as a .txt …

Comatose 290 Taboo Programmer Team Colleague

Look Into The Excel Object. You can create/Manipulate excel documents with a VB Program (even with WSH alone) by using these objects. An Example

set xapp = CreateObject("Excel.Application")
xapp.Visible = True

' Make a new Excel workbook:
set workbook = xapp.Workbooks.Add
set worksheet = workbook.Worksheets("sheet1")

Basically, It just shows you HOW to work with it in VB. If you Google VB6 Excel.Application, Google will give you a whole lot of information on it. You can also read up on the excel object straight from the horses' mouth:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrgrfexcelapplicationobjectmethods.asp

This way, you can work with the excel document (the cells, and everything) without ever having to set it's visible property to true (meaning, it stays hidden). Let me know what you come up with though.

Comatose 290 Taboo Programmer Team Colleague

I'm not sure why you would WANT to do that, but can't you just set the form to load maximized, and then use a timer control with a real short interval (like 100 ms) to call an API (setforegroundwindow) to make sure your maximized form is always the foreground window, or do you have another purpose?

Comatose 290 Taboo Programmer Team Colleague

Nice Code Here, But I would Personally Choose a different style. I think you have the right idea by using the word object, but I think you should use the methods of the word object to completely bypass the use of sendkeys (Well, At Least Put To A Minimum). For Example: http://www.dx21.com/SCRIPTING/VBSCRIPT/EXAMPLE.ASP, and then click the eye for "Spell Check Clipboard with Microsoft Word", it shows how to copy and paste information from Word Using The Word Object, However, That Wasn't Your Question, Just My Suggestion.

To Answer Your Question, I see two Major problems. One Is That Word Is Never Shown, or Set To Visible. This is a problem, because I'm pretty sure that sendkeys only works with active AND Visible Windows. The Second Issue, Is That VB Would be sending Keys (The File Open And All That) WITHOUT WAITING For Word To Be Launched. When You Instantiate A New Instance Of Word, It might take a variable amount of time (depending on the RAM and Processor Of The Machine in question). I suggest A couple of fun API Calls, One Is "FindWindow" (Or FindWindowEx If you want to be more daring), and "setforegroundwindow", however, you could also use AppActivate. In Order to get word to show (after creating the word object), you'll need to set it's .visible property (or invoke it's .show method, depends on the version you are using).

Sorry to be long winded, but I hope that some of the suggestions will …

Comatose 290 Taboo Programmer Team Colleague

I'm Pretty Sure This Is What You Are Asking For. The Key To Understand How This Works, Is To Take A Good Hard Look At The Collection. A Collection, Which Is Like An Array, Has Methods That Makes Working With Data Easier. We Populate The Collection With All The Words Of The Sentence, And Then Loop Through All The Words We Have, Generating A Random Number Between Zero And The Same Length As The Collection. Then, We Remove The Element Of The Collection That Was Randomly Selected (After Assigning It To An Array), Which Will Make The Max Variable (The Variable Used As The Upper Border Of The Random Seed) Decrement, Making The Random Selection One Less Than Before (Not Just One Less, But The One We Have Already Randomly Chosen On The Previous Loop).

I'm Probably Complicating The Situation By Trying To Explain It So In Depth, So Examine The Code And Comments, And Let Me Know How It Works Out For You.

Comatose 290 Taboo Programmer Team Colleague

I don't understand what you are wanting to do.... do you want each word of the sentence in a new label, or do you want a random word of the sentence in the one label???

Comatose 290 Taboo Programmer Team Colleague

what exactly do you mean by reset? Just set it to zero?

Comatose 290 Taboo Programmer Team Colleague

if you e-mail me, or post your e-mail, I'll send it to you as an attachment to your inbox wherever you'd like.

Comatose 290 Taboo Programmer Team Colleague

Me Too.

Comatose 290 Taboo Programmer Team Colleague

I would personally suggest downloading the module from CPAN's website at:
http://www.cpan.org, and download the bundle in the tar/gz format. Then, once you have it downloaded, make a temp folder of some kind, that will contain the extracted files (a tar/gz is sort of like a .zip file), then move the tar/gz file to the new folder, and extract the files (or, make the new folder, and download the file to it). Once there, ungz, untar it, and run the installation yourself....something crazy like:

gunzip CGI-Application-Session-0.07.tar.gz     #unzip the file
tar xvf CGI-Application-Session-0.07.tar         #untar the file

Then once it's unzipped and untared, you'll need to check out the makefile.... in the example that I'm using here (application-session), you'll need to run perl on the makefile... so:

perl Makefile.PL  #run perl on the makefile
make               #Run the make command on the output file from Makefile.PL
make install      #run the installation parameter of make on the makefile (or install file)

Don't get me wrong, I'm sure there are other ways and other fixes, as always... but this seems to be working for me... if you have any errors or problems trying it this way, I'll see if I can't help you through them also... in any case, let me know the outcome.

Comatose 290 Taboo Programmer Team Colleague

I think the multiline property can only be set during the design, and not at run time.

Comatose 290 Taboo Programmer Team Colleague

Is it possible that the vb open command is not waiting for the shell command to finish? You could make sure that VB deletes the random file, and then waits for the random file to exist again before finishing a doevents loop.... for example:

' /* Check If The Random File Exists */
if dir(app.path & "\random.txt", vbnormal) <> "" then 
     ' /* If So, Remove The Random File */
     kill app.path & "\random.txt"
end if

' /* Ok, Launch random.exe */
Shell App.Path & "\random.exe", vbHide

' /* Loop Until The Random Text File Exists Again */
do until dir(app.path & "\random.txt") <> ""
     ' /* Process System Events */
     doevents
loop

' /* Open The Random Text File For Reading */
Open App.Path & "\random.txt" For Input As #1
     ' /* Read In The Random Number */
     Input #1, RandomNumber
Close #1

' /* Set The TextBox To The Random Number */
txtRandom.Text = RandomNumber

I'm not sure how that will work, but let me know how it turns out.

Comatose 290 Taboo Programmer Team Colleague

I'm not a moderator on this forum ;)

Comatose 290 Taboo Programmer Team Colleague

Basically, you can use the system command:

system("c:\somepath\some.exe");

or you can use backticks, such as:

`c:\somepath\some.exe`;

And yet another solution is to use the open command:

open(FH, "c:\somepath\some.exe |");
close(FH);
Comatose 290 Taboo Programmer Team Colleague

You'll have to create a huge string. As far as I can tell, updating the clipboard with VB6 overwrites what was there previously. Just like if you keep opening a file for output instead of append. The easy solution is to have 1 variable that keeps getting concantenated during a loop, and then assign the clipboard the value of the variable....

Comatose 290 Taboo Programmer Team Colleague

I think you can do something crazy (I do this) by just pushing values onto inc, such as:

push(@INC, '.');

Which adds the current directory (.) to the INC (search path) of Perl. You should be able to any path, but I haven't tried. I know . works, but I'm pretty positive you can add any permissable (given permissions) path.

push(@INC, '/home/yourname/path2yourpms');

Let me know how that turns out.

Comatose 290 Taboo Programmer Team Colleague

post the hello world code

Comatose 290 Taboo Programmer Team Colleague

*Just Smiles*

Comatose 290 Taboo Programmer Team Colleague

Yeah, If you fixed it, what did you do?