VB run code on start of the application - vb6

I am a Java programmer and don't know much about VB.
My task:
Create an exe. When I run the exe it will read a text file, and after that it will display the content. After that the application code ends.
What i have done:
I have created a project and created a button on the form. On click of the button I have given the option to read.
Problem
I am not able to find the event which has to be used to run code on start up and code to end the application when my task completes.
Please help me with the process which I have to follow. If the code is provided, it's best, but if somebody knows any web resources it will also be a great help.

You can create a Visual Basic 6 program to run without any form.
You need to create a module. Put a Public Sub Main inside of it.
Then in under Project Properties, General Tab; change the startup object to be Sub Main.

To do something at form's start up, use Form_Load() event.
To close a form, use unload me.
To close your application, use end.
Hope this solves your problem. If not, you are welcome for further queries.

Related

Debug second console application triggered by first console app in same solution

I have two console application projects in a single solution and they are both configured to build to a common directory. The first app calls the second app via
Process proc = new Process();
proc.StartInfo.FileName = "myprocess.exe";
I can change my startup project and debug either one of them individually just fine, but I'm unable to step into the second project from the first project. When I look in build\debug I see the .pdb files for both apps and I know the second app is running completely through its routines. I just can't step into it. I've looked at Attach to Process and Debug:Location but haven't been able to find a solution yet. I've even tried putting them in different VS solutions, but to no avail.
So I need a way to step from the first project into the second project while debugging. Any suggestions would be appreciated.
Thank you.
You can use
Debugger.Launch();
which will bring up the dialog asking if you want to attach a debugger. You won't be able to 'step in' from the existing debugging session since it's attached to a different process.

FileOpenDialog from vbScript custom action appears behind main dialog

I'm creating an installer at work that must open a file browser. There is no file browser in wix, so I built a custom vbscript action that uses the Shell.BrowseForFolder method. It's working fine, but the file dialog shows up behind the main wix window. Does anyone know a wix/vbscript approach I could take to solve this problem?
Locate the HWND for the MSI UI and pass this into Shell.BrowseForFolder. I see a few example solutions that use FindWindow("MsiDialogCloseClass", vbNullString). Be careful about launching UI from a custom action: you need to consider silent installs/repair/uninstall, etc to make sure you get it right in all cases.
It looks like you're trying to allow the user to pick a directory. MSI has native support for this. I reccomend you use that. For an example see http://wix.codeplex.com/SourceControl/latest#src/ext/UIExtension/wixlib/BrowseDlg.wxs.

Open New Form on button click, Close exisiting Form, VS2010

Sorry for asking a really dumb question. I've been a vb6 programmer for years and I am just developing my first application in VS2010.
I'm trying to open a new form on a button click and close the current form.
In VB6 I would have used.
Me.Close
Form.Show vbmodal
I've googled for a solution and it tells me the code is basically the same
form.show()
me.close
However, when I click the button the program closes. If I take away me.close, the form shows.
I'm really confused.
Thanks
John
If the form that you are closing is the one that starts your application ('startup form'), then your application ends.
Try with
Me.Hide()
form.Show()
But you could also change the Property Shutdown mode for the project.
On the Applications Tab set the Shutdown mode to When the last form closes.
Of course, in this case, the order of the commands should be
form.Show()
Me.Close()
Try with Me.Hide() in place of Me.Close().
Dim f As New Form1
f.Show()
Checked!! as you see I declare f as new Form1, here you have to change with your form name under form properties then the next line is to show the copy of f!

How to get IVsBuildableProjectCfg to subscribe to build events?

I am trying to get an instance of the IVsBuildableProjectCfg object, but I have no clue how to get it.
I currently can get the DTE Project and/or the IVsHierarchy object representing each active project without a problem. How do you get an instance of IVsBuildableProjectCfg per project?
Ideally, I want to hook into the build event of each project to know whether or not each build is successful, as well as hooking into the solution to see if the overall build was fired.
(I also tried using the DTE2.BuildEvents, but my handler would never fire when I ran the debugger.)
Thanks!
Here's how you can get the active IVsBuildableProjectCfg for a given IVsHierarchy which I call ppHierarchy below:
IVsSolutionBuildManager buildManager = (IVsSolutionBuildManager)GetService(typeof(SVsSolutionBuildManager));
IVsProjectCfg[] ppIVsProjectCfg = new IVsProjectCfg[1];
buildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, ppHierarchy, ppIVsProjectCfg);
IVsBuildableProjectCfg ppIVsBuildableProjectCfg;
ppIVsProjectCfg[0].get_BuildableProjectCfg(out ppIVsBuildableProjectCfg);
Then you can subscribe to build events using:
uint pdwCookie;
ppIVsBuildableProjectCfg.AdviseBuildStatusCallback(new MyBuildStatusCallback(), out pdwCookie);
Where MyBuildStatusCallback is an object you create that implements IVsBuildStatusCallback.
I hope this helps!
You can do this with some macro programming:
Hit Alt-F11 (shortcut for the Macro editor, and we all know keyboard shortcuts are cool).
From Project Explorer, double click EnvironmentEvents.
From the left dropdown (where it says General), select BuildEvents:
4. From the right dropdown, select the event you're interested in (OnBuildDone for example).
5. A new Sub is added, place the code you'd like to run when a build is done.
6. Save, and close the Macro editor.
7. Build your project. The code you entered should execute once the build is done.
Hope this helps!

VB6 IE frame / WebBrowser causing NT.dll error

We have a legacy VB6 application which has worked just fine on Windows XP Professional SP 3 until just recently when we added an IE frame control so that we could display static local HTML files on a form. And, it works fine until I go to close the application. And, then it reports the following error message (consistently):
Faulting module ntdll.dll, version 5.1.2600.5755, stamp 49901d48
Here's the reference in the Visual Basic project file:
Object={EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0; ieframe.dll
And we use it by performing the following actions:
Development machine is running Win7 + Vb6 IDE.
Add a component reference to the "Microsoft Internet Controls" located at C:\Windows\SysWow64\ieframe.dll
Place a control on the form at design time.
Show that form modally by calling Form.Show vbModal The error happens when I use the default form instance frmMyForm.Show vbModal as well as when I use a local instance Dim MyForm as New frmMyFormMyForm.Show vbModal
Call WebBrowser.Navigate "staticPage.html"
When the user presses a button, the button click event returns the user choice and the form is disposed of.
Exit the application -- Here's where I get the error.
I've been looking all over the web, and haven't been able to find a whole lot of people still trying to use VB6 in this way. So, I'm wondering if someone might be able to help me on stackoverflow. Any help is much appreciated!
[Update] And, the plot thickens. I made a sample application with just that web component in order to make sure that it was causing the error. But, I didn’t experience the error when it closed like I was when exiting our existing/legacy vb6 application. I'll do a bit more investigating.
A follow up to this in case any runs into the same issue (the original poster and I were coworkers at the time)...
The application was using the VBCorLib library, and some of its string manipulation classes utilized direct memory access incorrectly. Read more at this VBCorLib forum post.
It turns out that the issue was that I was trying to delete the temporary file that the browser had loaded. It works now that I've moved that delete file code to the form unload event.

Resources