Solved

Easy Question

Posted on 2003-11-12
8
225 Views
Last Modified: 2010-05-01
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
Comment
Question by:learning_t0_pr0gram
8 Comments
 
LVL 4

Author Comment

by:learning_t0_pr0gram
Comment Utility
i increased points cuz i need this by tonight
0
 
LVL 6

Expert Comment

by:prasitlee
Comment Utility
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

by:learning_t0_pr0gram
Comment Utility
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

by:
monvelasquez earned 60 total points
Comment Utility
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
        List1.AddItem strNewWord
        'increase the number of undercores
        int_ = int_ + 1
     
      End If 'Len(strNewWord) >= MAX_LEN
     
    Loop 'Do Until blnMaxLenBridged
 
  Next i

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

_____________
Raymond:\>_
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Author Comment

by:learning_t0_pr0gram
Comment Utility
it works, thanks... a little different style then what i use, but i understand it, thanks man...
0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility

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)
        List2.AddItem temp2
    Next X

End Sub
-----------------------------------------------------------------------
0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
SORRY!

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

Expert Comment

by:dbrckovi
Comment Utility
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
            List2.AddItem temp2
           
            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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now