Send multimedia keys using VB6 [closed] - vb6

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I know that pause/play key(from keyboard)'s keyCode is 179, but how can I programically press those multimedia keys from VB6? There are some questions about it but they're for C#/C++/VB.Net

You can use the Chr function to convert your keycode to a string that SendKeys can use:
SendKeys Chr(179)
You might run into a Permission Denied error next, which you can work around by using a WScript.Shell object by using this subroutine:
Private Sub SendKeysViaWshShell(p_iKeyCode As Integer, Optional p_fWait As Boolean = False)
Dim objWshShell As Object
Set objWshShell = CreateObject("WScript.Shell")
objWshShell.SendKeys Chr(p_iKeyCode), p_fWait
Set objWshShell = Nothing
End Sub

Related

excecuting vbscript(?) code: automatically open new files in a directory [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
im new to vbs-,Powershell-, ... coding
i need to build something that checks for new files in a specific directory and opens all newly added files automatically.
i've found this post which seems to fit my needs perfectly: https://devblogs.microsoft.com/scripting/how-can-i-automatically-open-new-files-added-to-a-folder/
I tweaked the code to my situation like this:
Set objShell = CreateObject(“Wscript.Shell”)
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
(“SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE ” _
& “Targetinstance ISA ‘CIM_DirectoryContainsFile’ and ” _
& “TargetInstance.GroupComponent= ” _
& “‘Win32_Directory.Name=””T:\\\\Reporting\\\\AutoOpen””‘”)
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strNewFile = objLatestEvent.TargetInstance.PartComponent
arrNewFile = Split(strNewFile, “=”)
strFileName = arrNewFile(1)
strFileName = Replace(strFileName, “\\”, “\”)
strFileName = Replace(strFileName, Chr(34), “”)
objShell.Run(“excel.exe ” & strFileName)
Loop
Bummer that the above post contains no details on how to actually use the code or what programming language it is :D
I assumed this snipped is for vbscript. When i put it in a .vbs file and execute it, i get the error-message "invalid character, line 1, character 29, compiling error, ..." -> this character is the first quotation mark in line 1.
So i also tried powershell, but it seems like the code doesnt fit there either.
... So what kind of code is this after all?
And how can i put it in an executable file?
Thank you so much in advance.
The slanted or smart quotes “.” you are using are invalid in vbscript code.
You should replace all of them with regular double quotes "
Applications such as MS Word tend to convert regular quotes with these slanted ones, so that might be where you got them from.

read from exe files in vb6 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to read from exe files so i find this code
Dim strData As String
Dim lngFind As Long
Open txtAdrsOfFile For Binary As #1
strData = Space$(FileLen(txtAdrsOfFile))
Get #1, , strData
Close #1
lngFind = InStr(1, strData, txtFindString)
If strData = txtFindString Then
MsgBox "FIND"
Else
MsgBox "NOT FIND"
End If
its need a command buttton and 2 text boxs
but its not working
if there be a way to use that code if you guys can plz help me with doing this for multitipe strings i mean we can read more than 1 form a file
tnx
Firstly instr() returns an integer of the position of the find string inside the search string
It will not alter the two strings you pass it.
So instead of checking
If strData = txtFindString Then
You should check
If lngFind > 0 then
MsgBox "FIND"
Else
MsgBox "NOT FIND"
End If
This is because StrData is still going to equal what the contents of your file was before you call instr()
Also as pointed out if you searching for text and aren't worried about matching case you should call instr() with the text flag
lngFind = InStr(1, strData, txtFindString,1)

Copy a Cell Below A Cell with a Constant Value (see screenshot) - excel [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The picture will make it all make sense. But I'm just trying to copy the text from below the "Author information:" Cell to another cell location. This isn't difficult for a few because it's just a simple copy and paste but I need to search the entire worksheet and extract all of the info from the first cell below "Author information:" At this point there are thousands of entries...
Screenshot Dropbox link: https://www.dropbox.com/s/nbyg8lkay3c5c9s/Screenshot%202013-12-27%2016.32.38.png
Any help would be fantastic!
For ease, try the following.
In cell C2 type this formula =IF(A1="Author Information:",A2,"")
Copy this formula all the way down
copy the results in column C to another sheet and paste-special with values only
Sort that sheet to get rid of blanks
That should be a quick and dirty way to get it done.
Try this code:
Sub copyAuthorInfo()
Dim src As Worksheet, tgt As Worksheet
Dim irows As Long
Dim rrows As Long
Set src = ThisWorkbook.Sheets("Sheet1") ' this is the sheet with the original data
Set tgt = ThisWorkbook.Sheets("Sheet2") ' author info will be copied into this sheet
irows = src.UsedRange.Rows.Count ' count the number of used rows in sheet 1
rrows = 1 'row counter for the target sheet
For i = 1 To irows
If Cells(i, 1).Value = "Author information:" Then 'make sure to adjust the search text
' copying columns A to C. Change the 3 in the following line to copy more columns.
Range(Cells(i + 1, 1), Cells(i + 1, 3)).Copy tgt.Range("A" & rrows)
rrows = rrows + 1
End If
Next
End Sub
To run the code, you need to open the Visual Basic Editor (VBE) with Alt-F11 or your preferred method. Use Insert > Module and paste the code. You can run the code by hitting F5 while the cursor is somewhere in the code.
You have tagged with OSX. Does that mean you use a Mac? You also tagged with Excel 2007 and 2010. The code will run fine in these, but not in Excel 2008 for Mac, because it does not support VBA.

Lotus Notes - lotusscript: shell function: illegal function call

I have a problem: I want to run a file from lotusscript code:
Dim result As Integer
result = Shell("D:\testF.dsx", 1)
And I get the following error: Illegal function call.
If I want to execute it from formula it works:
#Command([Execute]; "D:\\testF.dsx")
Thanks a lot!
I had the same problem with the shell function in lotus script with PDF files. And my workaround is to use the windows scripting host to launch the file. I am pretty sure this will solve your problem too.
Set objShell = CreateObject("WScript.Shell")
returnValue = objShell.Run("d:\testF.dsx", 3, false)enter code here
It is not possible to "Execute" a Textfile. usually there is no "run" function defined for dsx- files.
You could do it like:
Dim result as Integer
result = Shell("notepad.exe D:\testF.dsx", 1)
Or find out, which program is linked to dsx (via registry) and execute the corresponding exe with filename as Parameter. If the filename contains spaces, then it has to be enclosed:
Dim result as Integer
result = Shell({notepad.exe "D:\testF.dsx"}, 1)
And reading your last question this approach for sure is NOT the right for your request. You have to use "open" in order to process files... Like Per Hendrik told you in his response.
I had similar problems passing parameters to Outlook.
On some windows machines, this #Formula worked perfectly:
#Command([Execute]; "Outlook.exe"; "/recycle")
On Windows Terminal Servers, it caused Outlook to be unable to parse the "/recycle"
The Shell-command from LotusScript wasn't even able to locate the Outlook.exe, as it was not in the PATH.
Ralf's code helped me in this respect. The "WScript.Shell" seems able to interact with Windows registry settings. Anyway, here is the code that works for activating an open Outlook window.
Dim objShell, returnValue
Set objShell = CreateObject("WScript.Shell")
returnValue = objShell.Run("outlook.exe /recycle", 3, False)

Any have a Visual Studio shortcut/macro for toggling break on handled/unhandled exceptions? [duplicate]

This question already has answers here:
Toggle "Break when an exception is thrown." using macro or keyboard shortcut
(10 answers)
Closed 3 years ago.
I've been trying to write a macro do do the equivalent of
Hitting Ctrl+Alt+E to bring up the Exceptions window
Toggling the textbox in the 'thrown' column for 'Common Language Runtime Exceptions'
Hitting OK
If I record this, it records only a single line of macro code which doesn't do anything. Anyone know how to do this?
It's late and I haven't tested it, but does this help?
Dim dbg As EnvDTE90.Debugger3 = DTE.Debugger
Dim exSettings As EnvDTE90.ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
Dim exSetting As EnvDTE90.ExceptionSetting = exSettings.Item("System.Data")
If exSetting.BreakWhenThrown Then
exSettings.SetBreakWhenThrown(False, exSetting)
Else
exSettings.SetBreakWhenThrown(True, exSetting)
End If

Resources