|
In the early '80s, a friend wrote an application on an 8 bit machine to calculate PI to the nth decimal place. Obviously, the floating point accuracy of an 8 bit machine would not suffice, so, he stored his data in character strings and manually performed the necessary calculations one column at a time. Assuming you have a formula or some other such means, use character strings and arrays.
Enjoy!
Tim
|
|
|
|
|
I am looking some thing like PI calculations
I tried it in the following way. Write a method for userdefined datatype and then use the operator overloading concept for operators(+,-,*,/) to perform arthmatic calculations with that new data type.
Public Function UDDouble(ByVal strDouble As String, ByVal intScale As Integer) As String
'Dim obj As String = "1.12345678903322112233"
Try
Dim strTemp As String() = New String(intScale) {}
Dim temp3 As String = ""
If strDouble.Contains(".") Then
Dim temp1 As String = strDouble.Split(".")(0)
Dim temp2 As String = strDouble.Split(".")(1)
If intScale > temp2.Length Then
For i As Integer = 0 To temp2.Length - 1
temp3 += temp2(i)
Next
For j As Integer = temp2.Length To intScale
temp3 += "0"
Next
Else
For i As Integer = 0 To intScale - 1
temp3 += temp2(i)
Next
End If
temp1 = temp1 + "." + temp3
Return temp1
Else
Return strDouble
End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Function
Dim arr1 As Double() = {2, 2, 7}
Dim arr2 As Double() = {1, 2, 8}
Dim arr3 As Double() = {0, 0, 0}
Dim carry As Integer
Dim borrow As Integer
Dim chrOperator As Char
Dim holdDigit As Integer
Select Case chrOperator
Case "+"
For i As Integer = 2 To 0 Step -1
'for addition
holdDigit = arr1(i) + arr2(i) + carry
carry = holdDigit \ 10
arr1(i) = holdDigit Mod 10
Next
Case "-"
For i As Integer = 2 To 0 Step -1
'for substraction
holdDigit = arr1(i) - arr2(i) + 10
borrow = holdDigit \ 10
arr1(i) = holdDigit Mod 10
If i = 0 And borrow = 0 Then
Throw New Exception("2nd number larger than first one")
Else
If (borrow = 0) Then arr1(i - 1) -= 1
End If
Next
Case "*"
For i As Integer = 2 To 0 Step -1
'For Multiplication
holdDigit = (arr1(i) * 128) + carry
carry = holdDigit \ 10
If i = 0 Then
arr1(i) = holdDigit
Else
arr1(i) = holdDigit Mod 10
End If
Next
Case "/"
'for Division
For i As Integer = 0 To 2
holdDigit = arr1(i) + borrow * 10
arr1(i) = holdDigit \ 128
borrow = holdDigit Mod 128
Next
End Select
Can some one let me know wether this approach is correct or not? If not please let me know the best possible way to do this.
Ram
|
|
|
|
|
Hi
i wants to create(Write) file in selected font, can i have any idea?
Hitesh sojitra
|
|
|
|
|
No, you can not.
Plain text files do not contain any information regarding formatting like font size, color, margin etc...
|
|
|
|
|
|
I believe, he is looking for .txt and not .rtf
|
|
|
|
|
Oooh, yeah. You're right.
|
|
|
|
|
Hi,
How i findout the total number of repitation of strings in an string array
please give me suggestion that how i do that.
i have stored strings in an array and now i have to findout how many times it repeates in an array.
Regards
Rameez
|
|
|
|
|
Please don't cross post.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Your asked essentially the same question 7 hours ago... try to work it out for yourself.
Write it out on paper and work through the problem.
|
|
|
|
|
<br />
Dim Count as Integer<br />
For each i in MyArray<br />
if i.contains = "YourString" then<br />
count += 1<br />
next<br />
Something like that?
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" - ALbert Einstein
I look at Microsoft, and turn to my poster on the wall saying: "Bang head here in case of stress".
|
|
|
|
|
Can anyone please tell me how to integrate VB.Net codes into powerbuilder in order to run one application
modified on Tuesday, August 12, 2008 8:46 AM
|
|
|
|
|
Do you think any body has this much time to read your code.
Please be specific of your requirement
|
|
|
|
|
Hi
I want to make a formula builder, in which user can take his own variable and by using that variable he can make his own formula and can check it whether its valid or not and when he enter a value for specific variable then he can get result.Its basically used in Payroll System
Like
if user takes one variable 'X' and make a formula like (X/24)-1
now when user select a different value for X then he can get result
modified on Wednesday, August 13, 2008 1:23 AM
|
|
|
|
|
OK - sounds like fun. Do you have a specific question ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I want to check whether a given text File is Already Opened or not. I am using Visual Basic 6.0 in the Windows XP OS.
I am using the following code. It works for .doc, .xls and .mdb. But its not working for .txt file type
Code:
--------
Public Function IsFileOpen(FileName As String) As Boolean
On Error GoTo ErrHandler
Open FileName For Binary Access Read Lock Read As #1
MsgBox Input$(LOF(1), #1)
Close #1
Exit Function
ErrHandler:
MsgBox "File is Already Opened"
End Function
|
|
|
|
|
Hi,
Try the following code:
BEGIN CODE
Try
Dim fs As FileSream = File.OpenWrite(strFileName)
If(fs == null) Then
// your Code
End If
Catch e As UnauthorizedAccessException e
/The file is open by another app
End Try
ENE CODE
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
The code will work, so long as the other app keeps the file open. For instance, Notepad does NOT do this. It opens the file, reads the entire contents, then closes it. Only then do you get to the see the text in Notepad. There is no way to tell if this has happened or not...
|
|
|
|
|
i need theway how to use dataset in web page to fill crystal report and run it
i tried to load data on dataset after that call that dataset from project in crystal report (ado.net) database so can any one help me please
|
|
|
|
|
We have an ASP.NET forum.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I have a group box called box. I would like to create a label (label1) that I want to create in runtime and add it to the group box. How do I go about doing that?
I can create it in runtime just fine. I just can't seem to get it to be inside the group box.
Thanks in advance.
|
|
|
|
|
box.Controls.Add(myNewLabelThatIJustCreated);
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I have done some searching and can't find the answer to this one anywhere.
I have a multiline textbox on a form that shows 2 lines of text on the form. I have restricted it to 200 chars because the report page that it prints on can display 200 chars in 2 lines. My problem is users can press return as many times as they want and put as many lines of text in the box as is possible before they use the 200 chars. Since the report will recognize a CRLF character and move the text to the next line if they put more than 2 lines of text in the multiline text box only 2 of those lines of text will print no matter what. They are wanting to restrict the data entry box so that only 2 lines of text can be entered even if the character count is less that 200. Is there a way to do this?
I'm coding in VB.net with Visual Studio 2005 and using Crystal Reports XI for my report. I can't manipulate the report side of things to print more than 2 lines because the way the report is laid out there is no room.
Thanks in advance to anyone who can help.
Judy
|
|
|
|
|
1. Count the number of CRs in the textbox.text and beat on the user if there is more than 1
2. Use the keydown/up events to interactively manage the characters typed into the textbox.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks. I was getting to that I just was wondering if perhaps there was a setting I had missed.
This points me in the right direction.
If the beatings worked I wouldn't need to do this. LOL
Judy
|
|
|
|