0

Ok when i was finally able to solve (with StackOverflow assistance) my arranging entries by time function, I was presented with a new issue.

It no longer followed the rules of the template i have attached to it. Not a huge problem because i thought of a quick solution but its not working.

I have added a function below, purpose:

  1. split the string passed to it -theSentence- into the array -theWords()-

  2. find out if the string -final- (do while loop adds each word from array to string one at a time) if more than 56 length

  3. if -final- is more than 56 length then add vbnewline to the string before adding next word

  4. change original string -theSentnce- to equal the created string -final- which should have a vbnewline in it after approx 56 length

.... not working need a push in the right direction probably something stupid

  Function chckLen(ByVal theSentence As String)

  Dim theWords() As String
Dim final As String
Dim arrayCntr As Integer
Dim arrayAmount As Integer
Dim chcker As Integer


 arrayCntr = 0

   theWords = Split(theSentence)
  arrayAmount = UBound(theWords)
  chcker = 56

  Do While arrayCntr <= arrayAmount

   If Len(final + theWords(arrayCntr)) > chcker Then
     final = final + vbNewLine
      final = final + theWords(arrayCntr)
     chcker = chcker + 56
   Else
     final = final + " " + theWords(arrayCntr)
   End If
         arrayCntr = arrayCntr + 1
  Loop

  theSentence = final

End Function
  • `not working` is not descriptive at all! – Maciej Los Aug 25 '15 at 07:29
  • Why are you giving `TheSentence` the `final` string? This should be given to `chcklen` if you use a Function. Otherwise it should just be a `Sub` – DragonSamu Aug 25 '15 at 07:46
  • i figured it out thanks, i ended up just taking away the byval in order to effect -theSentence- but out of curiosity and since im teaching myself all of this if i have chkLen = final will that work the same way ? – aethanskot Aug 25 '15 at 07:54
  • @aethanskot What was the issue? – DragonSamu Aug 25 '15 at 07:58
  • @dragonsamu the issue was: Function chckLen(ByVal theSentence As String) vs Function chckLen(theSentence As String) – aethanskot Aug 25 '15 at 08:03
  • What is your delimiter for the `Split` function? – Fred Aug 25 '15 at 08:04
  • @fred correct me if i am mistaken but by not designating a delimeter it uses " " as the default – aethanskot Aug 25 '15 at 08:06
  • no you are correct. Got to be honest, I didn't know that. However I do think its easier to read if you specify the delimiter even if it is the default. – Fred Aug 25 '15 at 08:09
  • thank you, i may look into adding that, the program is very compartmentalized so this is the only instance where i use this type of function but if i run into problems in the future ill know why – aethanskot Aug 25 '15 at 08:11

0 Answers0