Solved How to make the code work on Form2 in vb.net

July 10, 2013 at 09:04:26
Specs: Windows 7
Form2.Show() displays form2 but it's code is not executed, so help would be very much appreciated to move control from Form1 to Form2

See More: How to make the code work on Form2 in vb.net

Report •

✔ Best Answer
July 23, 2013 at 22:31:11
Where are you putting this code that is supposed to execute?

If you put it in the form_load() event is should execute. Form2.show should then show the form and execute the code.

Or you could put it into a Public Sub in the form2 module and call it from Form1. You would then need a me.show command at the end of the code.

VB6 works very well on Windows 7, even 64 bit Windows 7,

Stuart



#1
July 10, 2013 at 09:33:29
What do you mean, "it's code is not executed?" The fact that something shows up means something is executing. How do you invoke Form2? What do you see? What do you expect to see?

How To Ask Questions The Smart Way


Report •

#2
July 10, 2013 at 09:54:12
many thanks for your interest. The form2 as designed is shown but the code I have written on vb.2 does not happen ie 'open and read a file and use that data for a label.text. ( nor is that data being sent to immediate window) Perhaps I should have asked 'how do I invoke Form2?'

Report •

#3
July 10, 2013 at 10:55:29
It should be pretty simple.
'Assumed: Form2 is a class.
Dim f = New Form2 'Assumed: Option Infer.
f.Show()
Does that not work? If not, you'll need to show us what's happening.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
July 11, 2013 at 08:22:42
f.show() does not get the application to move from form1 code to form2 code. What I can't see is the replacement of vb6 form1 ' form2.application=trans' and on form2 code ' property let application(trans as string)

Report •

#5
July 11, 2013 at 10:16:21
It's now 'Set'. http://msdn.microsoft.com/en-us/lib...

I'm not sure what you're seeing, and what you're expecting.

One of the bigger changes between VB6 and VB.NET is that forms are just like any other object, and must be instantiated before use. They're not some sort of global, static existence that they apparently were in VB6.

How To Ask Questions The Smart Way


Report •

#6
July 13, 2013 at 09:07:28
Sorry but I have been through all the 'set' this that and the other and this is not what I'm looking for. What I am looking for are the question marks below:-

form1 code
' button1_click etc
????
end sub'
on Form2 code
' ?????'
and so move the control of the project to Form2 and read the code that I have written.


Report •

#7
July 15, 2013 at 06:27:50
I'm not sure what you're doing wrong, and you're admittedly refusing to show us.
Dim f = New Form2 '<-- Form2's constructor runs
f.Show() '<-- Form2's OnShown runs

How To Ask Questions The Smart Way


Report •

#8
July 15, 2013 at 10:11:43
If I load 3 forms in vb1 and the code from vb2 & vb3 then I can get the programme to do what I want, but I have not used vb2 or vb3 code windows.
What I want to do is move from vb1 code to vb2 code then to vb3 and back again to vb2.
If form2.show() is what I need then the question comes up 'how do I get form2 to use the code in vb2'? What code do I need at the top of vb2 code window so that it is read and actioned?
I'm sorry you say 'I'm not showing you" ...... if I have 2 forms form1 with a button and form 2 with a label then button click with show() will show form 2 but the label will still show 'text' because vb2 code has not read 'open file' to gain text to put to the label.text.
I am having to change from VB6 because the new computer with Windows7 does not like VB6 programme ( any chance of having Commodore64 basic back again?)

Report •

#9
July 23, 2013 at 22:31:11
✔ Best Answer
Where are you putting this code that is supposed to execute?

If you put it in the form_load() event is should execute. Form2.show should then show the form and execute the code.

Or you could put it into a Public Sub in the form2 module and call it from Form1. You would then need a me.show command at the end of the code.

VB6 works very well on Windows 7, even 64 bit Windows 7,

Stuart


Report •

#10
July 24, 2013 at 09:48:28
Thanks Stuart- VB6 says there is 'incompatability with it and Windows7'. I think I'd prefer to stay with VB6 because VB.NET looks far too clever for the bits I write.

Report •

#11
July 24, 2013 at 10:28:46
I cant see where you are getting the incompatibly from, I have been using VB6 on Windows 7 64 bit for about two years now. The only problem I have had is with third part Active X controls but all the native Active x controls work well.

When Windows Vista was in its Beta stages, Microsoft changed Windows Vista to accommodate VB6 because there is such a wide user base. I imagine they did the same with Windows 7.

I agree though with your desire to stick with VB6. I never bothered much with VB.Net. It seems more complicated than it needs to be I can do everything I need to do with VB6 including some pretty complicated stuff with the Internet.

Stuart


Report •

#12
July 27, 2013 at 16:39:27
Unfortunately my Windows7 Home Edition won't let the VB6 load program run because of the compatibility problem, Microsoft web help doesn't talk about resolving the problem.

I have partitioned off half of my second hard drive thinking of loading XP there but that load disc does not want to load as Window7 is there so have got to find out how to direct it to where I want it and not on C: drive.


Report •

#13
July 27, 2013 at 17:44:19
Here is a tutorial on installing VB6 on Windows 7.

http://www.fortypoundhead.com/showc...

No One might be your problem. The UAC. You can turn it back on when VB is installed

Stuart


Report •

Ask Question