Solved

Really easy question about .frm file

Posted on 2004-10-05
24
470 Views
Last Modified: 2008-02-01
Hi all,
    This is a really stupid question. I have a .frm form (no other forms) and I need to get it to run. I am running VB6 and am not quite sure what to do. I tried creating a new project in an executable, etc., but the same problem exists. I create the project, right-click the form and say view code. I then paste the .frm code I have and for some reason, the following two lines turn red:

Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form LoadMyForm

All the lines that start with "Begin" are red. In addition, the first four lines actually say

VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form LoadMyForm
   Caption         =   "Form1"

but the version line changes to "VERSION5#". Am I placing this part into the wrong file? What do I do to correct this? The rest of the file seems to work after the variable Dim's are declared. In fact, the last red lines are as follows:

Attribute VB_Name = "LoadMyForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

What do I do to get it to run? Thanks and sorry about the stupidity.
           Sincerely,
                       JL
0
Comment
Question by:jl_forum
  • 10
  • 7
  • 4
  • +1
24 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12233918
To add a .frm file to your project, start VB.

GoTo Project->Add form_>[Existing]

Browse for the .frm on your project, then click OK

Then the form is added to your project.

To view the code, right click the form in the Project pane, then select "View Code"

That's it!

0
 
LVL 32

Expert Comment

by:Erick37
ID: 12233964
Let me clarify (it's late here)...

To add a .frm file to your project:

Start VB with a new project.  Form1 is created by default.

In the menubar select:   Project->Add Form->[Existing]

Browse for the .frm file on your computer, then click OK
(If the name of the form happens to be Form1.frm, then rename the already open Form1 to something else)

The form is then added to your project.

To view the code, right click the form in the Project pane, then select "View Code"

That's Better.
0
 

Author Comment

by:jl_forum
ID: 12234121
Hi Erick37,
    Actually, the problem isnt in viewing the code. I actually have the .frm file in a text file. One of the problems is that I dont know what the actual file is called. I assume that it is LoadMyForm.frm. The other problem is that a lot of the text is red (errors). When I try and compile it with just the .frm file, it says:
Compile error: Invalid outside procedure
on the VERSION 5.00 that got changed to VERSION 5#. The red text i the Object = and Begin lines as stated above. I have no problem viewing the code, I just need to know how to compile/execute it. Thanks.
             Sincerely,
                   JL
0
 

Author Comment

by:jl_forum
ID: 12234166
Heres an example... if I had the data from the webpage http://www.codeguru.com/vb/gen/vb_forms/listviewcontrols/article.php/c5947/ and wanted to compile it without downloading the zipfile at the bottom, how would I do it? I get the second and third lines in red, the "Begin" lines in red, and when I try and compile, it says Invalid Outside Procedure.
What I did was create a new project, add a form, and copy and paste the data. Then I try and compile. What am I doing wrong? Thanks.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 12234209
Ok.

Save the text file as testform.frm to a directory of your choice (the filename you choose is unimportant, just make the extension .frm).  Then follow the procedure above.

After you get the form in VB, you can set it as the startup form thru the menu:
Project->Project1 Properties->"Startup Object" then select the name of the new form.


A .frm file contains information about objects and controls your form is using, as well as menu structure, etc.  The body of the code is contained after this information.  If you cannot get the frm to load in a new project, then copy the code out of the .frm file.  The code is everything after the last "Attribute ="  statement.  If you do this, then you must manually place the correct controls back on the form.

Hope it helps!
0
 

Author Comment

by:jl_forum
ID: 12234268
Thanks Erick37. It doesn't work with the stuff before "Attribute =", so I need to recreate that stuff. Perhaps I'm asking a little too much, but how do I go around creating those items? Additionally, theres a declaration of stuff as ADODB.blahblah. Do I have to put in a reference? If so, which one? The MS ADO? Finally, for the form, there is a "Begin MSAdodcLib.Adodc". What is this referring to and how do I create it? Thanks much! I'm upping the points because I'm asking so much. =)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12234288
The example you pointed to at CodeGuru is actually 2 modules: one form and one class module.

This is the beginning of the class module file:
VERSION 1.0 CLASS
BEGIN


It's better to download the zipped project to a separate directory, then unzip.
http://www.codeguru.com/code/legacy/vb_forms/MBTLVI.zip

Double click on  Project1.vbp to open the entire project.

Good Luck!
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12234332
All the info is in the .frm file.

Paste the .frm here and we'll see how to open it.  If you do not want to paste the code, then paste the header (everything up to and including the last "Attribute = " line)

I'll check back tomorrow.
0
 

Author Comment

by:jl_forum
ID: 12234336
Hi Erick,
    The problem is that I am not using that example, thus I do not have a zip file or vbp. I just have the .frm that I have involved. Help! =)
                Sincerely,
                       Jon
