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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Report / Problem assigning a Percentage in Textbo (DataField) 1

Status
Not open for further replies.

herjari

Programmer
Nov 27, 2002
12
0
0
AR
Dear friends,

I'm having the following problem and had tried to find an answer unsuccesfully for the last week.

I have a Data Report that contains one percentage value. The query that I made sends me "94,0073844" as answer.

PLEASE, can someone help and tell me how can I format this information to be shown as "94,07 %" in the textbox?

Thank you very very much for your answers... I'm really lost about this one...

Hernan
 
Multiply the variable by 100 to get rid of the decimal
num=num*100
a$=left$(str$(num),5)
94007
make it a string, 5 characters long
a$=left$(a$,5)

get the value of the right most digit and the second digit from the right. Test for rounding.

Put it all back together again using as a string.

a$=left$(num$,2)+"."+mid$(num$,3,1)+trim(str$(rounded$))+"%"
textbox.text=a$
 
You can use the Round Function.
It returns a number rounded to a specified number of decimal places.

Syntax
Round(expression [,numdecimalplaces])

If no decimal places are specified, the function returns an integer.

So you could do:
Num = Round(Num, 2)
which would turn 94,0073844 into 94,01.

Merlijn is the name, and logic is my game...
 
Thank you both but the problem is that the report -textboxes are different from the regular ones.

They don´t have the Format method (or at least I didn´t find out the correct way of using it...)

I´m going to paste a part of my code to see if I can help anyone to understand my problem...

Here I´m filling in the rpttextbox...

With .Controls("text2")
.Visible = 1
.DataField = "temporal"
.Format = Format("IndGenerico.sections(Section1).Controls(text2)", "####.##" & " %")
.Width = 1110
.Left = 1010
.Top = 50
End With

And when I do this, I´m receiving an error 438, "Object doesn´t support this properthy or method"

Please, anyone can give me a suggestion?

Best wishes and thanks in advance,

Hernan
 
In Datareport design view, select the rptText that you want to format. In the properties window, select dataformat then Custom and use ##.00% as the format string


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thank you very very much!

I can go to bed with a smile in my face now... ;)

Hernan
 
Dear Johnwm,

Now, I have one more question. Do you know if there is any way that I can change the DataFormat during run time and not at design time?

Thanks in advance,

Hernan
 
Sorry I haven't found a way to do that


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thank you very much anyway.

I have been trying to find a way to modify the textbox to Custom during run-time for several days and forgot that I still was able to make it at design time.

I will have to add 9 extra textboxes to my report... but that isn't that bad anyway...

Hernan
 
Dear John,

Look what I've found!! It worked perfectly!

.DataFormat.Type = fmtGeneral
.DataFormat.Format = "#0.00 \%"

Hernan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top