Results 1 to 11 of 11

Thread: W_o_r_d

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    W_o_r_d

    Ok how would i achieve this. I have a current method but its very long.

    Code:
    Public Sub Fourletters
    
    str = Mid(Word, 1) & "_" & Mid(Word, 2) & "_" & Mid(Word, 3)& "_" & Mid(Word, 4)
    
    list1.additem str
    so i have this 16 times for each length of word. Then i have to do

    Code:
    If Len(Word) = 2 Then Call TwoLetters
    If Len(Word) = 3 Then Call ThreeLetters
    im sure there is a quicker method.

    Thanks in advance.
    Im Learning !!!!

  2. #2
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: W_o_r_d

    that's not that long, if you want you can break it up liek this:
    Code:
    Public Sub Fourletters
    
    str = Mid(Word, 1) & _
    "_" & Mid(Word, 2) & _
    "_" & Mid(Word, 3) & _
    "_" & Mid(Word, 4)
    
    list1.additem str

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: W_o_r_d

    dim newstring as string

    for x = 1 to len(oldstring)
    newstring = newstring & mid(oldstring,x,1) & " "
    next x

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: W_o_r_d

    VB Code:
    1. Private Function Splitword(strWord As String) As String
    2. For x = 1 To Len(strWord)
    3.     If x = Len(strWord) Then
    4.         Splitword = Splitword & Mid(strWord, x, 1)
    5.     Else
    6.         Splitword = Splitword & Mid(strWord, x, 1) & "_"
    7.     End If
    8. Next
    9.  
    10. End Function
    11. Private Sub Form_Load()
    12. List1.AddItem Splitword("TESTING")
    13.  
    14. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: W_o_r_d

    This seems to work:
    VB Code:
    1. str = Left$(Word, 1)
    2. For I = 2 To Len(Word)
    3.   str = str & "_" & Mid$(Word, I, 1)
    4. Next

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: W_o_r_d

    How about this:


    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox AddUnderscore("Word")
    3. End Sub
    4.  
    5. Private Function AddUnderscore(strWord As String) As String
    6. Dim strTemp As String
    7. Dim a As Long
    8.  
    9.     For a = 1 To Len(strWord)
    10.         strTemp = strTemp & Mid(strWord, a, 1) & "_"
    11.     Next a
    12.    
    13.     AddUnderscore = Left(strTemp, Len(strTemp) - 1)
    14. End Function
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: W_o_r_d

    It would seem that 2:07 PM was a very popular time for this post. Good job by all!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: W_o_r_d

    ROFL! funny thing is..
    none of the suggestions are the same!
    everyone had a slightly diff way to do it!

    (mine's the best of course... ) j/k!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: W_o_r_d

    The smallest code for this you could ever get for this:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim s As String
    3.     s = "Word"
    4.     sformat = "@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@"
    5.     MsgBox Format(s, Left(sformat, 2 * Len(s) - 1))
    6. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: W_o_r_d

    Quote Originally Posted by [A51g]Static
    ROFL! funny thing is..
    none of the suggestions are the same!
    everyone had a slightly diff way to do it!

    (mine's the best of course... ) j/k!
    And another way :
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim Str As String
    5.     Str = "Word"
    6.    
    7.     Debug.Print Left(Replace(StrConv(Str, vbUnicode), Chr(0), "-"), Len(Str) * 2 - 1)
    8. End Sub

  11. #11
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: W_o_r_d

    very nice!!
    (beats mine lol)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width