0
 

Author Comment

by:jl_forum
ID: 12234982
Hi Erick, as requested:

VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form LoadMyForm
   Caption         =   "Form1"
   ClientHeight    =   9000
   ClientLeft      =   150
   ClientTop       =   300
   ClientWidth     =   10000
   LinkTopic       =   "Form1"
   ScaleHeight     =   10000
   ScaleWidth      =   12000
   StartUpPosition =   3  

   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Left            =   8000
      TabIndex        =   4
      Top             =   3500
      Width           =   1000
   End
   Begin VB.CommandButton Command2
      Caption         =   "Command2"
      Height          =   495
      Left            =   7000
      TabIndex        =   6
      Top             =   6000
      Width           =   1000
   End
   Begin VB.CommandButton Command3
      Caption         =   "Command3"
      Height          =   495
      Left            =   6000
      TabIndex        =   4
      Top             =   1000
      Width           =   1000
   End
   Begin VB.CommandButton cmdEat
      Caption         =   "&Eat"
      Height          =   495
      Left            =   400
      TabIndex        =   0
      Top             =   120
      Width           =   1200
   End
   Begin VB.CommandButton cmdSit
      Caption         =   "&Sit"
      Height          =   495
      Left            =   750
      TabIndex        =   0
      Top             =   120
      Width           =   1200
   End
   Begin VB.CommandButton cmdMonster
      Caption         =   "&Monster"
      Height          =   495
      Left            =   3000
      TabIndex        =   3
      Top             =   100
      Width           =   1200
   End
   Begin MSAdodcLib.Adodc Adodc1
      Height          =   495
      Left            =   7500
      Top             =   120
      Width           =   3000
      _ExtentX        =   5000
      _ExtentY        =   1000
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   3
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "DSN=MonsterDSN"
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   "MonsterDSN"
      OtherAttributes =   ""
      UserName        =   "Monster"
      Password        =   "Monster"
      RecordSource    =   "JAR_WALL"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSAdodcLib.Adodc Adodc2
      Height          =   855
      Left            =   9000
      Top             =   4000
      Width           =   1500
      _ExtentX        =   2500
      _ExtentY        =   1500
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=mango"

      OLEDBString     =   "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=mango"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc2"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.TextBox Text1
      Height          =   975
      Left            =   0
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   600
      Width           =   7000
   End

   Begin VB.PictureBox Picture1
      AutoRedraw      =   -1  'True
      Height          =   9000
      Left            =   0
      ScaleHeight     =   9000
      ScaleWidth      =   7000
      TabIndex        =   1
      Top             =   1800
      Width           =   7000
   End
   Begin VB.OLE OLE1
      Height          =   1000
      Left            =   4200
      TabIndex        =   5
      Top             =   4800
      Width           =   3000
   End
End
Attribute VB_Name = "LoadMyForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Please help if possible. Thanks.
              Sincerely,
                      JL
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12236617
If that is the ENTIRE contents of the .frm file, then what you have contains NO CODE whatsoever, just the definitions of the various controls (Buttons, Picture Box, ADO Data Controls) that have been drawn on the form.  This will be of little or no use to you without the associated code that makes the application work.

AW
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12236638
for example, here is a SIMILAR listing of the contents of a .frm file that I have used in a Demo program:

VERSION 5.00
Begin VB.Form frmEditPerson
   Caption         =   "Edit Person"
   ClientHeight    =   2595
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4440
   LinkTopic       =   "Form1"
   ScaleHeight     =   2595
   ScaleWidth      =   4440
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdApply
      Caption         =   "Apply"
      Enabled         =   0   'False
      Height          =   390
      Left            =   3360
      TabIndex        =   10
      Top             =   2160
      Width           =   975
   End
   Begin VB.CommandButton cmdCancel
      Caption         =   "Cancel"
      Height          =   390
      Left            =   2160
      TabIndex        =   9
      Top             =   2160
      Width           =   975
   End
   Begin VB.CommandButton cmdOK
      Caption         =   "OK"
      Enabled         =   0   'False
      Height          =   390
      Left            =   960
      TabIndex        =   8
      Top             =   2160
      Width           =   975
   End
   Begin VB.TextBox txtBirthDate
      Height          =   330
      Left            =   960
      TabIndex        =   4
      Top             =   1185
      Width           =   1815
   End
   Begin VB.TextBox txtName
      Height          =   330
      Left            =   960
      TabIndex        =   2
      Top             =   615
      Width           =   3375
   End
   Begin VB.TextBox txtSSN
      Height          =   330
      Left            =   960
      TabIndex        =   0
      Top             =   105
      Width           =   1815
   End
   Begin VB.Label Label4
      Caption         =   "Age"
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   1755
      Width           =   735
   End
   Begin VB.Label lblAge
      BorderStyle     =   1  'Fixed Single
      Height          =   330
      Left            =   960
      TabIndex        =   6
      Top             =   1680
      Width           =   975
   End
   Begin VB.Label Label3
      Caption         =   "Birthdate"
      Height          =   255
      Left            =   120
      TabIndex        =   5
      Top             =   1245
      Width           =   735
   End
   Begin VB.Label Label2
      Caption         =   "Name"
      Height          =   255
      Left            =   120
      TabIndex        =   3
      Top             =   690
      Width           =   735
   End
   Begin VB.Label Label1
      Caption         =   "SSN"
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   180
      Width           =   855
   End
