Hi, I am trying to use the "My" functions in Visual basic, but every time i run the code, it give me a Runtime error 424 - object required.
I am a newbie at this, please help.
I don't have anything else in the code, just New Project, Stantard EXE project, then in the Form1, i have this code

Private Sub Form_Load()
MsgBox ("Computer name: " & My.Computer.Name)
End Sub

When i run, it give me the error, I think i have to do something first before i use the My.Computer.Name, but i don't know what, i tried search MSDN but can't find the steps on how to use it. Thanks for the help.

Recommended Answers

All 4 Replies

What is "My" ? As far as I know there is no in-built VB object called "My". If you are trying to use an object you created then you have to include the reference to that object.
For example If you have created an object called myObject which has a property called ComputerName then the code should be like

Dim my as new myObject
Msgbox my.ComputerName

I think what you may be referring to is actually called "Me". "Me", like "this" in C++, is a reference to the object for which you are creating code. You are placing code in a form object, so "Me" is a reference to that form. Forms contain methods and procedures which can be accessed by Me.methodName() or Me.propertyName. This is redundant, however, because "Me" is assumed. Furthermore, "Computer" is not one of the properties or methods contained in a Form. If you are just starting out, I'd suggest finding a tutorial web site or buy a book.

I found out what the problem is, the "My" function is only supported in the .net versions, not vb6 and below. Thanks for the help guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.