Changing Fonts in a VB6 datareport

webstaff
01-15-2004, 06:27 AM
Hi Guys,
Can anyone advise me on this,
I want to change the fonts in a report via a command button on a form.

Section1 of the form(Detail section) has 60 RPTlabels names lbl1-lbl60

When i open the common dialog i want to pick a new style of font and get the report to reflect the change.

So far im not getting it, my code generated the Object doesnt support the properties.
My code is
<vb>
Private Sub Command6_Click()
' show font dialog
With CommonDialog1
.Flags = cdlCFScreenFonts
.ShowFont
End With

For Each RptLabel In DataReport1
With RptLabel.Font
.Bold = CommonDialog1.FontBold
.Italic = CommonDialog1.FontItalic
.Size = CommonDialog1.FontSize
.Name = CommonDialog1.FontName
End With
Next
DataReport1.Refresh
DataReport1.Show
End Sub
</vb>

Thanks in advance for any suggestions
W

Dennis DVR
01-15-2004, 06:40 AM
Dim i as integer
Dim ob as object
for i = 0 to datareport1.sections.count - 1
for each ob in datareport1.sections(i).controls
if typeof ob is rptLabel then
ob.Font.Name = etc
etc
etc
end if
next
next

and if you want to change the font size of the datareport you should change the default font size at design time before changing it at runtime coz using the default value which is 8 the datareport wont change the font size so try setting it to 9 at designtime

webstaff
01-15-2004, 06:50 AM
This line gives me Subscript out of range error?

For Each ob In DataReport1.Sections(i).Controls

any ideas?

Thanks again

MKoslof
01-15-2004, 07:03 AM
Well, I don't believe Duane meant to code it like this...you don't want the count within a For Each loop:...you want to loop within the controls of the object.



For I = 0 To datareport1.Sections.Count - 1
For Each ob In datareport1.Sections(i).controls
If TypeOf ob Is rptLabel Then
ob.Font.Name = etc
etc
etc
End If
Next
Next



PS:= Actually, the problem here is, I believe the sections().controls index starts at 1, so the index of 0 is not valid

MKoslof
01-15-2004, 07:10 AM
you should probably initially try this instead:




For Each ob In datareport1.Sections("Section 1").controls
If TypeOf ob Is rptLabel Then
ob.Font.Name = etc
etc
etc
End If
Next



this will loop all controls within Section 1. I am not *Very* familiar with data Reports..but I believe your intial issue is your array is starting or ending at an invalid index....again, the section/control index may start at one.

webstaff
01-15-2004, 07:11 AM
Thats it thanks, Its my foolishnes in naming the labels without starting with zero.
Many Many thanks.

PS:= Actually, the problem here is, I believe the sections().controls index starts at 1, so the index of 0 is not valid[/QUOTEPOST]

MKoslof
01-15-2004, 07:12 AM
;) ..Gotcha..Good luck!

Dennis DVR
01-15-2004, 07:27 AM
I'm sorry i got busy, ow man i missed a lot :chuckle: but at least mkslof assisted you and you got it working.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum