|
Of course we don't care about rounding...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: Of course we don't care about rounding...
The exact specifics of which are left up to the reader, depending on specifications of course!
|
|
|
|
|
According to http://www.int.gu.edu.au/courses/3008int/m03/FYI/Command_Syntax.htm#Heading97[^]
"Int Function
Int(number)
Returns the integer portion of the number specified by the number argument. If number is negative, then Int returns the first negative integer less than or equal to number."
So please explain this behavior.
This is the current line of code.
strValue = CStr(Int(CSng(Mid(strInput, 50, 7)) + 0.5)) which gives me -9.0 when the value is -8.12. Logically -8.62 + 0.5 = -8.12.
If I change this to VB.NET code.
strValue = (Convert.ToInt32(Convert.ToSingle(strInput.Substring(50, 7)) + 0.5)).ToString Then I get -8.12.
What is up with that and if I indeed need it to be -9 how do I get there?
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
With this code you shoudl get -8 . The documentation is a little misleading. It should say that it gives you the integer closest to 0. If you have -8.12 the value returned would be -8 .
So what's the point of all this? Are you trying to round down to the next lower integer, be it a positive or negative value? -9 is lower than -8.12 for example.
|
|
|
|
|
Dave Kreskowiak wrote: So what's the point of all this? Are you trying to round down to the next lower integer, be it a positive or negative value? -9 is lower than -8.12 for example.
Based on what the code is doing it would appear that it should literally move it to the next highest number and cut it off at the decimal. The problem is when I simply converted the values to a more .NET way of coding. The .NET way gives me the answer I would expect, the VB6 way does not. It almost seems to ignore the fact that it is negative so the numbers go the other way when rounding UP. This is a production system so I need it to give the same answers and I can worry about whether they are correct after I get a match.
-- modified at 11:39 Thursday 10th May, 2007
It would appear that it always rounds to the number lower not closer to zero so -8.12 goes to -9 whereas 20.8 goes to 20. That seems like a bug to me.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
CleaKO wrote: It would appear that it always rounds to the number lower not closer to zero so -8.12 goes to -9 whereas 20.8 goes to 20. That seems like a bug to me.
Not quite. OK. I didn't notice this before, but the Int function is NOT the same as CInt .
In VB6, if you do this:
CInt(Csng("-8.62") + 0.5) you get -8 .
If you do this:
Int(Csng("-8.62") + 0.5) you get -9 .
Why? The answer is in the documentation:
Int, Fix Functions[^]
Both Int and Fix remove the fractional part of a number and return the resulting integer value.
The difference between Int and Fix is that if the number is negative, Int returns the first negative integer less than or equal to that number, whereas Fix returns the first negative integer greater than or equal to that number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.
Cint()[^]
CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Under VB.NET, the CInt and Convert.ToInt32() methods follow the old VB6 CInt function. You can still use the original VB6 code VB.NET, the Int function IS still there.
|
|
|
|
|
Dave Kreskowiak wrote: Why? The answer is in the documentation:
Int, Fix Functions[^]
Both Int and Fix remove the fractional part of a number and return the resulting integer value.
The difference between Int and Fix is that if the number is negative, Int returns the first negative integer less than or equal to that number, whereas Fix returns the first negative integer greater than or equal to that number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.
Cint()[^]
CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Under VB.NET, the CInt and Convert.ToInt32() methods follow the old VB6 CInt function. You can still use the original VB6 code VB.NET, the Int function IS still there.
Thanks for the clarification.
I know the function is still there, I just like to try to get away from the VB6 versions if I can. Maybe Im just a little too strict with my .NET.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
The VB6 functions are equivalent to these .NET methods:
Int() -> Math.Floor()<br />
Fix() -> Math.Ceiling()<br />
Round() -> Math.Round()<br />
CSng() -> Convert.ToSingle()<br />
CLng() -> Convert.ToInt32()
The Convert.ToInt32 method rounds the value the same ways as Math.Round does.
---
single minded; short sighted; long gone;
|
|
|
|
|
Ahhhh, thanks! There are so many options that I am just trying to learn as I go.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
I used the following code to crack Caesar Cipher code where the key is unknown. I have written the following code and is it not working. I want it done in access. Plz Plz help me.
Option Compare Database
Option Base 1
Private Sub Command4_Click()
Dim naturalDist(26, 2) As Double
naturalDist(1, 1) = 1
naturalDist(2, 1) = 2
naturalDist(3, 1) = 3
naturalDist(4, 1) = 4
naturalDist(5, 1) = 5
naturalDist(6, 1) = 6
naturalDist(7, 1) = 7
naturalDist(8, 1) = 8
naturalDist(9, 1) = 9
naturalDist(10, 1) = 10
naturalDist(11, 1) = 11
naturalDist(12, 1) = 12
naturalDist(13, 1) = 13
naturalDist(14, 1) = 14
naturalDist(15, 1) = 15
naturalDist(16, 1) = 16
naturalDist(17, 1) = 17
naturalDist(18, 1) = 18
naturalDist(19, 1) = 19
naturalDist(20, 1) = 20
naturalDist(21, 1) = 21
naturalDist(22, 1) = 22
naturalDist(23, 1) = 23
naturalDist(24, 1) = 24
naturalDist(25, 1) = 25
naturalDist(26, 1) = 26
naturalDist(1, 2) = 0.08167
naturalDist(2, 2) = 0.01492
naturalDist(3, 2) = 0.02782
naturalDist(4, 2) = 0.04253
naturalDist(5, 2) = 0.12702
naturalDist(6, 2) = 0.02228
naturalDist(7, 2) = 0.02015
naturalDist(8, 2) = 0.06094
naturalDist(9, 2) = 0.06966
naturalDist(10, 2) = 0.00153
naturalDist(11, 2) = 0.00772
naturalDist(12, 2) = 0.04025
naturalDist(13, 2) = 0.02406
naturalDist(14, 2) = 0.06749
naturalDist(15, 2) = 0.07507
naturalDist(16, 2) = 0.01929
naturalDist(17, 2) = 0.00095
naturalDist(18, 2) = 0.05987
naturalDist(19, 2) = 0.06327
naturalDist(20, 2) = 0.09056
naturalDist(21, 2) = 0.02758
naturalDist(22, 2) = 0.00978
naturalDist(23, 2) = 0.0236
naturalDist(24, 2) = 0.0015
naturalDist(25, 2) = 0.01974
naturalDist(26, 2) = 0.00074
Dim theText As String
Dim resultText As String
Dim i As Integer
Dim j As Integer
Form_Form4.Text0.SetFocus
theText = Form_Form4.Text0.Text
theText = Replace(theText, " ", "")
theText = Replace(theText, ",", "")
theText = Replace(theText, ".", "")
theText = Replace(theText, ";", "")
theText = Replace(theText, "'", "")
theText = Replace(theText, """", "")
theText = Replace(theText, "-", "")
theText = Replace(theText, ":", "")
theText = Replace(theText, "%", "")
theText = Replace(theText, "*", "")
theText = Replace(theText, "$", "")
theText = Replace(theText, "!", "")
theText = Replace(theText, "@", "")
theText = Replace(theText, "#", "")
theText = Replace(theText, "(", "")
theText = Replace(theText, ")", "")
theText = Replace(theText, "_", "")
theText = Replace(theText, "+", "")
theText = Replace(theText, "/", "")
theText = Replace(theText, "\", "")
theText = Replace(theText, "|", "")
theText = Replace(theText, "?", "")
theText = Replace(theText, Chr(10), "")
theText = UCase(theText)
Dim theCharDist(26, 2) As Double
For i = 1 To (Len(theText))
theCharDist(Asc(Mid(theText, i, 1)) - Asc("A") + 1, 2) = theCharDist(Asc(Mid(theText, i, 1)) - Asc("A") + 1, 2) + 1
Next i
For i = 1 To 26
theCharDist(i, 1) = i
If theCharDist(i, 2) = 0 Then
theCharDist(i, 2) = theCharDist(i, 2) / Len(theText)
Else
theCharDist(i, 2) = 1
End If
Next i
For i = 1 To 26
For j = i To 25
If theCharDist(j, 2) > theCharDist(j + 1, 2) Then
Dim tmp(2) As Double
tmp(1) = theCharDist(j, 1)
tmp(2) = theCharDist(j, 2)
theCharDist(j, 1) = theCharDist(j + 1, 1)
theCharDist(j, 2) = theCharDist(j + 1, 2)
theCharDist(j + 1, 1) = tmp(1)
theCharDist(j + 1, 2) = tmp(2)
End If
Next j
Next i
For i = 1 To 26
For j = i To 25
If naturalDist(j, 2) > naturalDist(j + 1, 2) Then
Dim tmp2(2) As Double
tmp2(1) = naturalDist(j, 1)
tmp2(2) = naturalDist(j, 2)
naturalDist(j, 1) = naturalDist(j + 1, 1)
naturalDist(j, 2) = naturalDist(j + 1, 2)
naturalDist(j + 1, 1) = tmp2(1)
naturalDist(j + 1, 2) = tmp2(2)
End If
Next j
Next i
Dim lookupTab(26, 2) As Integer
For i = 1 To 26
For j = 1 To 26
If naturalDist(j, 1) = i Then
lookupTab(i, 1) = j
End If
If theCharDist(j, 1) = i Then
lookupTab(i, 2) = j
End If
Next j
Next i
For i = 1 To (Len(theText))
resultText = resultText + Chr(Asc("A") + naturalDist(lookupTab(Asc(Mid(theText, i, 1)) - Asc("A") + 1, 2), 1))
Next i
Form_Form4.Text2.SetFocus
Form_Form4.Text2 = resultText
End Sub
Private Sub Command7_Click()
Form_Form4.Text8.SetFocus
FN$ = Form_Form4.Text8.Text
LoadTextBox FN$, Form_Form4.Text0
End Sub
|
|
|
|
|
Irshadt wrote: I used the following code to crack Caesar Cipher code where the key is unknown. I have written the following code and is it not working. I want it done in access. Plz Plz help me.
This link may be of use[^]
|
|
|
|
|
I want to crack a Caesar Cipher Code using MS Access using Frequency Distribution table established for english language. Please be kind enough to write me a code.
|
|
|
|
|
Irshadt wrote: Please be kind enough to write me a code.
Why do you think we should do your work for you? What's in it for us?
|
|
|
|
|
Yeah, but it seems obvious to me that if I DID want to write code cracking code, Access is how I'd do it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello
I'm working on a piece of code that checks for "(bla bla number) comments"
Example. If I entered "86 comments", it would return the number in front of 'comments'
My code for this line seems wrong, please help. I'm a young learner. I got a reply this morning, but it's not quite working out. Thanks!
String regex = "\\d [Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]:";
Belief is a beautiful armour.
Knowledge is the sword.
|
|
|
|
|
I answered this, why did you ask it again ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a custom object which is is a simple model with only a few strings and booleans as fields.
I would like to pass this to a web service.
Is there anyway to do this?
I currently have the class in both projects but it says
"CustomClass is not of type web_service_name.CustomClass" when I try to pass it in the consuming project.
How can i tell it they are the same class?
|
|
|
|
|
You can only use 1 definition of the class. Both the UI and the WebService needs to reference a dll that has the definition of the class. It needs to also be serializable because it will be converted to xml for the transaction
<serializable()> _
Public Class Hello
public sName as string
.
.
.
End class
|
|
|
|
|
Thanks but that has nothing to do with my problem.
They are both the same definition.
What I am trying to do is to get it to recognise that.
|
|
|
|
|
You said, that you have the class in both projects. Does both mean you have the class defined in each or referenced in each? Defined will not work, it must be referenced in each....
|
|
|
|
|
for further clarification...
it compares the object using the full assembly name
if your ui project is codeproject and your class is hello
codeproject.hello - is the full class name
if your webservice is webproject and your class is hello
webproject.hello - is the full class name
does codeproject.hello = webproject.hello ?
you think it does but the full assembly names do no match so it thinks they are different objects...
|
|
|
|
|
Exactly!!!
How can I get these to be the same?
Surely it shouldn't be too difficult to just send an object with only a couple of string in it!
|
|
|
|
|
that's what I'm talking about with referencing a dll...
create a dll (let's call it A)
put the definition of the class Hello in A
in your exe reference A
use A.Hello everywhere in your code
in you webservice reference A
use A.Hello everywhere in your code
because the full assembly name is A.hello...when you pass A.hello to your webservice it will see that A.Hello = A.Hello and accept the object as being the same...
-
|
|
|
|
|
Thanks for you help so far.
I have compiled the class into a dll and placed it into the bin directory.
Now what do I do with it?
|
|
|
|
|
i'll assume your exe and your webservice are in the same solution
add the dll project to the solution
in your exe project, do an add reference and point to the dll project
- don't move the dll to the bin when you compile the dll will come along automatically
when you compile
in your webservice project, do an add reference and point to the dll project
- don't move the dll to the bin when you compile the dll will come along automatically
when you compile
|
|
|
|
|