VB has been connected to the ACCESS successfully,
to find data sheet density increased by 10%, close to 50% of the corresponding the strength increasing the intensity of density, text1. The text finally get the density,
I am a novice, wrote the following code temporarily, but there is a problem, trouble experts help modify, specific need how to write, thank you very much!
The Set Scnny=New ADODB. Connection
Scnny. CursorLocation=adUseClient
Scnny. Open the Provider="Microsoft. Jet. The oledb. 4.0; Data source="& amp; App. The Path & amp; "\ Data \ Data. MDB; Persist Security Info=False; The Jet OLEDB: Database Password=123456
"The Set srt1y=New ADODB. You
The Set srt1y. ActiveConnection=Scnny
Srt1y. Open the "select * from table where abs (H (select strength from data table where density * 1.1)/H (select strength from data table where density * 1) 1.5) in (select min (H (select strength from data table where density * 1.1)/H (select strength from data table where density * 1) 1.5) from the data table)"
If Not srt1y. EOF Then
Text1. Text=srt1y! Density
End the If
Srt1y. Close
Add:
I'm afraid of language to describe the great god, especially in EXCEL made a calculation example, as shown in the figure below, but this just using the EXCEL calculation examples, is ultimately want to EXCEL the effect on the VB use SQL statements to connect the ACCESS implementation,
When density increased by 10%, an increase of 50% strength, ultimately want results were obtained density is 15980,
Idea is: 15980 corresponds to the intensity of 0.3207, a 10% increase in 15980 is 17578175 78 17580175 80 is the most close to the corresponding intensity is 0.4790, 0.4790 divided by 0.3207=1.49356, the most close to 1.5 times, 0.3207 the increase of nearly 50% to 0.4790, so the final flux density is 15980,
CodePudding user response:
Feeling do you want to be in "SQL query operation" at the same time, to achieve "iterative arithmetic" (and "conditional iteration", or "fuzzy conditions"),It can support you for such a "operation"...
SQL operations anyway I am a layman, look,
CodePudding user response:
I feel you add one column in the database, is "how much density increased by 10%, the strength growth",And then query it 1 column data, which is the most close to "target" also on some relatively,
CodePudding user response:
You write 1 * 1.1 column density data at 10 to the nearest integer, prior to the query to the density of 10 integer column,2 you may have to two layers of query (and perhaps other netizens and nested query plan)
data table name, column name best without Chinese characters and punctuation, especially the punctuation marks can be interpreted as operator,
Rs1. Open the "SELECT * FROM [table]"
Do Until EOF (rs1)
Rs2. Open the "SELECT TOP [1] density WHERE [density]=" & amp; Rs1! * 1.1] [density & amp; "AND [strength] & gt;="& amp; Rs1! ] [1.1 times the density of the corresponding strength & amp; "The ORDER BY [] density"
If Not rs2. EOF Then Exit the Do
Rs1. MoveNext
Loop
Rs2. Close
MsgBox rs1! Density
Rs1. Close
CodePudding user response:
The SQL statement is completely wrongCodePudding user response:
The result of your deduction is wrong, you see the strength of the density of 15990 that that is closer to 1.5 times than in 15980CodePudding user response:
Ok, this is I think one of the more disgusting a SQL statement, in order to in a fix without temporary table, then use the three layers of nested child table, query out the first line should be you want, look from actual query result is also the most matching the record 15990, 15980, the second,Of course, I, the comparison of differences between the way is to take the absolute value of don't know whether meet your requirements
SELECT l33. Density, l33. Matching density, l31. Strength, l32) flashes strength AS match strength, Abs (l31. Strength * 1.5 - l32) flashes strength) AS intensity difference
FROM data table AS l31, data table AS l32, flashes (density, the SELECT l21. Density, l21. Matching l22. The minimum difference FROM (SELECT l11. The density, l12. Density AS match density, abs (l11) density * 1.1 - l12) density) AS difference FROM the data table AS l11, data table AS l12) AS l21, (the SELECT l11. Density, min (abs (l11) density * 1.1 - l12) density)) AS the minimum difference FROM the data table AS l11, data table AS l12 GROUP BY l11. Density) AS l22 WHERE l21. Differences=l22. Minimum difference) AS l33
The WHERE (((l31. Density)=l33. Density) And ((l32) flashes density)=l33. Matching density))
The intensity of the ORDER BY Abs (l31. * 1.5 l32) flashes intensity);
CodePudding user response:
Private Sub Command1_Click ()
Dim cn As ADODB. Connection
Dim rs1 As ADODB library. You, rs2 As ADODB. You
Dim lngDensity As Long, dblStrength As Double
Set the cn=New ADODB. Connection
The Set rs1=New ADODB. You
The Set rs2=New ADODB. You
Cn. The Open ". The Provider=Microsoft jet. The oledb. 4.0; Data source=c: \ test \ test. The MDB;"
Rs1. Open the "SELECT * FROM data_table", cn
EOF
Do Until rs1.LngDensity=((rs1! Density * 1.1 + 5) \ 10 * 10
DblStrength=rs1! Strength * 1.5
Rs2. Open the "SELECT density FROM data_table WHERE density=" & amp; LngDensity & amp; "AND strength & gt;="& amp; DblStrength & amp; "The ORDER BY density," cn
If Not rs2. EOF Then
Rs2. Close
The Exit Do
The Else
Rs2. Close
End the If
Rs1. MoveNext
Loop
MsgBox rs1! Density
Rs1. Close
End Sub
Indeed, get the query result is 15990, if will receive 15980, 1.5 to 1.49,