Combobox from Visual Studio Macros - visual-studio-2010

When you need to debug a Website that hosts on IIS Express, you usually don't restart it all over again, every time when you need to rebuilt your code. You just attach VS to the process. And the macros script helps a lot:
Public Module AttachToProcess
Public Sub AttachToWebServer()
Dim attached As Boolean = False
Dim proc As EnvDTE.Process
For Each proc In DTE.Debugger.LocalProcesses
If (Right(proc.Name, 14) = "iisexpress.exe") Then
proc.Attach()
attached = True
Exit For
End If
Next
If attached = False Then
MsgBox("iisexpress.exe is not running")
End If
End Sub
End Module
You can assign a keystroke and voila. The only problem is if your solution contains more than one webapp, there would be more than one iisexpress.exe processes with different PIDs, and VS would sometimes choose the wrong one.
The question: Is it possible to popup a dialog if there is more than one iisexpress.exe running to choose the right one?
Of course you can always use default 'Attach To Proccess' dialog, but it's not gonna be as quick as using that script and keyboard shortcut.

You can open a dialog, but it's not the most straightforward thing. You will need to put all your UI code into the macro, EG layout, size of controls, etc...
It's about 200ish lines of code, and rather than put it all here I will defer you to my blog at http://www.brianschmitt.com/2010/09/save-and-change-tool-layout-in-visual.html
You should be able to reuse the View Switcher dialog box and list out all instances of IISExpress. It shouldn't take much to do what you need it to.

Related

How do you open a GUI when you touch a brick? (with Filtering Enabled)

I'm trying to make a Shop enclosure when you touch a brick, it'll open the Shop Gui,
Now the main problem is that I do not know how to make the GUI open since using scripts whilst filtering enabled just won't cut it.
Does anyone have a solid explanation?
First of all, in order to execute any action when a brick is touched, you will need to use the .Touched attribute of your brick. Your brick has this attribute because it is a data type called a Part.
Second of all, I am not sure how you want the GUI to open, but the most basic way is to enable it using the .Active attribute of your GUI element. This will simply make it appear on screen. You GUI element has this attribute because it is a GuiObject, whether it be a Frame, TextButton, or whatever else.
The code will look something like this:
brick = path.to.part.here
gui = path.to.gui.here
function activateGui() --shorthand for "activateGui = function()"
gui.Enabled = true
end
brick.Touched:connect(activateGui)
Notice that .Enabled is a boolean (true or false). Also, notice that .Touched is a special object with a :connect(func) function. This is because .Touched is actually an Event. All Events have a special :connect(func) function that take an argument of another function func which is to be executed when the event occurs. In this case, we asked the brick's .Touched event to execute activateGui when it occurs.
Also, .Enabled is set to true by default, so in order for this method to work, make sure you set it to false in ROBLOX Studio by unchecking .Enabled in the Properties tab for the GUI element. Note that you do not have to do this for every single element of the GUI; if you set .Enabled to false on a certain element, all of its children will also automatically be hidden, so you only have to do it on the parent element.
Finally, you must do this in a Local Script. Because the GUI is unique for every single player, it is actually handled by each player's computer, not the ROBLOX server itself. Local Scripts are scripts that are specifically handled by a player's computer and not the server, so it is crucial that you do not try to do this with a regular Script, which is handled by the server.
For your information, the above code can be condensed to this if you would like:
brick = path.to.part.here
gui = path.to.gui.here
brick.Touched:connect(function()
gui.Enabled = true
end)
This is because you do not have to create a function, name it, and then give that name to .Touched; instead, you can just create it right on the spot.

Active IE 11 window for SendKeys

