Hi,
Instead of doing this....
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Form1
f.Show()
End Sub
End Class
I would like to make it generic by doing something like...
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Me
f.Show()
End Sub
End Class
.... but "Me" is not accepted, neither is "Dim f As New TypeOf(Me)".
I would like to put the CreateAndShow in a base form and then inherit from
it and still be able to use the CreateAndShow method.
Any suggestions? TANKS!!! :o)
M O J O 24 2836
That's a good idea, so I tried solving it as an exercise. The good
news is that it works.
The bad news is that I've been learning .NET for about a week, so I'm
rather embarassed to show you how I did it. But here goes:
Dim s1 As String = Me.ToString
' s1 is in the format "WindowsApplica tion1.Form1, Text: Form1"
' Now remove the part that isn't the class name.
Dim i1 As Integer = InStr(s1, ",")
If i1 0 Then s1 = Mid(s1, 1, i1 - 1)
' Note: Can't use Left(s1, i1-1) above - for some reason VB thinks
I'm trying to
' access Me.Left instead! <grrr>
Dim objNewForm As Object =
Activator.Creat eInstance(Type. GetType(s1))
Dim frm As Form = DirectCast(objN ewForm, Form)
frm.Show()
Ok, I worked on it some more, and this version is far less embarrasing!
Enjoy:
DirectCast(Acti vator.CreateIns tance(Type.GetT ype(Me.GetType. ToString)),
Form).Show() te******@hotmai l.com wrote:
If i1 0 Then s1 = Mid(s1, 1, i1 - 1)
' Note: Can't use Left(s1, i1-1) above - for some reason VB thinks
I'm trying to
' access Me.Left instead! <grrr>
You can use the line:
Imports VB = Microsoft.Visua lBasic
before your code so that you can use VB.Left(s1, i1-1). That tells it that
you want to use VB as an abbreviation for Microsoft.Visua lBasic.
Also, if you use Option Strict On, it will tell you when things don't match
up the way they should.
HTH
Andrew
Hi teslar91,
Thanks for helping me out here.
My problem is, that I can't use "Me", so your solution...
Public Shared Sub CreateAndShow()
Dim s1 As String = Me.ToString
' s1 is in the format "WindowsApplica tion1.Form1, Text: Form1"
' Now remove the part that isn't the class name.
Dim i1 As Integer = InStr(s1, ",")
If i1 0 Then s1 = Mid(s1, 1, i1 - 1)
' Note: Can't use Left(s1, i1-1) above - for some reason VB thinks'm
trying to
' access Me.Left instead! <grrr>
Dim objNewForm As Object = Activator.Creat eInstance(Type. GetType(s1))
Dim frm As Form = DirectCast(objN ewForm, Form)
frm.Show()
End Sub
.... gives me this error:
'Me' is valid only within an instance method.
I need to call the sub inside a shared sub, so I don't have an instance yet.
Any other suggestions? :o(
M O J O
"te******@hotma il.com" wrote:
Ok, I worked on it some more, and this version is far less embarrasing!
Enjoy:
DirectCast(Acti vator.CreateIns tance(Type.GetT ype(Me.GetType. ToString)),
Form).Show()
>
'Me' is valid only within an instance method.
I need to call the sub inside a shared sub, so I don't have an instance
yet.
Any other suggestions? :o(
M O J O
Static (shared) methods don't have a "Me". They are applicable to any
instance, hence cannot work on any specific instance. In this case you have
to pass in a "Me" as a parameter.
Mojo,
It is possible to create objects from classes. But never objects from
objects. (Although object is a class itself as well. To be more precise the
highest class from which every thing derives).
The startup form is a kind of strange thing in VB.Net (but handy) it has
inbuild a Sub main, where in it creates an object from itself. For the same
case you use a Module or Shared Class in which you can create your form
object. Than you can create as much objects from that class as you wish.
I hope this gives an idea.
Cor
"M O J O" <MO**@discussio ns.microsoft.co mschreef in bericht
news:88******** *************** ***********@mic rosoft.com...
Hi,
Instead of doing this....
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Form1
f.Show()
End Sub
End Class
I would like to make it generic by doing something like...
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Me
f.Show()
End Sub
End Class
... but "Me" is not accepted, neither is "Dim f As New TypeOf(Me)".
I would like to put the CreateAndShow in a base form and then inherit from
it and still be able to use the CreateAndShow method.
Any suggestions? TANKS!!! :o)
M O J O
Hello M O J O,
What's the point of this? If the goal is to not have to call .Show when
you create a form (lazy-ass).. then add Me.Show to the base form's ctor.
-Boo
Hi,
Instead of doing this....
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Form1
f.Show()
End Sub
End Class
I would like to make it generic by doing something like...
Public Class Form1
Public Shared Sub CreateAndShow()
Dim f As New Me
f.Show()
End Sub
End Class
... but "Me" is not accepted, neither is "Dim f As New TypeOf(Me)".
I would like to put the CreateAndShow in a base form and then inherit
from it and still be able to use the CreateAndShow method.
Any suggestions? TANKS!!! :o)
M O J O
M O J O wrote:
My problem is, that I can't use "Me", so your solution...
[...]
... gives me this error:
'Me' is valid only within an instance method.
I need to call the sub inside a shared sub, so I don't have an
instance yet.
Try this:
\\\
Dim myTypeName As String
Dim myObject As Object
'Get the name of the type of this class
myTypeName =
Reflection.Meth odBase.GetCurre ntMethod.Declar ingType.ToStrin g
'Create a new instance of this type
myObject = Activator.Creat eInstance(Type. GetType(myTypeN ame))
///
This can be used in a Shared method. It uses Reflection to get a handle to
the executing method, and from there to the type that contains that method
(i.e., your class). It then uses the Activator object to create a new
instance of an object of that type. Hopefully this will get you closer to
where you want to be?
--
(O)enone
-Boo,
Must you berate everyone?
"GhostInAK" <gh*******@gmai l.comwrote in message
news:be******** *************** ***@news.micros oft.com...
Hello M O J O,
What's the point of this? If the goal is to not have to call .Show when
you create a form (lazy-ass).. then add Me.Show to the base form's ctor.
-Boo
>Hi,
Instead of doing this....
Public Class Form1 Public Shared Sub CreateAndShow() Dim f As New Form1 f.Show() End Sub End Class I would like to make it generic by doing something like...
Public Class Form1 Public Shared Sub CreateAndShow() Dim f As New Me f.Show() End Sub End Class ... but "Me" is not accepted, neither is "Dim f As New TypeOf(Me)".
I would like to put the CreateAndShow in a base form and then inherit from it and still be able to use the CreateAndShow method.
Any suggestions? TANKS!!! :o)
M O J O This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Luis |
last post by:
the assignment is to count the number of words in a txt file here is my code
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
int main ()
{
|
by: RC |
last post by:
If I want to explicitly save the record before executing a Close
action. Which of the following should I use? Or does it depend on
whether it is based on a Form or something else?
If Me.Dirty Then
RunCommand acCmdSaveRecord
End If
DoCmd.Close
or
|
by: RzB |
last post by:
In a previous post in this NG (Oct 98)
http://makeashorterlink.com/?D505347FB
Henry Craven says that he was investigating a
relationship between the presence or absence of
a "Me!" prefix, the value of the Top propery of a
control, and the occurrence of an invalid runtime error
"The control or subform control is too large for this location"
|
by: TCORDON |
last post by:
Can someone give me a sample or point me in the direction of one, on how to
implement User "Remember Me" option when logging into a website?
TIA
|
by: Michael Fitzpatrick |
last post by:
I have a .NET application with an installer. The customer wants the install
page with the "Everyone" or "Just Me" selection to default to "Everyone".
Presently it defaults to "Just Me". Any hints on how I can achieve this?
--
: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: my email address zfarjf@pbqrvafvtug.com is encrypted with www.rot13.org
| |
by: acool |
last post by:
I just created a simple Windows Service in VB.NET. I right clicked on the
component and added the installer, installed via InstallUtil.exe all went
well until i try to do a net start and then I get:
"the service name is invalid" WHY??
|
by: Agnes |
last post by:
For my own practices.
I like to put "Me".
e.g IF Me.txtInvoice.textlength = 0 ....... etc
Me.txt.....etc
However, Is there any difference (without Me) ??
Thanks
|
by: ImageAnalyst |
last post by:
Yay!!! They fixed this for VS2005. You can now set the default
installation to be "Everyone" instead of "Just Me" and you can control
whether you even want those radio button installed in your Setup
program.
>From the Documentation
http://msdn2.microsoft.com/en-us/library/5f981xa1.aspx
===========================================================
"The InstallAllUsers property for a deployment project determines
whether an application is...
|
by: Ray |
last post by:
Hello,
Please help a VB newbie :) I'm a bit confused, reading all the
MyClass, Me, My keywords of VB. I think I get MyClass and My, but
Me... Can you just tell me if I get this correctly?
"Me" in VB (6, 7, 2005) is exactly like "this" in C# or C++. Its
meaning hasn't changed since VB 6. True or False?
Many thanks,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |