Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I will try to make this by myself ...but I want to know if its possible before I will spend hours(or days) for that.

 

Let's say that today is monday (19th). When I open the form with the chart control on it, the chart must have the last seven days with some values (values taken from a file...done that so is not a problem).

 

So...the chart will have this data:

 

tu 13th we 14th th 15th fr 16th sa 17th su 18th mo 19th

 

 

if I open the chart on sunday ..the chart column data will be different with the last seven days....

 

thanks

 

later edit :

 

btw ...I tried to get current time and...

 

get month

get day

 

and where I have the chart I put:

 

month-5

month-4

month-3

month-2

month-1

month >> now...

 

the same with day...but .... if today is 2th ...I think that the "-3" is not a correct day.... :)

Edited by Ace Master
Posted

Sorry for the delay on the reply but I didn't notice this thread...

 

What you want is donne this way:

 

       Dim d As Date
       Dim ts As New TimeSpan

       ts = ts.FromDays(7) '7 days
       d = Date.Now

       d = d.Subtract(ts)  'Subtract the 7 days from the 'd' Date

 

 

On the TimeSpan object you have several methods, not only the FromDays...

 

:D

Software bugs are impossible to detect by anybody except the end user.
Posted

thanks

 

thank you so much Alex.... :)

 

is working now....days and months, but it is a way to change the time format?

 

in my chart I have under evert line somthing like that:

 

for months chart:

5/6/2003 6/6/2003 7/6/2003 ...etc...

 

or....

 

for days chart:

9/30/2003 10/1/2003 ...etc...

 

I whant if is possbile to display:

 

for months :

may 2003 june 2003 ..etc...

 

and for days:

monday tuersday ..etc...

 

bye

Posted

Taken from the dynamic help of the VS .Net 2003...

 

This example shows various uses of the Format function to format values using both String formats and user-defined formats. For the date separator (/), time separator (:), and the AM/PM indicators (t and tt), the actual formatted output displayed by your system depends on the locale settings the code is using. When times and dates are displayed in the development environment, the short time format and short date format of the code locale are used.

 

Dim MyDateTime As Date = #1/27/2001 5:04:23 PM#
Dim MyStr As String
' Returns current system time in the system-defined long time format.
MyStr = Format(Now(), "Long Time")
' Returns current system date in the system-defined long date format.
MyStr = Format(Now(), "Long Date")
' Also returns current system date in the system-defined long date 
' format, using the single letter code for the format.
MyStr = Format(Now(), "D")
' Returns the value of MyDateTime in user-defined date/time formats.
MyStr = Format(MyDateTime, "h:m:s")   ' Returns "5:4:23".
MyStr = Format(MyDateTime, "hh:mm:ss tt")   ' Returns "05:04:23 PM".
MyStr = Format(MyDateTime, "dddd, MMM d yyyy")   ' Returns "Saturday,
  ' Jan 27 2001".
MyStr = Format(MyDateTime, "HH:mm:ss")   ' Returns "17:04:23"
MyStr = Format(23)   ' Returns "23".
' User-defined numeric formats.
MyStr = Format(5459.4, "##,##0.00")   ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00")   ' Returns "334.90".
MyStr = Format(5, "0.00%")   ' Returns "500.00%".

 

This will work out ...

Software bugs are impossible to detect by anybody except the end user.
Posted

uf...

 

other thing...

 

the code make the formating working very well, but I can't use the timespan anymore ..for substract the days.

 

this is my code:

 

Dim d As Date = Date.Now()

Dim ts As New TimeSpan

Dim MyStr As String

 

ts = ts.FromDays(7) '7 days

MyStr = Format(d, "dddd, MMM d yyyy")

' d = d.Subtract(ts) 'Subtract the 7 days from the 'd' Date

 

 

MsgBox(MyStr)

 

 

the msgbox returns the format I whant but I can't use time substract because MyStr is now a string and cannot substract from string.

 

I need something else ??

Posted

Exactly... you make a cast from a Date to a String so you can't use the TimeSpan anymore...

 

Do it like this:

 

Dim d As Date = Date.Now()
Dim ts As New TimeSpan
Dim MyStr As String

ts = ts.FromDays(7) '7 days
d = d.Subtract(ts) 'Subtract the 7 days from the 'd' Date
MyStr = Format(d, "dddd, MMM d yyyy")

MsgBox(MyStr)

 

It's just a matter of subtracting the TimeSpan before Formating the Data...

 

Ok like this ? :D

Software bugs are impossible to detect by anybody except the end user.
Posted

hi.

 

the code you give is good..but is like I did before...I can see only in msgbox

 

I whant in my chart when I put the name of columns to put something like that:

 

Dim Sales2(,) As Object = New Object(,) _

{{"stuff", "Param 1"}, _

{MyStr, Vals2(0)}, _

{MyStr, Vals2(1)}, _

{MyStr, Vals2(2)}, _

{MyStr, Vals2(3)}, _

{MyStr, Vals2(4)}, _

{MyStr, Vals2(5)}, _

{MyStr, Vals2(6)}}

 

chart2.ChartData = Sales2

 

now in the chart column I have just "tuesday", and can't make mystr - 6

mystr - 5

mystr - 4

mystr - 3

 

etc.....

Posted

i did it

 

i did individualy :)

 

Dim d1 As Date = Date.Now()

Dim d2 As Date = Date.Now()

Dim d3 As Date = Date.Now()

 

Dim ts1 As New TimeSpan

Dim ts2 As New TimeSpan

Dim ts3 As New TimeSpan

 

Dim MyStr1 As String

Dim MyStr2 As String