End
Attribute VB_Name = "frmEditPerson"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents mobjPerson As Person
Attribute mobjPerson.VB_VarHelpID = -1

Private Sub cmdApply_Click()

  ' save the object
  mobjPerson.ApplyEdit
  mobjPerson.BeginEdit

End Sub

Private Sub cmdCancel_Click()

  ' do not save the object
  mobjPerson.CancelEdit
  Unload Me
 
End Sub

Private Sub cmdOK_Click()

  ' save the object
  mobjPerson.ApplyEdit
  Unload Me

End Sub

Private Sub Form_Load()

  Set mobjPerson = New Person
  EnableOK mobjPerson.IsValid
  mobjPerson.BeginEdit
 
End Sub

Private Sub mobjPerson_NewAge()

  lblAge = mobjPerson.Age

End Sub

Private Sub txtBirthdate_Change()

  If IsDate(txtBirthDate) Then mobjPerson.Birthdate = txtBirthDate

End Sub

Private Sub txtName_Change()

  mobjPerson.Name = txtName

End Sub

Notice that AFTER the block that reads


Attribute VB_Name = "frmEditPerson"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

is a Block that contains the code that makes the Form behave as it was designed to.  Without that code, the form is FUNCTIONLESS.

AW
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 32

Expert Comment

by:Erick37
ID: 12237460
Hi JL,

I just copied your code into Notepad and then saved it to disc as Form1.frm.

I opened VB and started a new project.  I was able to add this form to the project and open it without error.  This means that all of the controls added at design time are valid.

What errors were you getting?
0
 
LVL 3

Assisted Solution

by:aParser
aParser earned 50 total points
ID: 12238891
JL,

I'm not sure if you've figured this out, but VB source code files are made up of two things: the programmer's code (that the VB IDE shows you) and extra code that VB uses behind the scenes.  VB *hides* this from you in the IDE.  If you try to copy-and-paste the part of a form that VB tries to hide from you -- like "VERSION 5.00" or "Attribute VB_Creatable = False" --  you'll confuse VB.

With regards to your question about the code on CodeGuru:

As Erick37 said, the code on that page is actually two files.  You could do this:

Open two copies of Notepad.

In the first copy of Notepad, copy and paste everything between "VERSION 5.00" and the "End Sub" right before "VERSION 1.0 CLASS".

