Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Easy Question

Posted on 2003-11-12
Medium Priority
233 Views
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
0
Question by:learning_t0_pr0gram

LVL 4

Author Comment

ID: 9737433
i increased points cuz i need this by tonight
0

LVL 6

Expert Comment

ID: 9737476
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
0

LVL 4

Author Comment

ID: 9737500
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...
0

LVL 3

Accepted Solution

monvelasquez earned 240 total points
ID: 9737513
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:\>_
0

LVL 4

Author Comment

ID: 9737545
it works, thanks... a little different style then what i use, but i understand it, thanks man...
0

LVL 11

Expert Comment

ID: 9737604

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
-----------------------------------------------------------------------
0

LVL 11

Expert Comment

ID: 9737615
SORRY!

My example doesnt do what you asked! I'll rewrite it.
0

LVL 11

Expert Comment

ID: 9737689
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
----------------------------------------------------------------------------------
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month12 days, 14 hours left to enroll