Problem : I am trying to automate the saving of a file (manage to save the file when the below IE bar appears at the bottom of the page)
My code is going on my intranet, clicking here and there and then I click on an "Export" button which will trigger this from IE :
I didn't manage to find a way to automate the saving of the file because the only way (I think) to interact with this "window" is to use SendKeys.
In order to do so I have to "activate" this window (Yes, I have it activated for the HTML scraping with this bit of code, but it's not the active window though):
I tried using AppActivate but for some reason it doesn't work.
There are 2 options to pass this obstacle :
Find a way to activate the IE window containing that saving bar so that I can use Application.SendKeys "%{S}" on it
(second option only) : Disable this saving bar or manage to have it open in a new window
So far I have gone through lots of posts talking about that subject but none gave an operational solution for that issue on IE 11.
Let me know if you want to see any bit of code, I have a lot of different attempts gathered from different posts but this would highly increase the length of this post.
Front-end automation is a tricky business. It can be really hard to find a solution that always works (those pesky users are free to move the mouse and click buttons at will, disrupting your code). Because you are taking the data from an intranet site, this suggests the data you need already exists within your organisation. If at all possible (and I know it isn't always) take the data from the servers/source systems, rather than via the UI.
AppActivate and SendKeys can be very fussy. Because the url is always the same a better approach would be to directly download it. Here is a example, based on another answer.
Before you can run code you will need to add two references:
Microsoft XML, v6.0
Microsoft ActiveX Data Objects 2.8 Library
From the VBA IDE click Tools >> References... and select from the list (the original answer does not use references, instead it uses late binding).
' Downloads a file from a given URL.
' URL String URL to get file. Ex: http:\\MySite\MyFile.
' Path String Location to save file. Ex: C:\Myfile.csv.
' Requires: Microsoft XML, v6.0
' Requires: Microsoft ActiveX Data Objects 2.8 Library.
Sub DownloadURL(ByVal URL As String, ByVal Path As String)
Dim httpXML As XMLHTTP60 ' Used to download data.
Dim st As ADODB.Stream ' Used to write downloaded data to file system.
Set httpXML = New XMLHTTP60
' Request file.
httpXML.Open "GET", URL, False
httpXML.send
' Download response.
If httpXML.Status = 200 And httpXML.readyState = 4 Then
Set st = New ADODB.Stream
st.Open
st.Type = adTypeBinary
st.Write httpXML.responseBody
st.SaveToFile Path, adSaveCreateOverWrite
st.Close
Else
MsgBox "Something went wrong :(", vbCritical, "An error occured"
End If
End Sub

How do I sort build output of Visual Studio by Build Order by default?

I know that I could sort the build output of my multicore builds in Visual Studio using the Build Order item in the Output window (as described here).
But once I've done that and hit F7 again, the option switches back to Build and I have to switch back to Build Order again.
Is there a way to set Build Order as default setting in the Output window?
Searching a bit shows me that this question was asked several times but never answered:
http://ntcoder.com/bab/2009/06/02/ordering-output-of-out-of-order-builds-in-visual-studio/#comment-484
http://blogs.msdn.com/b/zainnab/archive/2010/07/03/show-the-output-window-during-build-vstiptool0045.aspx#comments
http://weblogs.asp.net/scottgu/archive/2005/10/21/428094.aspx#1451451
Edit:
The answer given by Simon works for me (or at least it points me to the right direction), but I could not simply copy his code and insert it in my MyMacros project. Instead, I have to create the handler for the build events exactly as described here:
On the Class View explorer pane, in the Macros IDE, double-click the EnvironmentEvents node to display it as an EnvironmentEvents tab
and a drop-down menu on the macro editor pane.
From the EnvironmentEvents drop-down menu, select an events type, such as TaskListEvents. The Declarations combo box is now populated
with the available Task List events.
On the Declarations drop-down menu, select an event, such as TaskAdded, to add its event procedure to the module.
The event is inserted into your macro and you can now add code to the event procedure.
Otherwise, the event handler isn't called at all.
You could write a Visual Studio macro, something like this:
Dim WithEvents MyBuildEvents as BuildEvents
Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles MyBuildEvents.OnBuildBegin
OpenBuildOrderOutputPane()
End Sub
Private Sub OpenBuildOrderOutputPane()
Dim window As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput) ' Get Output Window
Dim output As OutputWindow = CType(window.Object, OutputWindow)
For Each pane As OutputWindowPane In output.OutputWindowPanes ' Browse panes
If (pane.Guid = "{2032B126-7C8D-48AD-8026-0E0348004FC0}") Then ' Build Order guid
pane.Activate()
End If
Next
window.Activate()
End Sub
You need to paste this code in MyMacros, EnvironmentEvents module.

Excel VBA - Is there a TextChanging / TextChanged or a similar event? Or how to move a selection without using Enter?

I have recently been asked if I could make a macro in Excel VBA that will allow a user to type in two numbers and have it automatically drop to the next row. The purpose of this is so they can type in grades for a test two numbers at a time without pressing enter since they aren't great at typing.
When I first heard this he mentioned it was Visual Basic, so I figured I'd just use a TextChanging or TextChanged event in the cell range and have it work off that. However, I haven't been able to find any such event or anything resembling it in the documentation thus far. The first thing that I came across was Workbook_Change, but that only changes after you press enter which is useless to me. Someone else mentioned there is such an event, but couldn't name it directly and I haven't been able to find what they were talking about.
If anyone has any information on if such an event exists or is possible I'd love to know.
The Excel version is 2007 as far as I'm aware.
This, in my opinion, requires a non-programming solution. I absolutely sympathize - it is tough to watch people get old - but you have to draw the line somewhere - for their sake and yours. The enter key is the most basic part of a computer. You could probably write a macro that would automatically hit enter on every even(or odd depending) keystroke in excel - but you're going to run into other problems like not being able to use delete normally. And what if you do want to put a string of text in a cell(like the student's name)? Perhaps it is time to find a non-programming solution. By that I mean someone should have a candid conversation with him about how he wants to solve the problem. Personally, I would offer to type the numbers in for him, as I am accustomed to the number pad - but it is probably better to be more direct and start to discuss retirement.
See this discussion about the limitations of cell edit mode in excel:
http://www.mrexcel.com/forum/excel-questions/524860-call-macro-every-keystroke.html
If you're really heart-set on a programming solution, I would recommend some kind of keystroke logging add-in.
Good Luck.
You could use the Worksheet_SelectionChange event. It is triggered without enter, but it would be triggered a lot.
You could however also create a special user-form for typing in the data, but this might be more work than necessary.
The main problem with using my suggested event is, you will need it as trigger and trigger it yourself, when selecting the next row, so disable event handling before changing the selection.
Edit:
This is a quick solution (paste this into the vba-code of the desired worksheet):
Private Const clngColumnRightToLastGrade = 5
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = clngColumnRightToLastGrade Then
Application.EnableEvents = False
'offset selection, one row down, two cols to left
Target.Offset(1, -2).Select
Application.EnableEvents = True
End If
End Sub
This will set you one row down and to column C, everytime your selection changes to column E (=5).
You don't have to use a constant of course, you could specify the column to sense in the workbook, so your user might modify it easier by himself.
To make this as an optional feature, you could extend it to autogenerated code. What I have in mind is like a Ribbon-Button, which opens a setupForm to configure, and a Ribbon-Button to activate the configuration, which would place this code in the configured sheet. But this might be a bit over the top.
In Excel 2003, (may be different in Excel2007 ?!) the WorkSheet_Change event is triggered every time the value of a cell is changed wether it is by pressing enter, delete, selecting an other cell after modifying a cell or even when a vba script changes the value of a cell.
I would do something like that:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RefRange As Range
Set RefRange = Intersect(ActiveSheet.Columns("??????????"), ActiveSheet.UsedRange)
If Not Intersect(Target, RefRange) Is Nothing Then
Target.Offset(0, 1).EntireColumn.Range("A1").Select
'Target.Offset(0, 1).EntireColumn.Range("A65536").End(xlUp).Offset(1,0).Select
End If
End Sub

Hidden Window Display on Users Desktop

We have a VB6 application that uses a non-visible window (form) for DDE communication.
We have some clients reporting that occasionally they can see this window on their desktop.
I did a scan through the code for any visible = true or show's on the form in question, but nothing.
This about all we do with it:
Load frmDDELink
frmDDELink.stuff = stuff
We don't actually explicitly display (or explicitly not display it either).
What could cause a hidden window to be displayed on a user's desktop such that it is visible?
Try and set the location of the form to off-screen.
frmDDELink.ClientLeft = -100
frmDDELink.ClientTop = -100
A misbehaving app on the client's machine could do that. FindWindow() is a notoriously inaccurate API function. On top of that, all VB6 windows have the same class name. Thunder something, iirc. It might be finding your window instead of the one intended, making the wrong window visible.
I like Black Frog's simple hint to set the location off-screen, and nobugz's possible explanation. I would also suggest handling the Form_Activate event and setting the form invisible again.
Private Sub Form_Activate()
'Log something for debugging purposes?'
Me.Visible = False
End Sub
try to set the border into none, or me.visible = false, and set the property not to display in the task bar.

Resources