PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to change VB 2015 from public partial class form to public class form-VBForums
Results 1 to 6 of 6

Thread: How to change VB 2015 from public partial class form to public class form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    1

    How to change VB 2015 from public partial class form to public class form

    I am new to VB. For my computer science class we must create a simple form. However, when I try to edit the form it is in the public partial class format. It says

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApp6
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    }
    }

    However, I want to change it to a public class form as my instructions are using the public class format. Thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,451

    Re: How to change VB 2015 from public partial class form to public class form

    You are trying to solve a problem that doesn't exist. That 'partial' keyword simply means that code for the class can be split over multiple code files. Given that VS automatically uses two code files (one for designer-generated code and one for your own code) you require that 'partial' keyword or your form will simply stop working. Just go ahead and put your code within that class definition and everything will work as it should.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,451

    Re: How to change VB 2015 from public partial class form to public class form

    Hang on a minute! That's C# code that you've posted. What language are you supposed to be using? It would help if you knew that to begin with.

    Note that VB still uses partial classes but VB only requires that one part be declared with the 'Partial' keyword where C# requires all parts to use the 'partial' keyword.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,244

    Re: How to change VB 2015 from public partial class form to public class form

    Yeah, I was tempted to move the thread, but now that I think about it, the problem may really be that this is a C# project created when a VB project was desired. If that's the case, then the thread is in the right forum.
    My usual boring signature: Nothing

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: How to change VB 2015 from public partial class form to public class form

    If you're in a VB class, you're making C# projects so nothing you see in your textbook or class lectures is going to work. C# is a different language.

    Technically VB could have the partial keyword there, but the historic design philosophy of VB is to "reduce clutter" by doing as much as possible implicitly. So since the keyword is optional in most class definitions, VB doesn't use it. C# has a philosophy of "be explicit in everything you do" so even though the partial keyword is optional it uses it so you know it's there.

    This creates a sort of clash: many .NET features are designed with explicit philosophies in mind, but VB's cultural propensity towards implicit philosophies means you often find out you're using a feature a few hours after "not knowing the feature is there" creates the problem.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,451

    Re: How to change VB 2015 from public partial class form to public class form

    The rules for the use of the 'partial' (C#) and 'Partial' (VB) keywords are as follows:

    C#: It is an error to have multiple class declarations with the same name unless all declarations include the 'partial' keyword.

    VB: It is an error to have multiple class declarations with the same name unless at least one of them includes the 'Partial' keyword. It is a warning to have more than two class declarations with the same name if more than one of them does not include the 'Partial' keyword.

    Since 2005, which was when partial classes were introduced, VS has generated two code files for a Windows Form with one being for code generated by the designer and one being for user code. In the case of C#, the 'partial' keyword is required on all partial definitions so the definition in the user code file includes the 'partial' keyword, as you are seeing in the code you posted in post #1. In the case of VB, one class definition can omit the 'Partial' keyword without error or warning so you'll find that the definition in the user code file doesn't include the 'Partial' keyword while the one in the designer code file does include it. You could include it in both if you wanted to, but the IDE does not do so by default.

    Note that C# projects display the designer code file in the Solution Explorer by default, while VB projects do not. That's because designer code files should generally not be edited manually so VB tries to protect you from yourself. If you do want to see it or in the rare case where you need to edit it manually, you can see the designer code file in a VB project by clicking the 'Show All Files' button at the top of the Solution Explorer and expanding the node for your form. In VB 2017, the default designer code file looks like this:
    vb.net Code:
    1. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    2. Partial Class Form1
    3.     Inherits System.Windows.Forms.Form
    4.  
    5.     'Form overrides dispose to clean up the component list.
    6.     <System.Diagnostics.DebuggerNonUserCode()> _
    7.     Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    8.         Try
    9.             If disposing AndAlso components IsNot Nothing Then
    10.                 components.Dispose()
    11.             End If
    12.         Finally
    13.             MyBase.Dispose(disposing)
    14.         End Try
    15.     End Sub
    16.  
    17.     'Required by the Windows Form Designer
    18.     Private components As System.ComponentModel.IContainer
    19.  
    20.     'NOTE: The following procedure is required by the Windows Form Designer
    21.     'It can be modified using the Windows Form Designer.  
    22.     'Do not modify it using the code editor.
    23.     <System.Diagnostics.DebuggerStepThrough()> _
    24.     Private Sub InitializeComponent()
    25.         components = New System.ComponentModel.Container()
    26.         Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    27.         Me.Text = "Form1"
    28.     End Sub
    29.  
    30. End Class
    As you can see, the class is declared Partial.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width