![]() |
For Next statement
why is it when i use this:
Function cvText(cllText As String) For i = 1 To Len(cllText) cvText = Mid(cllText, i, 1) Next End Function .... and test it.. Print cvText("hello") o I get "o" but if I use Function cvText(cllText As String) For i = 1 To Len(cllText) cvText = Right(clltext,i) Next End Function i get: Print cvText("hello") hello i get "hello" i want to be able to loop through each character using mid(clltext,i,1) to test if there is a blank. the goal is to create a function that ucase's the beginning of each letter of a word thanks. |
For Next statement
|
For Next statement
Hi Vincent,
The function return value is whatever the last thing is that you assigned to the function name. In the first case it was the last letter of the input, in the second case it was all the letters of the input. I've modified the first function below to return the entire input string: Function cvText(cllText As String) Dim i As Long For i = 1 To Len(cllText) cvText = cvText & Mid(cllText, i, 1) Next i End Function Note that with each pass through the loop the additional character is being concatenated onto the previous characters, rather than replacing them as in the original. -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * "vincentj" wrote in message ... why is it when i use this: Function cvText(cllText As String) For i = 1 To Len(cllText) cvText = Mid(cllText, i, 1) Next End Function ... and test it.. Print cvText("hello") o I get "o" but if I use Function cvText(cllText As String) For i = 1 To Len(cllText) cvText = Right(clltext,i) Next End Function i get: Print cvText("hello") hello i get "hello" i want to be able to loop through each character using mid(clltext,i,1) to test if there is a blank. the goal is to create a function that ucase's the beginning of each letter of a word thanks. |
All times are GMT +1. The time now is 08:52 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com