Why doesn't this work?

Public Class testDates
    Inherits Object
    Private mMonth As Integer
    Private mDay As Integer
    Private mYear As Integer

    'constructor 
    Public Sub New(ByVal monthValue As Integer, ByVal dayValue As Integer, _
    ByVal yearValue As Integer)
        mMonth = monthValue
        mDay = dayValue
        mYear = yearValue
    End Sub

    Public Function ToStandardString() As String
        Return mMonth & "/" & mDay & "/" & mYear
    End Function

    Public Function ToMMMMString() As String
        Dim newString As String
        newString = mMonth
        Format(newString, "mmmm")
        Return newString
    End Function

    Public Function ToMMMMDDYYYYString() As String
        Dim anotherString As String
        anotherString = mMonth & mDay & mYear
        Format(anotherString, "mmmm dd, yyyy")
        Return anotherString
    End Function
End Class


Imports System.Windows.Forms
Module Module1

    Sub Main()
        Dim myDate As New testDates(2, 1, 1961)
        Dim output As String
        Dim output1 As String

        Console.WriteLine(myDate.ToStandardString())
        Console.WriteLine(myDate.ToMMMMString())
        Console.WriteLine(myDate.ToMMMMDDYYYYString())
        
    End Sub

End Module

what exactly is it suppose to do?

I_Byte, still struggling with this eh? Dates and Times can always be so much fun...NOT!

Here is what I would have done, as I modified your code to have it make more sense then me trying to explain in words.

Imports System

Public Class testDates
    Inherits Object
    Private mDate As DateTime

    'constructor
    Public Sub New(ByVal strDate As String)
        mDate = Convert.ToDateTime(strDate)
    End Sub

    Public Function ToStandardString() As String
        ToStandardString = Format(mDate, "MM/dd/yy")
    End Function

    Public Function ToMMMMString() As String
        ToMMMMString = Format(mDate, "MMMM")
    End Function

    Public Function ToMMMMDDYYYYString() As String
        ToMMMMDDYYYYString = Format(mDate, "MMMM dd, yyyy")
    End Function
End Class



Module Module1

    Sub Main()
        Dim myDate As New testDates("2, 1, 1961")

        Console.WriteLine(myDate.ToStandardString())
        Console.WriteLine(myDate.ToMMMMString())
        Console.WriteLine(myDate.ToMMMMDDYYYYString())

    End Sub

End Module

Hope that helps.

P.S. By the way, why did you import the System.Windows.Forms Namespace, when you don't seem to need it?

I am still confused about when I should import objects and when I shouldn't. I actually got that date thing figured out, but I didn't do it as you suggested, Paladine. I am going to run it the way you wrote it to see the difference between both. After I got the dates figured out, I actually got to use it at work. It was exciting to see it work correctly.

You have been great with your advice and help. I give you an A+. ;)

Hey thanks I_Byte :D


Well what is it exactly that confuses you about importing objects? If you mean in the case of importing the system.windows.forms namespace, it is just not needed unless you are using a form. In the case you gave I assume it was just a console application (i.e. ms-dos prompt) from the code provided.


I suggest using MSDN to check out the class/namespace listings under .NET Frameworkd SDK. Or better yet, just check the SDK Documentation included in the .NET Framework Install.

That is what I love about this site. We all can learn as we learn from one another.

Okay, I understand that, but what if I want to use a messagebox.show? Do I need to import something then? :?:

Paladine, have you worked much with VBA in Word? Let me give you this example and see if you can figure this out for me.

I have a document that needs to be filled out. To help the user input all the correct information that goes on the form, I built a user form. On enter the information gets transferred to the form. To accomplish this I use this statement:

ActiveDocument.Bookmarks("NAME").range.InsertBefore txtName
ActiveDocument.Bookmarks("ADDRESS").range.InsertBefore txtAddress

This works great because I have separate bookmarks for Name and Address. But what if I just have one bookmarks called "DATA":

ActiveDocument.Bookmarks("DATA").range.InsertBefore txtNetWeight _
& vbTab & txtCostPerLbs & vbCrLf

After this gets put on the document, I ask the users if he needs to input data again. If he clicks on Yes, then:

ActiveDocument.Bookmarks("DATA").range.InsertBefore txtNetWeight _
& vbTab & txtCostPerLbs & vbCrLf

BUT, here's the problem. I need the second set of data to be inserted below the first line that is already on the document. What happens instead is that it gets inserted above the line that is already on the document.

Any ideas? :roll:

I_byte: I have not worked with VBA in word very much, but you are the second person to ask me to figure something out in it. I love a challenge, so I will get back too you....

As far as

Messagebox.Show()

does requre Import System.Windows.Form

Hope that helps.

Opps, that is

Import System.Windows.Forms

my bad!

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.