Comatose 290 Taboo Programmer Team Colleague

Try changing your for loop from a reverse count to a normal count:

Private Sub Form_Load()
File1.Path = "C:\Images"
File1.Refresh
 
 If File1.ListCount > 0 Then
   
    For i = 0 To File1.ListCount - 1
      Combo1.AddItem File1.List(i)
    Next
End If
End Sub
Comatose 290 Taboo Programmer Team Colleague

or something.

Comatose 290 Taboo Programmer Team Colleague

Declaring variables isn't required in VB, but it's a great practice. Part of the reason is, when you get into other languages, that are more powerful, you'll be forced to declare any variable before you can use it.... also, declaring variables provides the program with a reserve of memory for that variable. This makes your program smaller, and makes it run faster. On a simple test application, like the one we have here, it won't make a noticable difference, but in larger applications, you'll be asking yourself what the hell happened. Provided is a link to a page that will help you to optimize your VB programming, so that you can increase the speed significantly of yours apps.

Also, When you don't declare a variable, it's default type is a variant. If you read the page linked, you'll see why variants are a no, no. Basically, they are the largest, most bulky variable type in existance, and should really be treated like the Leper Variable. In fact, every time you use a variant type variable, I want you to think about how you are giving your code leprosy.

http://www.aivosto.com/vbtips/stringopt.html

Comatose 290 Taboo Programmer Team Colleague

Ok, the problem is that you declared the variable (msg) as a boolean value.... while the msgbox function returns more values than just true and false. This code works wonderfully when you change the type declaration of your variable:

Dim msg As VbMsgBoxResult

msg = MsgBox("Save this one?", vbYesNo)
 
If msg = vbYes Then
    MsgBox "true"
Else
    MsgBox "false"
End If
Comatose 290 Taboo Programmer Team Colleague

what code is there between the if blocks (where it says 'code goes here), what's actually there?

Comatose 290 Taboo Programmer Team Colleague

try replacing true with vbyes.

Comatose 290 Taboo Programmer Team Colleague

Ghost in the machine?

MartyMcFly commented: :) +2
Comatose 290 Taboo Programmer Team Colleague

I don't understand completely what you are trying to do.... but I can tell you that in order to get the selected item in the listbox, you can say:

selitem = list1.list(list1.listindex)

and that will return the value (in a single-select only listbox) selected in the listbox....

Comatose 290 Taboo Programmer Team Colleague

Depends on if you want to launch the MP3 with the default application or not...... here is an example project that you can use that allows you to select if you want to use the default application, or if you want to specify an application to use when launching the file. It's fully commented, so let me know how it turns out for you.

Comatose 290 Taboo Programmer Team Colleague

When I was in the army, they had filters. The problem I had wasn't that I wanted to look at porn or anything silly, but that even legit e-mail sites were locked out. Being a programmer, with access to a linux box that was outside of the network, I wrote a perl script that allowed me to type in the URL, and it used the LWP module to retrieve the HTML, added a base tag to the HTML (to expand all relative paths) and modified the links so that it referenced my perl program, so that it could get the HTML for the HREF'd page, and saved the HTML file on to the server (the linux box running perl, which was also a web-server). I suppose the concept is a proxy, but when someone can program, you have just lost over half of your power to lock them out of things.

Comatose 290 Taboo Programmer Team Colleague

And you can still use shellexecute to execute a program without it's "default" loading operation. Meaning, you can load media player with the filename you want it to play as a parameter, instead of calling the .mp3 (or whatever) directly.

Comatose 290 Taboo Programmer Team Colleague

just use the Date function, which should return a date, and the time function, which I believe returns a time. You might want to look into the "format" string, so that you can decide the way it's returned (mm/dd/yyyy, hh:mm:ss).

Comatose 290 Taboo Programmer Team Colleague