Dim MyStr3 As String

 

ts1 = ts1.FromDays(0) '0 days

d1 = d1.Subtract(ts1) 'Subtract the 0 days from the 'd' Date

 

ts2 = ts2.FromDays(1) '1 days

d2 = d2.Subtract(ts2) 'Subtract the 1 days from the 'd' Date

 

ts3 = ts3.FromDays(2) '2 days

d3 = d3.Subtract(ts3) 'Subtract the 2 days from the 'd' Date

 

MyStr1 = Format(d1, "dddd")

MyStr2 = Format(d2, "dddd")

MyStr3 = Format(d3, "dddd")

 

MsgBox(MyStr1)

MsgBox(MyStr2)

MsgBox(MyStr3)

 

is quite hard but at least is working .... I have three variables to put in my chart. Now going to all seven..and the same for months.

 

uf.....

Posted

Hi did the complete procedure...

I've created a String Array to store the last 7 days from today.

 

Maybe it isn't the best way but I didn't wanted to complicate the thing... from here you can change it like you wish.

 

I'm displaying the results on a ListBox...

 

Try it and tell me if it worked like this. :D

 

   Public Sub ChartMonths()

       Dim Dates(6) As String   'Stores the last 7 days counting from today
       Dim d As Date
       Dim ts As New TimeSpan  'TimeSpan you want

       For day As Integer = 0 To 6

           d = Date.Now

           ts = ts.FromDays(day)   'Subtract the days one by one
           d = d.Subtract(ts)      'Subtract the number of days specified 
           Dates(day) = Format(d, "dddd, MMM d yyyy")

           Me.ListBox1.Items.Add(Dates(day))

       Next

End Sub

Software bugs are impossible to detect by anybody except the end user.
Posted

:D I think you should use my way anyways...

 

Your code works but with too many lines and declared objects... ;) But it wasn't easy for us to understant each other...

 

But it's donne... :p

Software bugs are impossible to detect by anybody except the end user.
Posted

But the months are easyer to do...

 

What do u need?

the last 6 months on the same current day number or on the 1st day of each month?

 

It's just a matter of subtracting the months and control if the year changes...

 

Try to do it... if you get any trouble post it that I'll help...

Software bugs are impossible to detect by anybody except the end user.
Posted

I know that is not the best way for doing this...

 

I want just the last 6 months...I don't care what day is today (or year)

Just to know what month is current and to subtract the last 5 from it.

 

This is my code... :)

 

Dim months(150) As String 'Stores the last 6 months counting from today

Dim m As Date

Dim ms As New TimeSpan 'TimeSpan you want

 

For month As Integer = 0 To 150

 

m = Date.Now

 

ms = ms.FromDays(month) 'Subtract the month one by one with 30 days

m = m.Subtract(ms) 'Subtract the number of month specified

months(month) = Format(m, "MMM ")

 

 

 

Next

 

msgbox(0) > return october

msgbox(30) > return september

 

...and so on...

Posted (edited)

big problem

 

...big problem...

 

I want to make refresh of the chart each 30 seconds and I made a button to simulate a refresh and can�t access the file anymore if the application is still open.

 

I can't change the values in the text file, the only way to do that it is if I close my app�

 

It is a way to write into the file again if the app is open?

Edited by Ace Master
Posted

Sorry but I don't have time right now to tell you how to do the other one but this last one, the file problem, it's a tipical non closed file...

 

How do you read the file?

 

When you open the file it remains opened until you closeit (File.close)... meanwhile no one cass have access to that same file!

 

 

On the other one you may want to do it with 2 Loops:

 

Dim Day, Month as integer
day = date.day
month = date.month

Do

    Do

    Loop Until ...

Loop until month = date.month -6

 

 

It's just a suggestion... I'll only be back in about 12 hours or so ...

 

Post what you're doing... :D

Software bugs are impossible to detect by anybody except the end user.
Posted (edited)


Const FilePath As String = "C:\month.txt"
       Dim sr As New System.IO.StreamReader(FilePath)
       Dim lines As Integer
       Dim Vals As New ArrayList
       Dim str As String

       Do
           str = sr.ReadLine()
           lines += 1
       Loop While (Not str = "")
       lines -= 1
       sr.Close()

       sr = New System.IO.StreamReader(FilePath)

       For jump As Integer = 1 To lines - 6
           sr.ReadLine()
       Next

       For i As Integer = 0 To 5
           Vals.Add(Val(sr.ReadLine))
       Next

 

I close the file with sr.close() ... and is not working

 

later edit :

 

I did it. Wrong placement of the close() :)

Edited by Ace Master
Posted

yes

 

yep... :) ..now is perfect...

 

you can tell me please what I need here for extract the "space" and the "new line" from that text? Right now is working for space split ..but don't know how to add other split for new line (enter)

 

this is my code:

 

  Dim sr As New System.IO.StreamReader("poz.txt")
       Dim Line As Object
       Dim vals() As Object
       Dim space As String = "	"
       Line = sr.ReadToEnd
       vals = Line.Split(space)
       vals = Line.Split(vbCrLf)
       sr.Close()

 

with this code I recieve " Index was outside the bounds of the array." because of the second vals split (vbCrLf)

Posted

So... here we go again :D

 

What do we have here now... From what u told me u have the Text File witch you read into a Live val of type Object...

Then you want to split the lines... Correct?

 

So, why don't you use the sr.ReadLine instead of the sr.ReadToEnd??

 

The ReadLine method allows you to read the text file line by line until the end. With this you can read each line into a Array of strings for example... eliminating the line break probem...

 

What do u think? :D

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...