Info in Database converted to Chart

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2005
Posts: 7
Reputation: wallis_online is an unknown quantity at this point 
Solved Threads: 0
wallis_online wallis_online is offline Offline
Newbie Poster

Info in Database converted to Chart

 
0
  #1
Apr 1st, 2005
What I need to do is have the data on the bottom line of my chart to show the full date as it is in the database that I take the data from. In the database it is in the form of 29/March/2005 and this is how I want it to display on the chart. my code is as follows:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim db As Database
  2. Dim qdef As QueryDef
  3. Dim rs As Recordset
  4. Dim dbname As String
  5. Dim i As Integer
  6.  
  7. dbname = App.Path
  8. If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
  9. dbname = dbname & "FishKeeping.mdb"
  10. Set db = OpenDatabase(dbname)
  11.  
  12.  
  13. Set qdef = db.CreateQueryDef("", _
  14. "SELECT Date, PH FROM WaterQuality")
  15. Set rs = qdef.OpenRecordset(dbOpenSnapshot)
  16.  
  17. rs.MoveLast
  18. NumPoints = rs.RecordCount
  19. ReDim Values(1 To NumPoints, 1 To 2)
  20.  
  21. rs.MoveFirst
  22. For i = 1 To NumPoints
  23. Values(i, 1) = Format$(rs!Date, "dd/MMMM/yyyy")
  24. Values(i, 2) = rs!PH
  25. rs.MoveNext
  26. Next i
  27.  
  28. rs.Close
  29. db.Close
  30.  
  31. Chart1.chartType = VtChChartType2dXY
  32. Chart1.RowCount = NumPoints
  33. Chart1.ColumnCount = 2
  34. Chart1.ChartData = Values
All I get is the error: Type Mismatch and it highlights

Values(i, 1) = Format$(rs!Date, "dd/MMMM/yyyy")

But if I change this line to

Values(i, 1) = Format$(rs!Date, "yyyy")

it displays my chart but the bottom line only display by year. Am i missing something!?

It does all this if my database is set up to display the date as text or in date/time format.

Any help greatly appreciated sorry for the long query !

Hope all this makes sense!
Last edited by alc6379; Apr 6th, 2005 at 11:00 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Info in Database converted to Chart

 
0
  #2
Apr 1st, 2005
Well, Think about it like this... The Date, in the format of dd/mmmm/yyyy is going to try to format the date as something like this: 01/0004/2005 (most likely). Now, another option is, have you tried to remove the format$? So it would be set to something like: Values(i, 1) = rs!Date and try that as text.... since the date in the database is already set to the format you want, just try to load the date as a string into the cell. Let me know if that works.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 7
Reputation: wallis_online is an unknown quantity at this point 
Solved Threads: 0
wallis_online wallis_online is offline Offline
Newbie Poster

Re: Info in Database converted to Chart

 
0
  #3
Apr 1st, 2005
Yeah I tried that.... And it spreads the information out along the bottom of the chart - but removes the information up the side of the chart and doesnt show any dates - I have attatched 2 pictures of what the graph looks like, image 1 is as you suggested, removing the format$ and the 2nd image is with the format$ in. Ive not posted much on this site so dont know how the images will turn out. Let me know if youwant more info or even if you want me to send you the program in a zip file to go over the project better.

cheers for the advice though! glad for the help you have given.
Attached Thumbnails
Image1.jpg   Image2.jpg  
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Info in Database converted to Chart

 
0
  #4
Apr 1st, 2005
Yes, Please attach the zip so that I can fiddle with it. Along with your database (or one similar without any confidential information).
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 7
Reputation: wallis_online is an unknown quantity at this point 
Solved Threads: 0
wallis_online wallis_online is offline Offline
Newbie Poster

Re: Info in Database converted to Chart

 
0
  #5
Apr 1st, 2005
Originally Posted by Comatose
Yes, Please attach the zip so that I can fiddle with it. Along with your database (or one similar without any confidential information).
None of the data is confidential, its all just 'test' information, I havnt commented anything. frmPHChart is the main one to look at as this is where the chart info is, feel free to mess with the rest of it though !

Thankyou very much for the help ! this is much appreciated, its nothing too important so feel free to leave it if ya like!

thankyou sooo much!

Cheers
Attached Files
File Type: zip Water Quality Results.zip (24.1 KB, 17 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Info in Database converted to Chart

 
0
  #6
Apr 2nd, 2005
Ok, The solution to the date format has been resolved. What I had to do was set a temporary variable to equal the date as it is, and then use that to set it to a new format date. The Date setup in your database is m/dd/yyyy, which I converted in code to MMMM/dd/yyyy. Then, I converted That To The New Setup Date dd/MMMM/yyyy. Here is the code how I went about doing this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. tmpdate = Format$(rs!Date, "MMMM/dd/yyyy")
  2. ndate = Format(tmpdate, "dd/MMMM/yyyy")

Now, this is all well and dandy, but we still have a real big problem, (and this is the reason for the type mismatch error), is that your variable, Value's is declared in the code above as a single. When we change the date from all numbers (m/dd/yyyy) to a mixture of letters and numbers (dd/MMMM/yyyy), this new value becomes a string! A String! So, unfortunately, since the variable is defined as a single, it can not hold or contain a string. You also use that 2 dimensional array, as the reference to your chart itself. If you were able to change the Values array, it will impact the chart, because (from what I can tell) the chart is in need of an array of single's. I'm still trying to find a workaround, but have been so far unsuccessful. However, finding the problem is sometimes the hardest part.... and that part is done!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC