# Easy Question

I'm tired and my brain just can't seem to figure this out.. what i want it to do is:

you have a list of words loaded in a list box:

word1
word2
word3
word4
ect...

what i want it to do is add
w_o_r_d_1
w__o__r__d__1
w___o___r___d___1

ect.. i want the length to go no higher then 32, and then likewise for the rest of the words in the list...

i can't seem to figure out how to get it to stop at a length of no higher then 32 and i'm sick of trying it... help?

Thanks
LVL 4
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
i increased points cuz i need this by tonight
Commented:
Dear learning_t0_pr0gram,
Just use the function len() to check if your word lenght is greater than 32 or not.
And use the function mid() to get the 33rd Character to the last character in the word.
I would give you the sample code as following.

strWord = "w___o___r___d___1"
If len(strWord) > 32 then
strRemainingChars = mid(33,strWord)
end if

If you still need any help, please let me know.
Meng
Author Commented:
ya but if i got 130 words in the list, that would be a lot to type, isn't there a shorter way of doing it?

here is the code i use to make it w_o_r_d_1

For w = 0 To Len(Text4.Text) - 2
Text4.Text = Left(Text4.Text, v) & "_" & Mid(Text4.Text, v + 1, Len(Text4.Text))
v = v + 2
Next

and to tell it to do it for each item

for x = 0 to list1.listcount - 1

i just can't get it to stop at 32 characters...
Commented:
I have a piece of code here... i'm not sure what you want to do with the generated
words but in here i added them to the list...

--[CODE]--------------------------------------------------------------------------------------

Const MAX_LEN = 32

Dim i, j As Integer               ' just some looping variables
Dim intWordCount As Integer       ' total number of initial words
Dim strCurrentWord As String      ' current word in process
Dim int_ As Integer               ' number of underscores to insert
Dim strNewWord As String          ' new word to insert
Dim blnMaxLenBridged As Boolean   ' flag checking if the max lenght was reached

' Get the initial list of words
intWordCount = List1.ListCount

' loop through the words
For i = 0 To intWordCount - 1

' get the current word
strCurrentWord = List1.List(i)

int_ = 1   ' number of underscores to insert
blnMaxLenBridged = Len(strCurrentWord) >= MAX_LEN  ' check if the length > 32

'check for maximum length
Do Until blnMaxLenBridged

' start inserting underscores
strNewWord = Left(strCurrentWord, 1)      ' start the new word with the first character
For j = 2 To Len(strCurrentWord)
strNewWord = strNewWord & String(int_, "_") & Mid(strCurrentWord, j, 1)
Next j

' check the length
If Len(strNewWord) >= MAX_LEN Then

' tell that the max length was reached
blnMaxLenBridged = True

Else

' add the new word to the list
'increase the number of undercores
int_ = int_ + 1

End If 'Len(strNewWord) >= MAX_LEN

Loop 'Do Until blnMaxLenBridged

Next i

--[/CODE]-------------------------------------------------------------------------------------

_____________
Raymond:\>_

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
it works, thanks... a little different style then what i use, but i understand it, thanks man...
Commented:

You have to calculate Expected word length before you add lines to it.
Formula for doing this is:

Spaces = X                                                       'Number of underscores that have to be put between each two chars
CharsNumber = Len(Text)                                  'Number of characters in a string
Betweens = CharsNumber - 1                             'Number of "betreens" - (places between characters where you put underscores

ExpectedLength = Charsnumber + Betweens * Spaces

Try this example:  (It does not use your algorythm for adding underscores)

-------------------------------------------------------------------
Private Sub Command1_Click()
Dim temp As String, temp2 As String
Dim spaces As Integer
Dim ExpectedLength As Integer

For X = 0 To List1.ListCount - 1
spaces = X + 1
temp = List1.List(X)
temp2 = ""

ExpectedLength = Len(temp) + (Len(temp) - 1) * spaces
If ExpectedLength > 32 Then Exit Sub
For Y = 1 To Len(temp)

Select Case spaces
Case 1
temp2 = temp2 & Mid(temp, Y, 1) & "_"
Case 2
temp2 = temp2 & Mid(temp, Y, 1) & "__"
Case 3
temp2 = temp2 & Mid(temp, Y, 1) & "___"
Case 4
temp2 = temp2 & Mid(temp, Y, 1) & "____"
Case 5
temp2 = temp2 & Mid(temp, Y, 1) & "_____"
Case 6
temp2 = temp2 & Mid(temp, Y, 1) & "______"
Case 7
temp2 = temp2 & Mid(temp, Y, 1) & "_______"
End Select
Next Y
temp2 = Mid(temp2, 1, Len(temp2) - spaces)
Next X

End Sub
-----------------------------------------------------------------------
Commented:
SORRY!

My example doesnt do what you asked! I'll rewrite it.
Commented:
This is it!

Add two listboxes, and a button, and paste this:

-----------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
Dim temp As String, temp2 As String
Dim spaces As Integer
Dim ExpectedLength As Integer
Dim SpaceString As String

SpaceString = "_____________________________________________________"       'Used to extract the right number of backscores

For X = 0 To List1.ListCount - 1                                            'Get every word from list1
temp = List1.List(X)

spaces = 1                                                              'Theese 3 lines are used to prevent
ExpectedLength = Len(temp) + (Len(temp) - 1) * spaces                   'proccessing a word which would have more than
If ExpectedLength > 32 Then GoTo skip                                   '32 chars after first pass

Do
temp2 = ""
For Y = 1 To Len(temp)                                               'Add spaces after each character
temp2 = temp2 & Mid(temp, Y, 1) & Mid(SpaceString, 1, spaces)
Next Y

temp2 = Mid(temp2, 1, Len(temp2) - spaces)                           'Remove underscores after the last char

spaces = spaces + 1

ExpectedLength = Len(temp) + (Len(temp) - 1) * spaces                    'Calculate expected length before next pass
If ExpectedLength > 32 Then GoTo skip

Loop While ExpectedLength < 32
skip:
Next X

End Sub
----------------------------------------------------------------------------------
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.