Click here to Skip to main content
16,005,037 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Easy Q:How to find the longest name(user input) in an array? Pin
Henry Minute25-Mar-09 13:11
Henry Minute25-Mar-09 13:11 
GeneralRe: Easy Q:How to find the longest name(user input) in an array? Pin
Luc Pattyn25-Mar-09 14:03
sitebuilderLuc Pattyn25-Mar-09 14:03 
GeneralRe: Easy Q:How to find the longest name(user input) in an array? Pin
Henry Minute25-Mar-09 14:14
Henry Minute25-Mar-09 14:14 
GeneralRe: Easy Q:How to find the longest name(user input) in an array? Pin
JernejR26-Mar-09 1:43
JernejR26-Mar-09 1:43 
GeneralRe: Easy Q:How to find the longest name(user input) in an array? Pin
Henry Minute26-Mar-09 1:54
Henry Minute26-Mar-09 1:54 
QuestionHow many charcters per line When Printing Pin
Ryan Fleming25-Mar-09 9:27
Ryan Fleming25-Mar-09 9:27 
AnswerRe: How many charcters per line When Printing Pin
dan!sh 25-Mar-09 9:37
professional dan!sh 25-Mar-09 9:37 
GeneralRe: How many charcters per line When Printing Pin
Ryan Fleming26-Mar-09 4:51
Ryan Fleming26-Mar-09 4:51 
I had been looking at the MeasureString method, and was not sure if there was a better way. I just want to clarify that there is not a better way to use MeasureString than the way I am doing it right now. By the way because this is a text report, I am using the Courier New font, so all characters are the same width. Code Snippet Below:

***************************************************************************************
Private Sub buildReport(ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim line As String = ""
Dim LinesIfPrinted As Int16 = 0

'Get the longest line of text in the report
For LineIndex As Int16 = 0 To strLines.Length - 1
'strLines is a text array with each line of the report
If strLines(LineIndex).Length > line.Length Then line = strLines(LineIndex)
Next

'Find Out How Many Pages
ev.Graphics.MeasureString(line, printingFont, ev.MarginBounds.Size, System.Drawing.StringFormat.GenericTypographic, CharactersPerPage, PagesToPrint)
'PagesToPrint is set to how many lines the longest text of the report is
'Thus I know how many pages this line will require.
ReDim LinesToPrint(PagesToPrint - 1, strLines.Length - 1)


'This is what I think could be more efficient. Currently I shorten the
'longest line of text by one ASCII character, until the LinesIfPrinted
'Variable is equal to 1. Than I know how many characters fit on a single
'line.
For CharIndex As Int16 = 1 To line.Length - 1
ev.Graphics.MeasureString(line.Substring(0, line.Length - CharIndex), printingFont, ev.MarginBounds.Size, System.Drawing.StringFormat.GenericTypographic, CharactersPerPage, LinesIfPrinted)
If LinesIfPrinted = 1 Then Exit For
Next

'Next I build the multidimenstional array with each line of text
'and if it is longer than CharactersPerPage I break it into separate
'pages.
<this code="" left="" out=""> End Sub
*************************************************************************************

So my question is if there is a more efficient way to determine how many characters fit on a line without using the For CharIndex as Int16 = 1....... block of code?

Thanks

Ryan
AnswerRe: How many charcters per line When Printing Pin
Dave Kreskowiak25-Mar-09 10:40
mveDave Kreskowiak25-Mar-09 10:40 
GeneralRe: How many charcters per line When Printing Pin
Tom Deketelaere25-Mar-09 23:43
professionalTom Deketelaere25-Mar-09 23:43 
GeneralRe: How many charcters per line When Printing Pin
Dave Kreskowiak26-Mar-09 4:23
mveDave Kreskowiak26-Mar-09 4:23 
GeneralRe: How many charcters per line When Printing Pin
Tom Deketelaere26-Mar-09 4:29
professionalTom Deketelaere26-Mar-09 4:29 
JokeRe: How many charcters per line When Printing Pin
Ryan Fleming26-Mar-09 4:52
Ryan Fleming26-Mar-09 4:52 
QuestionLTrim Pin
vijay248225-Mar-09 5:35
vijay248225-Mar-09 5:35 
AnswerRe: LTrim Pin
Yusuf25-Mar-09 5:43
Yusuf25-Mar-09 5:43 
GeneralRe: LTrim Pin
vijay248225-Mar-09 5:53
vijay248225-Mar-09 5:53 
GeneralRe: LTrim Pin
Dave Kreskowiak25-Mar-09 6:24
mveDave Kreskowiak25-Mar-09 6:24 
GeneralRe: LTrim Pin
vijay248225-Mar-09 23:24
vijay248225-Mar-09 23:24 
GeneralRe: LTrim Pin
Dave Kreskowiak26-Mar-09 3:36
mveDave Kreskowiak26-Mar-09 3:36 
AnswerRe: LTrim Pin
Jon_Boy25-Mar-09 6:22
Jon_Boy25-Mar-09 6:22 
QuestionFormat 34 to 034 (3 digits) Pin
grahamoj25-Mar-09 2:34
grahamoj25-Mar-09 2:34 
AnswerRe: Format 34 to 034 (3 digits) Pin
Thomas Krojer25-Mar-09 2:49
Thomas Krojer25-Mar-09 2:49 
AnswerRe: Format 34 to 034 (3 digits) Pin
Anubhava Dimri31-Mar-09 0:57
Anubhava Dimri31-Mar-09 0:57 
Questionwant to read the next line of thecomma delimited text file Pin
Lee Mwangi25-Mar-09 2:18
Lee Mwangi25-Mar-09 2:18 
AnswerRe: want to read the next line of thecomma delimited text file Pin
Tom Deketelaere25-Mar-09 2:45
professionalTom Deketelaere25-Mar-09 2:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.