Save that file as "Form1.frm".  (Be sure to override Notepad to "Save as type: All files" so that it won't save your file as Form1.frm.txt)

In the second copy of Notepad, copy and paste everything from "VERSION 1.0 CLASS" through the last "End Property".

Save that file as "CTooltip.cls".

Close both copies of Notepad.

Then, create a project, delete the default form that VB6 creates for you in the project, and add these two files (one as a Form, the other as a Class, obviously).  (You'll also have to go into the project properties and set the Start Up location to be your new form.)  I'm guessing that you don't really want to use this particular project, so I'm not going to go into a step-by-step process for how to do this with this particular pair of files.

And a couple of other detail questions:

If you do this right, the form already contains the References it needs.  You shouldn't have to add anything.

The "MSAdodcLib.Adodc" is the CLASSID for the "Microsoft ADO Data Control 6.0", which you see referenced at the top of your form with:
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"

I'm assuming that you're going to all of this trouble because you can't download the code.
0
 

Author Comment

by:jl_forum
ID: 12239344
Hi guys, thanks for your comments. I totally appreciate all  your help on this.

Arthur: Actually, I did not paste the entire code, just the form controls. The form controls are the only part I am really having an issue with though. It keeps giving me errors when I try and compile it. The form controls don't appear in the design aspect of it either.

Erick: You got it to work? Did you paste it all into one big .frm file? I did it as one big .frm file and like I said before, the "Version 5.00" becomes "Version 5#" and
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form LoadMyForm
becomes highlighted in red. All the "Begin" lines are in red as well. Perhaps you are doing it differently than me? Do you actually see form controls appear? I'm sorry that I am not understanding this well.

aParser: I am going through this trouble because I only have the form file and wish to compile this. My code is similar to that of which Arthur put up. The .frm is divided into two sections similar to what his is. All that is supposed to be within the same .frm file correct? There is no classes in my file. Rather, it is like Arthurs. The format is as follows:

{what I pasted above}
Option Explicit
Dim...
Dim...
.
.
.
Private Sub()
End Sub
Private Sub()
End Sub
.
.
.
Like I stated before, the lines become red and when I try and compile it, I get the "Compile error: Invalid outside procedure"
error.

Sorry guys, I guess I'm really stupid about this or not understanding what you mean. I am trying to specify it as much as possible. I appreciate all your help. Please dont give up on me! =)
                 Sincerely,
                       JL
0
 
LVL 3

Expert Comment

by:aParser
ID: 12239622
What we're saying is that you can't create a form in the VB IDE and paste in the stuff above "Option Explicit".

It's not entirely clear to me if you have all of this stuff in a file on your system or if you're getting it from somewhere else like the CodeGuru site.

If it's from somewhere else, paste everything into a Notepad document and save it with a .FRM extension, then start VB6 and add the file to your project.

If it's already on your system, make sure the file has a .FRM extension and then just add the file to the project.  (Erick37's second comment explains how to add a file to a project.)

Again, you can't paste everything you've shown into a form when it's open in the IDE.
0
 

Author Comment

by:jl_forum
ID: 12239710
Hmm... I believe I tried that yesterday. In other words, just save my entire contents into a .frm file, create a new project, and add an existing form, correct? If so, I still get the red lines as stated previously and it doesn't want to compile. Is there something else I need to add (reference or something)? When I add the form as an existing form, the design view is still empty. I don't see any buttons or anything. Thanks again for your help!
0
 
LVL 3

Expert Comment

by:aParser
ID: 12241278
What you describe sounds correct.  I'm surprised that you're still able to see things like "VERSION 5.00" and "Attribute VB_Exposed = False" ... but then again, I suppose you are, too, and that's the point. :)

As far as references go, you might try adding the "Microsoft ADO Data Control 6.0" under Components before adding the .FRM.

I'm trying to think of reasons why the VB IDE might still be unhappy with the file, but I'm starting to grasp at straws.  There could be some strange line breaks in the file.  It could be some kind of versioning issue; you might try downloading the latest service pack for VB.  It could be that the controls on the form aren't registered in your system -- but the only "non-standard" control appears to be the ADO Data Control.  You can search your registry for the GUID you pasted: {67397AA1-7FB1-11D0-B148-00A0C922E820} .  If it's missing, make sure that the MSADODC.OCX is on your system and register it.  I don't know if the latest MDAC would have any affect on that control.  I was also worried that there might be something in a .FRX, but I don't see anything.

The strangest thing is that Erick37 did the exact same thing and got no error. ... And now I've tried it and gotten it to work.  And the project automatically added the reference to the ADO Data Control to the project when I added the form.

Check whether the OCX is on your system and registered.  If it is, I'm stumped.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12241302
Close Visual Basic.

Open Nopepad or any TEXT editor.

Paste the code in the text file (in Notepad), then save the file as filename "MyForm.frm"

Close Notepad.

Open VB, then add the FILE to the project, using the first instructions from yesterday.

(Do not paste the code in the code window while in the VB editor - that will not work!)
0
 

Author Comment

by:jl_forum
ID: 12241752
Hmm... good point aParser. I'm actually on a different computer but I will try it when I get back and report on what's up. Erick, thats exactly what I did. Again, those errors appeared and all that described above. Hopefully it is what aParser pointed out? I dont understand why the "Begin" lines would be red as well though... any ideas? Thanks guys, I really like this forum and am glad there are people like you all so dedicated to helping others! =) Much obliged!
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 25 total points
ID: 12242209
The .frm file contains the instructions that the IDE interprets to build the Form.  You must let the IDE read the .frm file, do its processing, then you will see the form, and then you can edit the code, and execute the program.  You do NOT cut and paste the contents of the .frm file (as seen in Notepad) into the VB IDE. It doesn't work like that.

AW
0
 

Author Comment

by:jl_forum
ID: 12250696
Hey guys, it seemed to work! Thanks! The problem was that the OCX file wasn't existent and registered. I guess I hadn't done the correct thing with pasting it into an .frm outside the IDE as well (I swear I did), but I got everything good and going! Thanks!! =) Now my other question to you all is how do I split points amongst you all? You all helped so much. Thanks all for helping a newbie!
                 JL
0
 
LVL 3

Expert Comment

by:aParser
ID: 12251116
0
 

Author Comment

by:jl_forum
ID: 12253307
Thanks all! =)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now