+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 12

Thread: Creating a Class in Visual Studios.Net (Visual Basic Section)

  1. #1
    Newbie dream is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    18

    Creating a Class in Visual Studios.Net (Visual Basic Section)

    Hello, I am new to using Visual Studios.Net. I am trying to write a class using Visual Studios.Net in the Visual Basic section. Could someone tell me what I am doing wrong?

    Module Module1

    Public Class MyClassName

    End Class
    Sub New()
    Dim intVariable As Integer
    intVariable = 0

    End Sub
    Property Variable() As Integer
    Get
    Return Variable

    End Get
    Set(ByVal Value As Integer)
    Variable = Value
    End Set
    End Property
    MyClassName End Class
    REM I don't really know if End MyClassName should be at the end.
    REM book has End Class at the end.
    REM But the programs still manages to run I think.
    End Module

  2. #2
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    The End Class should not be at the top, but at the bottom with the REM statements. Incidentally, you can now use the ' character instead of REM to comment.

    In VS using a module to write a class is a pointless way, when you can actually add your own class directly. To do this, go to Add New Item and choose Class. Give it a name, and accept. It should load up with code already set up. Simply add the methods to populate the class.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  3. #3
    Newbie dream is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    18

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    Thanks for the help.

  4. #4
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    Is it working now?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  5. #5
    Newbie dream is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    18

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    Yeah it is ok now. I am having problems activating my direct x controller though. I am reading a book called Gaming Programming for Teens. I believe that the author left out many important details about visual basic.

  6. #6
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    Oh - maybe it's more of a book for advanced VB users. Is your computer powerful enough for Direct X?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  7. #7
    Newbie dream is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    18

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    Yeah it should be. I just installed a graphics card geforce 7200 series. I past the test to see if it is obsolete. But since I am new to VB I don't really know who to initialize a device yet for direct X. Mainly I am just trying to write some code to form a window and changes its color to blue. I believe it has something to do with the adapters of the device or something of that nature.

  8. #8
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    You shouldn't need DirectX just to display a form! Use a simple Form object, and change its BackColor to Color.Blue, like so:
    Code:
    Dim f As New Form()
    f.BackColor = Color.Blue
    f.Show()
    You can change any extra properties of the 'f' object before showing it, to make it look just the way you want it to.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  9. #9
    Newbie dream is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    18

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    Quote Originally Posted by Xav View Post
    You shouldn't need DirectX just to display a form! Use a simple Form object, and change its BackColor to Color.Blue, like so:
    Code:
    Dim f As New Form()
    f.BackColor = Color.Blue
    f.Show()
    You can change any extra properties of the 'f' object before showing it, to make it look just the way you want it to.
    It is that simple? Here is the command line that I am having problems with below:

    REM Create the Direct3D device
    device = New Direct3D.Device(adapterNumber, Direct3D.DeviceType.Hardware, Me, flags, params)


    Here is the program below:

    Imports Microsoft.DirectX

    Public Class Form1
    Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 266)
    Me.Name = "Form1"
    Me.Text = "Form1"

    End Sub

    #End Region
    Dim device As Microsoft.DirectX.Direct3D.Device

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Size = New Size(800, 600)
    Me.Text = "DirectX Initialization Demo"
    Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
    REM the above statements resize the window of the form

    REM set up the presentation parameters
    Dim params As New Direct3D.PresentParameters
    params.Windowed = True
    params.SwapEffect = Direct3D.SwapEffect.Discard
    params.AutoDepthStencilFormat = Direct3D.DepthFormat.D16
    params.EnableAutoDepthStencil = True
    params.BackBufferCount = 1
    params.BackBufferCount = 800
    params.BackBufferCount = 600

    REM Check video card capabilities
    Dim adapterNumber As Integer = Direct3D.Manager.Adapters.Default.Adapter
    Dim flags As Direct3D.CreateFlags
    flags = Direct3D.CreateFlags.HardwareVertexProcessing
    flags += Direct3D.CreateFlags.PureDevice

    Dim caps As Direct3D.Caps
    caps = Direct3D.Manager.GetDeviceCaps(adapterNumber, Direct3D.DeviceType.Hardware)
    If caps.DeviceCaps.SupportsHardwareTransformAndLight = False Or caps.DeviceCaps.SupportsPureDevice = False Then

    MessageBox.Show("Your video card is obsolete.", "Hardware Problem")
    End

    End If

    REM Create the Direct3D device
    device = New Direct3D.Device(adapterNumber, Direct3D.DeviceType.Hardware, Me, flags, params)

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    device.Clear(Direct3D.ClearFlags.Target + Direct3D.ClearFlags.ZBuffer, Color.Blue, 1.0, 0)
    device.BeginScene()
    device.EndScene()
    device.Present()
    Me.Invalidate()
    End Sub
    End Class

    It is suppose to bring up a window and make the window blue.

  10. #10
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creating a Class in Visual Studios.Net (Visual Basic Section)

    BLIMEY! Oh, I see. I have just remembered you are writing games. Just displaying a blue window is easy using the standard .NET functions, but once you start writing complex games, there will be a point where this long code will overtake the normal .NET ones in terms of usability.

    You see, the usual .NET framework is not designed to write games. This code might seem like a lot, but the more you try to draw to the screen, the easier it will seem.

    If you want to use the standard .NET commands, you can install the XNA Game Library. This provides an extra set of tools for writing games, but your DirectX thingy looks fine, and I advise you to stick with the code it gives you - my example could not in a million years write a game!

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Tutorial: Starting C# with C# 2008 Express Edition
    By Jordan in forum CSharp Tutorials
    Replies: 20
    Last Post: 07-27-2009, 04:45 AM
  2. Visual Studio 2008: C# Hello World Tutorial
    By Jordan in forum CSharp Tutorials
    Replies: 27
    Last Post: 07-23-2009, 04:32 PM
  3. PHP 5 and OOP
    By Jordan in forum PHP Tutorials
    Replies: 11
    Last Post: 09-22-2008, 01:58 AM
  4. Creating an image viewer in Visual Basic
    By blueparukia in forum Visual Basic Programming
    Replies: 4
    Last Post: 09-10-2007, 02:00 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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