Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB 5 - no Round fcn?

Status
Not open for further replies.

KerryC

Technical User
Apr 9, 2002
36
CA
This is probably the dumb question of the week, but...

I need to write a user defined function for Crystal Reports so I installed a copy of VB5 that we had floating around. When I try to use the Round() function I get a Function not defined error, and I can't find the function in the online help. Was there no Round() function in VB version 5???

Kerry
 
Under VB5, I believe the Round function (and the IIf function) were actually in another DLL that you had to include with your program. Since it's been 7 years since I used vb5, I've forgotten which DLL it was, but maybe you can google for it now.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You don't need to use VB in order to write user defined functions for Crystal reports. There is built in functionality in Crystal to allow you to write functions. I would suggest that you check the Crystal documentation.

VBrit
 
Hello Kerry,

I experienced the problem with the lacking round function, when my VB-code was running on a computer with (a dutch version of) Windows 97.

I used the following trick to deal with it.

Put the number in a worksheet cell. (f.i. "A1" on sheet1)
Format the cell with the number of decimals you need.
Format another cell as text. (f.i. "A2")
Use the following code to round your number:

set sh1 = Workbooks(ThisWorkbook.Name).Sheets("Sheet1")

sh1.Cells(1,1)= myNumber
sh1.Cells(1,2)= sh1.Cells(1,1).Text
myRoundedNumber = Cstr(sh1.Cells(1,2))
MsgBox myRoundedNumber

Good luck,

Rudo
 
Well, it looks like I'm out of luck, for now anyway. I did do some googling and indeed there was no round function until Visual Basic 6. As to using it from another dll, I couldn't find any mention of that. Also unfortunately we don't have Excel on the machines where I need to use this function so I guess the suggested worksheet workaround is out as well - arghh!

Crystal Reports 9 does indeed have functionality to create custom functions without using visual basic, but unfortunately it's Crystal V8.5 I'm stuck with right now and it doesn't look like it has that functionality. We're in the process of moving up to V9 so soon I'll be able to take this route.

Anyway, thanks for all the suggestions - I guess I'll sit tight at the moment and wait for some software upgrades to happen first.

Thanks again,
Kerry
 
rudo,
That looks like Excel not VB!

Kerry,
Basic 101:
Public Function myRound(myDouble As Double, myDigits As Integer) As Double
Dim exp As Long
exp = 10 ^ (myDigits)
myRound = (myDouble * exp) + 0.5
myRound = Int(myRound) / exp
End Function


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
John, that explains it - I didn't take Basic 101 :)

Thanks for this - should do the job.

Kerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top