12 Replies - 400 Views - Last Post: 27 November 2012 - 05:19 PM Rate Topic: -----

#1 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Declaring a new sub problem

Posted 26 November 2012 - 05:54 PM

I have a new public sub I have declared and it showing the following error that I don't understand? I know it has to do with declaring it in a class but I'm not sure where or how...I'm sometimes a very slow learner, but it sticks for a lifetime once I have learned...Please help.

The error reads: Public Sub New([h As Integer = 12], [Optional ByVal m As Integer = 0], [Optional ByVal s As Integer = 0]in designer generated type Time' should call InitializeComponent method.

Help me with the code, but more so help me to let it sink in "InitializeComponent method".

Public Class Time


    'declare integer instance variables for the hour, minute and second
    Private hourValue As Integer         ' 0-23
    Private minuteValue As Integer      ' 0-59
    Private secondValue As Integer      '0-59
    Private WithEvents incrementMinuteButton As Button


    'Sub New(ByVal h, ByVal m, ByVal s As String)

    'Time constuctor with hour, minute and second as optional parameters
    Public Sub New(Optional ByVal h As Integer = 12, Optional ByVal m As Integer = 0, Optional ByVal s As Integer = 0)

        SetTime(h, m, s)                'call SetTime with three arguments


    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Declaring a new sub problem

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,012
  • Joined: 02-July 08

Re: Declaring a new sub problem

Posted 26 November 2012 - 07:41 PM

On the first line inside Sub New put InitializeComponent.
Was This Post Helpful? 1
  • +
  • -

#3 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: Declaring a new sub problem

Posted 26 November 2012 - 08:01 PM

I'msorry?



'Public Sub(ByVal h, ByVal m, ByVal s As String)
    'Dim cls1 As New Class1
    'Time constuctor with hour, minute and second as optional parameters
    
       Public Sub New(InitializeComponent As Optional ByVal h As Integer = 12, Optional ByVal m As Integer = 0,         Optional ByVal s As Integer = 0)

        SetTime(h, m, s)                'call SetTime with three arguments


    End Sub

    ' Time constructor: another Time object supplied
    Public Sub New(ByVal t As Time)

        SetTime(t.hourValue, t.minuteValue, t.secondValue)

    End Sub   'New

    ' set a new time value using universal time, check validity of the data
    Public Sub SetTime(ByVal h As Integer, ByVal m As Integer, ByVal s As Integer)

        Hour = h                    ' Set accessor validates the hour
        Minute = m                  ' Set accessor validates the minute
        Second = s                  ' Set accessor validates the second

    End Sub   'Set Time

Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Declaring a new sub problem

Posted 26 November 2012 - 08:47 PM

Nono! That's not inside Sub New(), that is where the parameters go.

    Public Sub New(Optional ByVal h As Integer = 12, Optional ByVal m As Integer = 0, Optional ByVal s As Integer = 0)
         InitializeComponent()	 
	 SetTime(h, m, s)                'call SetTime with three arguments
    End Sub


This post has been edited by lar3ry: 26 November 2012 - 08:47 PM

Was This Post Helpful? 1
  • +
  • -

#5 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: Declaring a new sub problem

Posted 26 November 2012 - 09:31 PM

99% there! Thank you very much! I have learned new psychology in my job...There are 60% visual learners, 30% auditory and 10% kinesthetic... I am so visual and I thank you so much

The last solution I need is and why or what to do different the next time:
a blue line under time.ToUniversalTimeString and it says:
'Time is a type and cannot be used as an expression
generate Time class or generate new type?

ToUniversalTimeString is not a member or 'Time

generate property stub
generate method stub
generate field


    Private Sub UpdateDisplay()
        'Public Sub New(ByVal ticks As Long, ByVal kind As DateTimeKind)


        setHourTextBox.Text = Convert.ToString(time.Hour)
        setMinuteTextBox.Text = Convert.ToString(time.Minute)
        setSecondTextBox.Text = Convert.ToString(time.Second)
        output1Label.Text = ("Hour: " & time.Hour & "; Minute: " &
        time.Minute & "; Second: " & time.Second)
        output2Label.Text = ("Standard time is: " & time.ToString() &
        "; Universal Time is: " & time.ToUniversalTimeString)

    End Sub ' UpdateDisplay 




This post has been edited by charyl: 26 November 2012 - 09:51 PM

Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Declaring a new sub problem

Posted 26 November 2012 - 09:53 PM

Since time is a type, it's not a good idea to name a variable as "time". I really don't know if you did that or not, because I can't see your declarations in the code you posted.

This post has been edited by lar3ry: 26 November 2012 - 09:54 PM

Was This Post Helpful? 1
  • +
  • -

#7 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: Declaring a new sub problem

Posted 26 November 2012 - 10:02 PM

I hit something and it was a different screen, new statement; argument (please correct me) what it says is; 'ToUniversalTimeString' is not a member of 'Time.
Was This Post Helpful? 0
  • +
  • -

#8 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Declaring a new sub problem

Posted 26 November 2012 - 10:24 PM

View Postcharyl, on 26 November 2012 - 11:02 PM, said:

I hit something and it was a different screen, new statement; argument (please correct me) what it says is; 'ToUniversalTimeString' is not a member of 'Time.

Right. It's not... What you wanted to say was probably time.ToUniversalTime.ToString
When in doubt, watch the little choice boxes as you type, they will show you what's available, and usually, when you don't have any choices shown, it means you are not at the right place in the hierarchy to use what you started to type.

As an example, try adding an item to a ListBox called lst1, by typing lst1.add("Hello"), when you get to lst1.ad, you suddenly have no choices, so you can backspace and check your choices. You can single-click on choices to see what they do, and you will soon see that lst1.Items.Add("Hello") is the right way.
Was This Post Helpful? 1
  • +
  • -

#9 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: Declaring a new sub problem

Posted 26 November 2012 - 10:57 PM

That's very good reiteration on coding! And it's always good to refer to this!
But something is not sinking in; I don't know what line of code to add to make the line go away under time.ToUniversalTime.ToString

but once you add the line of code my question would be why, and why did it make it work or what made it work?...how do I ask the proper question in vb language





    ' update time display  
    Private Sub UpdateDisplay()
        'Public Sub New(ByVal ticks As Long, ByVal kind As DateTimeKind)


        setHourTextBox.Text = Convert.ToString(time.Hour)
        setMinuteTextBox.Text = Convert.ToString(time.Minute)
        setSecondTextBox.Text = Convert.ToString(time.Second)
        output1Label.Text = ("Hour: " & time.Hour & "; Minute: " &
        time.Minute & "; Second: " & time.Second)
        output2Label.Text = ("Standard time is: " & time.ToString() &
        "; Universal Time is: " & time.ToUniversalTime.ToString
)

    End Sub ' UpdateDisplay

This post has been edited by charyl: 26 November 2012 - 11:00 PM

Was This Post Helpful? 0
  • +
  • -

#10 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Declaring a new sub problem

Posted 26 November 2012 - 11:59 PM

Well, you aren't doing yourself a favor, having 2 topics for the same problem. Look at the answers there, and try to understand that you named your form Time, and that doesn't represent DateTime or Date, but the form.
Was This Post Helpful? 0
  • +
  • -

#11 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: Declaring a new sub problem

Posted 27 November 2012 - 01:34 AM

already looked at that, didn't understand
Was This Post Helpful? 0
  • +
  • -

#12 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Declaring a new sub problem

Posted 27 November 2012 - 04:17 AM

OK. You named your form as Time. Each time you address Time in it, you address the form class, not the DateTime structure.

You have Dim time As New Time() in your code, and then you use this time variable. Your time variable represents new instance of Form class named Time (I'm trying to tell you as simple as I can, not mentioning subtle details, just to not confuse you more). Visit those links, and see the difference between them.

Here's one basic tutorial about classes in VB.NET.
Was This Post Helpful? 1
  • +
  • -

#13 charyl  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 324
  • Joined: 29-June 11

Re: Declaring a new sub problem

Posted 27 November 2012 - 05:19 PM

So sorry, I just opened it back up. I will change my form name and re look at the links above...My brain is fried today so I will probably have to fix this tomorrow, but I will try! I really appreciate your patients and the fact you have noticed these small details AND your tutorials!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1