Unless I don't understand what you are doing, this project should be what you asre after. The project has a label (for identification of what the textbox is), a multi-line textbox (for the information to be typed into), a frame (purely cosmetic), and a button. The project is fully commented, line by line, and section by section, but contains no error checking (for instance, what if the textbox is blank???). Step by step, it gets the drive that the path to the user profile is stored on (the drive the desktop is stored on). Then it gets the path for the profiles home (the parent to the desktop folder), and then it makes a variable with that information, that points to the destkop. Then it writes the information to a logfile on the desktop, and exits the program (using a graceful method of exit, instead of the END command, which is nasty when you get into bigger and funner things [like API's and keyhooks]). Good luck, and hope it helps.

Comatose 290 Taboo Programmer Team Colleague

Thank you for following up with a solution. It helps in many, many ways, and it's not often that people do it.

Comatose 290 Taboo Programmer Team Colleague

Oops, I don't have excel installed.... :(

I thought it was part of the vb project files, I'll check it out

Comatose 290 Taboo Programmer Team Colleague

And the excel document.

Comatose 290 Taboo Programmer Team Colleague

I'm not sure why you need the sleep, findwindow returns a number (the handle to a window) and if it can not find the window, it returns 0. So, do until ret > 0 should work just fine. You may also consider using "doevents" which makes the program process other things temporarily before moving on your code. To answer you actual question, however, there is another API call, called "getdesktopwindow" which will return the hwnd (the numbers that windows refers to the window as) of the desktop to a long variable..

Something that you might want to look at, is the blockinput API call. This will help you I think, but there is a problem, that I'm still looking into, and that is how to disable ctrl-alt-delete with it.... it seems to block everything except for ctrl-alt-del..... so try this:

Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
DoEvents
retval = BlockInput(True)
Sleep 10000
retval = BlockInput(False)
End Sub

This code blocks all input (except for ctrl-alt-delete, working on that) for 10 seconds..... you can obviously block for as long as you want, be it in a loop or whatever.... but be careful ;)

Comatose 290 Taboo Programmer Team Colleague

it's not a good idea to use sleep. Sleeping may always wait (in this case) 1 second, but some machines may take longer than 1 second to load the prompt. Basically, you are having to guess how long it will take that window to appear, and shoot in the dark at an approximate range. I suggest using a findwindow API call, and put yourself in a do loop.... say, do until the return value of findwindow is not 0, then sendkeys to the window.

Comatose 290 Taboo Programmer Team Colleague

Attach your project.

Comatose 290 Taboo Programmer Team Colleague
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlSht)
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlWBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlApp)

will not work in vb6. That, too, is vb.net. In order to have the excel.exe application close from the process list, you are going to need to SET the objects to Nothing. Just like you set the objects to something (be it a workbook, or excel.application, or whatever), you have to then set it back to nothing. One thing about programming (in any language) that I truly love, and that is a pretty strict rule, is that "Anything That You Open, You Must Also Close." Now, while it may not seem that creating an object is the same as opening one, it is. If you do an if statement, what else must you do? You must End If, if you while you wend, if you do you loop, if you open you close, if you create, you destroy.

set xlSht = nothing
set xlWBook = nothing
set xlApp = nothing
set xltmp = nothing
Comatose 290 Taboo Programmer Team Colleague

Nope, that's for .NET, which doesn't apply. Imports doesn't work in Legacy Vb's. However, setting the objects back to nothing is the proper way to go about this. Otherwise, you'll have tons of exe's (as objects) just floating around and eating up Ram.

Comatose 290 Taboo Programmer Team Colleague

I'm a moderator, and unless it's blatently rude, or complete spam, I don't touch people's posts, unless it's to add code tags.

Comatose 290 Taboo Programmer Team Colleague

I knew that, I was just checking to see if you knew :lol:

Have you tried using percentages instead of px? I don't know if it will make a difference or not, but you could try that.

Comatose 290 Taboo Programmer Team Colleague

the only thing that seems off to me (in firefox) is the bar with general info, abous us, etc.... it's a little short. I Also can't see the navigation class, which is inside of layout.css, I presume.

Comatose 290 Taboo Programmer Team Colleague

Is cell 1, 1 empty?

Comatose 290 Taboo Programmer Team Colleague

varname=xlsheet.Cells(1, 1).value?

