|
You really should not do it this way. If you have a DateTime datatype, use it. Don't you think so?
jeshra279 wrote: Please provide me a line of code for this?
It cannot be done in a line of code with current approach.
Still if you want to stick to this way, then since the values in your database are as strings, then break up the date, month and year part into seprate integers. Then start with checking that if the year is less than selected dates year. If the year is same, check for month and if month is same check for date. Then you can filter out the records.
Don't you think this is bit insane way of comparing dates?
PS: There can be a decent way than what I have told. But anyways, IMHO if you use strings to store dates, you are wrong no matter how you comapre them.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
when you have a number (say 123) you store it in a numeric field, not as a "123" string, right?
when you have a date, a time, a datetime, you store it in a field of the corresponding type, and NOT as a string; doing it properly avoids all confusion about date formats and regional settings; and it saves CPU cycles.
If your database table has a date field that is currently a string, and you want it to become a date, then this should do it:
- add a new field, with a new name;
- issue an SQL command to populate the new field based on your interpretation of the existing field;
- adapt your code base to use the new field, and no longer use the old one;
- delete the old field;
- optionally rename the new field in the database table and in your code.
That is a one time effort saving you all the trouble you would otherwise have later when your app grows, and/or when your app gets used by more people in more countries.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hey all. On a new project im working on, which is about learning different areas in visual basic. One area i havnt covered much is writing to files and retrieving data from a file.
The program includes a update script, which justs checks online reading a .txt file to see if the version is newer, if so it downloads it. I would like to record when the user last press 'checkForUpdates' button. Take the timestamp and write it into a xml file. Then using a simple label to read and display the value inside the xml file.
I have been trying a few ways, just using timestamps i got lost.
Any help would be great,
Malcom
|
|
|
|
|
If you can show the code you have tried and explain the exact problem, it would be easier to help.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Oki sorry, i asked wrong, i have tried some ways but i can't get it to work.
Im not asking for the answer, that be wrong. I am learning it afterall.
I just need say a boost. Just a quick example of generating a timestamp then i can work it from there. I did some googling and believe i can easly use xml file just need to mess around abit more.
Sorry for the bother,
Malcom
|
|
|
|
|
DateTime.Now will give you the current time. And then, you can look into the classes in System.Xml namespace to write that to your XML file.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
hi, here i have some code for you.
System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter("C:\\timestamp.xml",System.Text.Encoding.UTF8);
xtw.Formatting == Formatting.Indented;
xtw.Indentation = 4;
xtw.WriteStartDocument();
xtw.WriteStartElement("TimeStamp");
xtw.WriteString(DateTime.Now.ToOADate());
xtw.WriteEndElement();
xtw.WriteStartElement("TimeStampAttribute");
xtw.WriteAttributeString("DateTime",DateTime.Now.ToOADate())
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Close();
|
|
|
|
|
Thank you both. I tried your hints and i got somewhere. Just was hitting a wall. The time was coming out as 00:00:00. To the last replier before me, thanks for the code, really gave me a better idea of what i needed. Thanks
|
|
|
|
|
Can anybody tells me how to export data to excel...
|
|
|
|
|
Google is your freind...
Google[^]
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
From what?
Though as has already been posted, Google gives thousands of examples.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Hi All,
The problem discussed is accuracy of numeric calculation result,in vb. Namely I compare a numerical mathematic calculation, Line-Plan Intersection, in VB.Net and Matlab 2007 the intersection point result specify in below:
Matlab 2007 ---->
Xint=2.000000000000000
Yint=1.333333333333333
Zint=0.666666666666667
But
Visual Studio 2008 ---->
Xint=2.0000000596046448
Yint=1.3333333730697632
Zint=0.66666668653488159
Hand Calculated ----->
Xint=2.000000000000000
Yint=1.333333333333333
Zint=0.666666666666667
why this error occurs?
Thanks.
|
|
|
|
|
What Data Type are you using for the calculation in VB?.
This looks like an issue with floating-point precision.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
Certinly I have been used Double data type for this calculation. The code inserted in below is the same
story that I have been explained.
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click<br />
<br />
Dim xint, yint, zint As Double<br />
Dim ob, oc, ratio As Double<br />
Dim havint, intree As Boolean<br />
Dim x0, x1, x2, xb As Double<br />
Dim y0, y1, y2, yb As Double<br />
Dim z0, z1, z2, zb As Double<br />
'3 Points of plane formed triangle too.<br />
x0 = 2<br />
x1 = 2<br />
x2 = 2<br />
y0 = 0<br />
y1 = 2<br />
y2 = 2<br />
z0 = 2<br />
z1 = 2<br />
z2 = 0<br />
'Points of line, other point is [0 0 0]<br />
xb = 1.5<br />
yb = 1<br />
zb = 0.5<br />
Line_PlaneIntersection(x0, x1, x2, xb, y0, y1, y2, yb, z0, z1, z2, _<br />
zb, xint, yint, zint, ob, oc, ratio, havint, intree)<br />
End Sub<br />
<br />
<br />
Public Shared Sub Line_PlaneIntersect(ByVal X0 As Double, ByVal X1 As Double, ByVal X2 As Double, _<br />
ByVal Xb As Double,ByVal Y0 As Double, ByVal Y1 As Double, _<br />
ByVal Y2 As Double,ByVal Yb As Double,ByVal Z0 As Double, _ <br />
ByVal Z1 As Double, ByVal Z2 As Double, ByVal Zb As Double, _<br />
ByRef Xint As Double, ByRef Yint As Double, ByRef Zint As _<br />
Double, ByRef OB As Double, ByRef OC As Double, ByRef Ratio As _<br />
Double,ByRef HaveIntersect As Boolean, ByRef InTriangle As _<br />
Boolean) <br />
<br />
<br />
'***This formulation is based on the assumption that the line starts from origin***<br />
Dim t, u, v As Single<br />
Dim A, B, C, D As Double<br />
Dim A1, A2, A3 As Double<br />
Dim B1, B2, B3 As Double<br />
Dim C1, C2, C3 As Double<br />
Dim D1, D2, D3, D4, D5, D6 As Double<br />
Dim Det As Double<br />
Dim Det1, Det2, Det3, Det4, Det5, Det6 As Double<br />
Det1 = +Xb * ((Y2 - Y0) * (Z1 - Z0))<br />
Det2 = +Yb * ((X1 - X0) * (Z2 - Z0))<br />
Det3 = +Zb * ((X2 - X0) * (Y1 - Y0))<br />
Det4 = -Xb * ((Y1 - Y0) * (Z2 - Z0))<br />
Det5 = -Yb * ((X2 - X0) * (Z1 - Z0))<br />
Det6 = -Zb * ((X1 - X0) * (Y2 - Y0))<br />
Det = Det1 + Det2 + Det3 + Det4 + Det5 + Det6<br />
If Det <> 0 Then<br />
HaveIntersect = True<br />
A1 = X0 * ((Y1 - Y0) * (Z2 - Z0) - (Y2 - Y0) * (Z1 - Z0))<br />
A2 = Y0 * ((X2 - X0) * (Z1 - Z0) - (X1 - X0) * (Z2 - Z0))<br />
A3 = Z0 * ((X1 - X0) * (Y2 - Y0) - (X2 - X0) * (Y1 - Y0))<br />
A = A1 + A2 + A3<br />
B1 = X0 * ((Y2 - Y0) * Zb - (Z2 - Z0) * Yb)<br />
B2 = Y0 * ((Z2 - Z0) * Xb - (X2 - X0) * Zb)<br />
B3 = Z0 * ((X2 - X0) * Yb - (Y2 - Y0) * Xb)<br />
B = B1 + B2 + B3<br />
C1 = X0 * ((Z1 - Z0) * Yb - (Y1 - Y0) * Zb)<br />
C2 = Y0 * ((X1 - X0) * Zb - (Z1 - Z0) * Xb)<br />
C3 = Z0 * ((Y1 - Y0) * Xb - (X1 - X0) * Yb)<br />
C = C1 + C2 + C3<br />
D1 = +(X1 - X0) * (Y2 - Y0) * Zb<br />
D2 = +(X2 - X0) * (Z1 - Z0) * Yb<br />
D3 = +(Y1 - Y0) * (Z2 - Z0) * Xb<br />
D4 = -(X1 - X0) * (Z2 - Z0) * Yb<br />
D5 = -(X2 - X0) * (Y1 - Y0) * Zb<br />
D6 = -(Y2 - Y0) * (Z1 - Z0) * Xb<br />
D = D1 + D2 + D3 + D4 + D5 + D6<br />
t = A / D<br />
u = B / D<br />
v = C / D<br />
Xint = Xb * t<br />
Yint = Yb * t<br />
Zint = Zb * t <br />
Dim Bool1, Bool2 As Boolean<br />
Bool1 = u >= 0 And u <= 1<br />
Bool2 = v >= 0 And v <= 1<br />
If Bool1 And Bool2 And (u + v) <= 1 Then<br />
'means that the intersection point lies in triangle wroughted from 3 points of the plane <br />
InTriangle = True<br />
OB = Math.Sqrt(Xb ^ 2 + Yb ^ 2 + Zb ^ 2)<br />
OC = Math.Sqrt(Xint ^ 2 + Yint ^ 2 + Zint ^ 2)<br />
Ratio = OB / OC<br />
End If<br />
Else<br />
HaveIntersect = False<br />
InTriangle = False<br />
End If<br />
End Sub
'***************************************************************************************************
%MAtlab syntax
clear<br />
%Data of line's points<br />
xa=0; ya=0; za=0;<br />
xb=1.5; yb=1; zb=1/2;<br />
Ia=[xa<br />
ya<br />
za];<br />
Ib=[xb<br />
yb<br />
zb];<br />
%Data of plane<br />
x0=2; y0=0; z0=2;<br />
x1=2; y1=2; z1=2;<br />
x2=2; y2=2; z2=0;<br />
A= [xa-xb x1-x0 x2-x0<br />
ya-yb y1-y0 y2-y0<br />
za-zb z1-z0 z2-z0];<br />
B=[xa-x0<br />
ya-y0<br />
za-z0];<br />
<br />
C=A^-1*B<br />
<br />
Iint=Ia+(Ib-Ia).*C(1)<br />
after running
Iint =
2.0000
1.3333
0.6667
|
|
|
|
|
I am not Maths Wizard (I was a terrible student), but this excerpt from Wikipaedia on double floating point precision may shed some light...
Why do you need to return so many digits after the decimal point?
Addition and subtraction
A simple method to add floating-point numbers is to first represent them with the same exponent. In the example below, the second number is shifted right by three digits, and we then proceed with the usual addition method:
123456.7 = 1.234567 * 10^5
101.7654 = 1.017654 * 10^2 = 0.001017654 * 10^5
Hence:
123456.7 + 101.7654 = (1.234567 * 10^5) + (1.017654 * 10^2)
= (1.234567 * 10^5) + (0.001017654 * 10^5)
= (1.234567 + 0.001017654) * 10^5
= 1.235584654 * 10^5
In detail:
e=5; s=1.234567 (123456.7)
+ e=2; s=1.017654 (101.7654)
e=5; s=1.234567
+ e=5; s=0.001017654 (after shifting)
--------------------
e=5; s=1.235584654 (true sum: 123558.4654)
This is the true result, the exact sum of the operands. It will be rounded to seven digits and then normalized if necessary. The final result is
e=5; s=1.235585 (final sum: 123558.5)
Note that the low 3 digits of the second operand (654) are essentially lost. This is round-off error. In extreme cases, the sum of two non-zero numbers may be equal to one of them:
e=5; s=1.234567
+ e=-3; s=9.876543
e=5; s=1.234567
+ e=5; s=0.00000009876543 (after shifting)
----------------------
e=5; s=1.23456709876543 (true sum)
e=5; s=1.234567 (after rounding/normalization)
Another problem of loss of significance occurs when two close numbers are subtracted. In the following example e = 5; s = 1.234571 and e = 5; s = 1.234567 are representations of the rationals 123457.1467 and 123456.659.
e=5; s=1.234571
- e=5; s=1.234567
----------------
e=5; s=0.000004
e=-1; s=4.000000 (after rounding/normalization)
The best representation of this difference is e = −1; s = 4.877000 , which differs more than 20% from e = −1; s = 4.000000 . In extreme cases, the final result may be zero even though an exact calculation may be several million. This cancellation illustrates the danger in assuming that all of the digits of a computed result are meaningful. Dealing with the consequences of these errors is a topic in numerical analysis; see also Accuracy problems.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
I find answer! Because I had been defined three of variable as Single.
However this variables were small but when I change those to Double this problem solved.
Dim t, u, v As Single -------->Dim t, u, v As Double
Sorry
|
|
|
|
|
Using the Double datatype does not "solve" the problem. It mearly masks it. It still has the same problem as the Single type. Google and read up on "IEEE 754" and "IEEE 854" to understand how number representation works in computers and why you're getting the results you are.
|
|
|
|
|
Hmm. In this case I think single/double is the root cause; the OP complained about the numbers his code produced (which displayed some 16 digits of which obviously only 7 or so were correct). He wasn't really worried about the very last digit (yet).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
i want to insert some values "from visual basic into one m-file in matlab" then run another m-file from visual basic that will get benefit from the first m-file with the inserted values. i really would apprecitae any help. this is what i wrote so far in visual basic:
Dim Matlab As Object
Dim Result As String
Dim MReal (0,3) As Double
Dim MImag() As Double
Set Matlab = createObject("Matlab.Application")
' here where i saved the two m-files
Result = Matlab.Excute("C:\Porgram Files\MATLAB71\work")
'this is the second m-file which i want to run
Result = Matlab.Excute("solvingnle")
Call Matlab.GetFullMatrix("X", "base", MReal, MImag)
'here where i will show the result of my m-file, each result of the matrix seperate
Text1.Text = MReal(0, 0)
Text2.Text = MReal(0, 1)
Text3.Text = MReal(0, 2)
Text4.Text = MReal(0, 3)
End Sub
|
|
|
|
|
I'm building a dataset by querying several different Oracle tables with the same query.
I want to output the dataset to an Excel file with a separate heading for the results from each Oracle table.
To do this, so far I've added a 'Heading" column to the datatable, but I can't figure out how to fill that column to identify the datarows that came from each Oracle table.
If anyone can shed some light on this it would be appreciated.
For i = 0 To 3
Try
CN = New OracleConnection("Data Source=xe;User Id=" & Username(i) & ";Password=" & Password(i))
'create the dataadapter object
Dim adp As New OracleDataAdapter(SQL(i), CN)
adp.Fill(ds)
If i = 0 Then
ds.Tables(0).Columns.Add("Headings")
End If
|
|
|
|
|
I don't think that you need to add a 'Headings' column.
A DataSet has a Tables collection, each DataTable in that collection has a TableName property. so that is accessible by iterating over the Tables collection.
Each DataTable has a Columns collection which is a collection of DataColumn s, each of which has a ColumnName property.
So iterate over the Tables collection and for each DataTable returned iterate over its Columns collection. For each DataColumn , get its ColumnName .
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi. Thanks for your input.
I'm iterating through a list of users of an Oracle database and running the same query on each. I create a new Oracle dataadapter for each user.
I would have thought that VB would fill a separate table with each user's query results. For some reason it's putting them all in the same table: Table(0).
It would be much easier to handle things if they did go into separate tables, but I can't see how to do this. Do you have any suggestions?
Thanks again.
|
|
|
|
|
Without seeing your code, it is difficult to be certain, and I am also not familiar with Oracle from a .Net point of view.
But if you are iterating a user list, it should be possible to create a new Table on each loop and have the query results added to that Table which then gets added to the DataSet.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Creating a new table for each user in your list would be exceedingly tedious to manage and also adds a lot of weight to your data in memory. DataTables are not light-weight objects. So, if you have thousands of users, you're going to consuming vast amounts of memory, needlessly.
From your limited description, it sounds like you have a serious design flaw in your data model.
|
|
|
|
|
Hello to All,
I am creating file with .ttg extenction. And i want to open those files with my application(Default) by using programming.
So how can i do that?
Thanks for help
If you can think then I Can.
|
|
|
|
|