Newbie, Looking for guidance

3 digit date + 3 digit assigned number

Page 1 of 1

3 Replies - 673 Views - Last Post: 11 June 2008 - 04:20 AM Rate Topic: -----

#1 DerianWeidman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-June 08

Newbie, Looking for guidance

Post icon  Posted 10 June 2008 - 07:49 AM

Im mearling looking for guidance, not someone to do the code for me, i just started coding vb a couple of days ago, ive odne my hello world, i even made a form that works with an access database, but now the next task is to get a 3 digit date and ascending 3 digit number to be spawned each time the form is opend, to assign it a name so to speak.

Im also curious as to how i am going to convert the date into a 3 digit format. month then day
so today being: 611

like i said im looking for guidance, this isnt for homework, for me to see if i can make something, although i will say, im really getting into this.

Is This A Good Question/Topic? 0
  • +

Replies To: Newbie, Looking for guidance

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Newbie, Looking for guidance

Posted 10 June 2008 - 08:23 AM

Look to using a DateTime object. It has properties which allow you to get the month and day. You won't convert the date to a three digit number, so much as you will just concatenate the numbers together.

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#3 DerianWeidman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-June 08

Re: Newbie, Looking for guidance

Posted 10 June 2008 - 08:36 AM

well ive come up with this, but i now need to figure out how to add 3 more numbers to it, based on an access database id i would think would be the easiest way.

Dim result As String = Now.Month.ToString + Now.Day.ToString
Me.TextBox1.Text = result

Was This Post Helpful? 0
  • +
  • -

#4 robertelder  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 30
  • Joined: 06-June 08

Re: Newbie, Looking for guidance

Posted 11 June 2008 - 04:20 AM

Im also curious as to how i am going to convert the date into a 3 digit format. month then day
so today being: 611

DerianWeidman,

You say you are looking for a "3 digit date" with an "ascending 3 digit number".

Using the code you provided, you may have some issues with the length of the result.

For today "11 June" it works fine as it converts the date to "611". If you were to run this code back on "8 June", the code would only show two digits: "68". If you need a three digit date, you'll have to add some logic to handle the first 9 days of each month. Also, you'll want to think about how you are going to handle dates like "31 December" which will give you a four digit result.

Unless you are required to use a 3-digit date, i would recommend at least a 4-digit date as the easiest method. If a month or day number is less than 9, add a 0. "8 June" becomes "0608", and "31 December" is simply "1231". If this program is going to be used for more than one year, it might be a good idea to include 2 or 4 extra digits for the year "20080611"



For the second part of your question regarding an ascending 3 digit number that will be generated each time the form is opened, this will take some more thought.

If the application is not going to be shutdown, you could just create a variable to store the last number and add to it each time it is needed. For example:
Public Class Form1
	Dim LogIDNum As Integer

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		'increment the LogID# by 1
		LogIDNum = LogIDNum + 1

		'display a string of numbers based on month/day and LogID#
		Dim result As String = Now.Month.ToString + Now.Day.ToString
		Me.TextBox1.Text = result & LogIDNum
	End Sub
End Class



Unfortunately, if the application is closed, then when it is reopened the variable will start over again.

The easiest way to get around this issue would be to log the last number assigned to a textfile, xml, or even to your access database. When you need to assign a new number, you just find the last number, increment it by 1, then replace the old number with the new number in the log.

Good luck!

-Rob
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1