Comatose 290 Taboo Programmer Team Colleague

Unless I'm mistaken (and could be, since I haven't javascripted in a while), doesn't it matter which browser you are doing it for? (like, aren't the DOM's different for IE and mozilla?)

I think the w3c compliant version is:

document.getElementById('textboxnamehere').value="text to display";
Comatose 290 Taboo Programmer Team Colleague

In truth I agree with Yomet on this.... I didn't want to delve into variable scope, because some people have a real hard time understanding scope... the best solution is to put the variables in the proper scope.

Comatose 290 Taboo Programmer Team Colleague

You never clear the results variable. The results variable always gets added to, because results = results & Chr(Asc(Mid(Password, i, 1)) + 3), which means, results is equal to results and the return of these nested functions, every time it's called (I'm not going to go into variable scope here). When the button is clicked, you need to have it set results = "" before the for loop.

A few pointers and critique here (if you are one of those people who can't stand criticism, stop reading, your answer is above).

Point 1
Indent Your Code
I know that on small projects, it's no big deal... but when you get into larger bigger projects, if you don't indent your code for clarity, YOU WILL get lost in it. Indenting is a necessary part of programming and debugging, and regardless of project size, should still be adhered to. Ideally, The code should be:

For i = 1 To Len(Password)
    Result = Result & Chr(Asc(Mid(Password, i, 1)) + 3)
Next

If Text1.Text = "" Then
     MsgBox "Please key in your password"
Else
     Text2.Text = Result
End If

Point 2
Code Placement
You test if the textbox is empty, After you perform the operation on the textbox...(you encrypt the data in the textbox, AND THEN, you test if it's empty or not...You should test it first, because even though the for loop doesn't care if the textbox is empty, if it was different scenario, where it wrote it …

Comatose 290 Taboo Programmer Team Colleague

Ok, This code was taken from http://www.frez.co.uk/freecode.htm#md5. You can use the class module to instantiate an instance and use the md5 call of it. Like so:

Dim oMD5 As CMD5
Set oMD5 = New CMD5
Hash  = oMD5.MD5("Your Password Here")

Attached is the test project appended to the site I previously mentioned.

Comatose 290 Taboo Programmer Team Colleague

I don't personally suggest the method you are inquiring about.... most password systems as of late, have been using an MD5 (or some other algorithm) to "Hash" the password. Just a little defination here, a Hash is a string that can NOT be decrypted. It's gone through some crazy algorithms that make the string permanently encrypted. Under normal circumstances, this doesn't seem like a very good plan huh? What we do next, though, is when we want to see if the password is correct, is we use the exact same algorithm to Hash what the user types in for the password, and compare the two Hashes with each other. Naturally, if both Hashes are identical, then the password must clearly be the same too. This increases the workload of a password cracker significantly, and adds countless more attempts to a bruteforce attack.

There are pretty good encryption algorithms out there that are pretty darn secure, and at the same time, are decryptable (such as blowfish and triple des) and most of these require a key pair, that gets generated, and only the partner key of something encrypted can decrypt it.

If you aren't THAT worried about security, and only want to keep prying eyes from seeing the password in plain text, then you could do something as simple as an XOR encryption, which is nothing more than an exclusive OR of bits.

Comatose 290 Taboo Programmer Team Colleague

;) thanx.

Comatose 290 Taboo Programmer Team Colleague

yeah,

What you'll want to do, is where you make it update the textbox, in the phrasefinish (or wherever you have it modify the textbox) it would look something like this:

Text1.Text = newspokenwordvariable & Text1.Text

Does that help?

Comatose 290 Taboo Programmer Team Colleague

written where? perhaps I'm lost on what you are trying to do exactly..

Comatose 290 Taboo Programmer Team Colleague

this is really stupid, because the righttoleft property IS indeed locked. In order to get the result that I believe you desire, you'll have to set the textbox's Alignment property to 1 (right justify) instead of the righttoleft property. If this isn't the desired outcome, let me know.

Comatose 290 Taboo Programmer Team Colleague

are you meaning like sentences? Or are you meaning like in the declaration? (show me an example of what you mean.

Comatose 290 Taboo Programmer Team Colleague

The example I gave uses words, but yes it is very limited, because you have to define all the words you want it to recognize.

Comatose 290 Taboo Programmer Team Colleague

I was researching it, and I don't remember which I used.... but here is the source:
Loading the app, complains that I'm missing: Xlisten.dll, Xvoice.dll, and Xcommand.dll, so I'm not sure which of those voice recognitions have those files...

in form_load:

Hear1.GrammarFromString "[Grammar]" + vbNewLine + _
                          "type=cfg" + vbNewLine + _
                          "[<start>]" + vbNewLine + _
                          "<start>=Firefox" + vbNewLine + _
                          "<start>=Comatose" + vbNewLine + _
                          "<start>=Visual Basic" + vbNewLine + _
                          "<start>=Calculator" + vbNewLine + _
                          "<start>=Play Pop" + vbNewLine + _
                          "<start>=Close" + vbNewLine + _
                          "<start>=Minimize" + vbNewLine + _
                          "<start>=Maximize" + vbNewLine + _
                          "<start>=Switch" + vbNewLine + _
                          "<start>=Check Mail" + vbNewLine + _
                          "<start>=Thank You" + vbNewLine + _
                          "<start>=Thunderbird" + vbNewLine + _
                          "<start>=Mozilla" + vbNewLine + _
                          "<start>=Yes" + vbNewLine + _
                          "<start>=No" + vbNewLine + _
                          "<start>=Good Night" + vbNewLine + _
                          "<start>=Send Enter" + vbNewLine + _
                          "<start>=Stop Running" + vbNewLine
Hear1.Activate

And here is the hear1's Phrase Finish (slightly modified for personal reasons):

Private Sub Hear1_PhraseFinish(ByVal flags As Long, ByVal beginhi As Long, ByVal beginlo As Long, ByVal endhi As Long, ByVal endlo As Long, ByVal Phrase As String, ByVal parsed As String, ByVal results As Long)
Select Case Phrase
    Case "Firefox"
        ShellExecute Me.hWnd, "open", "firefox.exe", "", "C:\", SW_MAXIMIZE
    Case "Calculator"
        ShellExecute Me.hWnd, "open", "calc.exe", "", "C:\", SW_MAXIMIZE
    Case "Play Pop"
        ShellExecute Me.hWnd, "open", "pop3.exe", "", "c:\", SW_MAXIMIZE
    Case "Close"
        SendKeys "%{F4}"
    Case "Minimize"
        SendKeys "% n"
    Case "Maximize"
        SendKeys "% x"
    Case "Switch" …
Comatose 290 Taboo Programmer Team Colleague

When you say "all I want it to do" seriously trivializes what you want to do. I built a program that does voice recognition, but you have to make sure that you install the microsoft voice recognition software, and after that, you have to "train" the voice recognition software (it takes some kind of algorithm with your voice and sets itself to function based on the way you talk). I believe the sdk is: http://www.microsoft.com/downloads/details.aspx?familyid=7D13964C-06FD-4BF9-B49C-814FAA6A86EA&displaylang=en
once you get what you need installed and running, let me know, and I can give you the code I used.

Comatose 290 Taboo Programmer Team Colleague

in a code module:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub OpenWith(ByVal xFileName As String)
    ShellExecute 0, vbNullString, "RUNDLL32.EXE", "shell32.dll,OpenAs_RunDLL " & xFileName, "", vbNormalFocus
End Sub

And then wherever you want to show it:

call openwith("somefile.txt")

Let me know how it turns out.

Comatose 290 Taboo Programmer Team Colleague

First problem (in form_load):

me.show
main.Setfocus

Second:
Dunno which box we are talking about... the big multi-line one?

Third (on text1's keypress event, or whatever box you do the typing in):

if keyascii = 13 then
     keyascii = 0
     main.text = text1.text & vbcrlf & main.text
end if
' /* Or Something Like This ^ */
Comatose 290 Taboo Programmer Team Colleague

tmpvar is a temporary variable, used only as a buffer to hold the current line of the file in the loop. Basically, it gets changed on every line of the file. It's only used as a temporary storage place to store the item long enough to stick it into the collection. Truth be told, you could probably read the data directly to the collection, but it makes it easier to read the code using the buffer variable. I'm guessing somewhere you have an option explicit set, which is demanding you declare all your variables... try removing the option explicit, and see if that resolves anything.

Comatose 290 Taboo Programmer Team Colleague

The Melee.txt text file should have 1 entry per line for the code above to work. So, something like:

knife
dagger
spear
elbow

The dir function is telling me if the melee.txt file exists.... the vbnormal portion of it, says to look for a normal file, with no hidden, or system attributes set. Imagine our pain if you did an open command and the file wasn't there..... uh oh.

Comatose 290 Taboo Programmer Team Colleague

Sure it is.... try this in a test project on form_load:

' /* Declare A New Collection */
Dim Melee As New Collection

' /* Add Item Dagger, with index of: dagger */
Melee.Add "Dagger", "dagger"
' /* Add Item Sword, with index of: sword */
Melee.Add "Sword", "sword"

' /* Show By "key" index */
MsgBox Melee.Item("sword")

' /* Show By Numeric Index */
MsgBox Melee.Item(1)

Now, you can do this with some files that read it in.... hmn, something like:

dim meleeFile as string
meleeFile = app.path & "\melee.txt"

' /* If The melee file does Exist */
if dir(meleeFile, vbnormal) <> "" then
     open meleeFile for input as #1
          do until eof(1)
               input #1, tmpvar
               melee.Add tmpvar, tmpvar
          loop
     close #1
end if

And now, whenever you want to add a melee weapon or something, you can just update the .txt file (hmn, you could let the user make their own weapons and stuff now.... cool). Obviously, these are just two examples, but I'm sure you can figure out how to make them work together...

A little on collections:

Collections can be referenced by either a numeric index, or a keyed index. Naturally, the first index say, melee.item(1), would be the first item in your collection list. melee.item(2) the second and so on. You could also reference it by the key name. In the first snippit, you see "Sword" which is the actual value, you could get that from using melee.item(2), but you …

Comatose 290 Taboo Programmer Team Colleague

I would suggest putting these skills into a data file, like a text file, or a database. I might strongly suggest that you look into SQL or ADO (you'll find that you will have less trouble with SQL) for this project. I, however, would go with text files (because I don't always listen to reason). Then, you read in the textfiles, say, on form_load, and use a dynamic multi-dimensional array. I Can See Redim Preserve playing a big role in this. You might also consider using a "collection" instead, which is sort of like an array, but with keywords as indices. Let me know what you come up with.

Comatose 290 Taboo Programmer Team Colleague

Yup.

You set the objects back to nothing (destroying them) before you ever use them in the code:

Dim oXL As excel.Application
      
      Dim oWB As excel.Workbook
      Dim oSheet As excel.Worksheet

      Dim bolExist As Boolean

      Dim strCell_Value As String
      Dim i As Integer
      
      Dim num_cells As Integer
      
      
    Set oSheet = Nothing
    Set oWB = Nothing
    Set oXL = Nothing

You need to use them to do the reading or writing to excel BEFORE setting them to nothing. ;)

Comatose 290 Taboo Programmer Team Colleague

I will say that the C/C++/Javaish/Perlish/etc/etc structure for working with escape sequences is a real treat compared to The basic language. The only way to do this, is to concantenate the character code value to the string where the double quote would be. It's sick, and it makes the code a lot less understandable when dealing with strings, but here is how your example would look:

str1 = "President Lincoln said " & chr(34) & "Four score and seven years ago..." & chr(34)

chr is the basic function to return the ascii value of a given character code. In this case, 34, which is ". This page has a cool list of them: http://www.lookuptables.com/

Comatose 290 Taboo Programmer Team Colleague

Hmn, I get an invalid zip file.... maybe upload it again?

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

;)