Results 1 to 4 of 4

Thread: random 4 letters with condition

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    2

    random 4 letters with condition

    i dont knw were to put this i hope some one can help me.. i need a code for this:


    i am to create a program that generates 4 random letters.
    conditions : a letter must not repeate twice
    : there must always be a vowel


    Pls help.. i knw this is easy,, i just cant find a code.. thanx..

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Welcome to the Forums.

    Do you mean four letters as in documents or letters as in four
    characters (a, b, c, d)?

    Can you show us a smaple of what you need?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    2
    here is the example

    the program generates 4 letters that has a vowel

    ex. asdf
    lkji


    as long as there is a vowel and no letter is repeated tiwce..

  4. #4
    Junior Member
    Join Date
    Sep 2004
    Location
    Hamburg / Germany
    Posts
    20
    Hi,

    may be this code will help you:

    VB Code:
    1. Function FourLetters() As String
    2.  
    3.   Dim cnt As Integer
    4.   Dim myCharStr As String
    5.   Dim newChr As String
    6.  
    7.   Randomize
    8.  
    9.   Do Until vowelIn(myCharStr)
    10.     myCharStr = RandomCharacter
    11.     For cnt = 2 To 4
    12.       Do
    13.         newChr = RandomCharacter
    14.       Loop Until InStr(myCharStr, newChr) = 0
    15.       myCharStr = myCharStr & newChr
    16.     Next cnt
    17.   Loop
    18.   FourLetters = myCharStr
    19. End Function
    20.  
    21. Private Function RandomCharacter() As String
    22.   RandomCharacter = Chr(Asc("a") + Rnd * 26)
    23. End Function
    24.  
    25. Private Function vowelIn(myCharStr) As Boolean
    26.   Dim i As Integer
    27.   vowelIn = (InStr(myCharStr, "a") > 0) Or _
    28.             (InStr(myCharStr, "e") > 0) Or _
    29.             (InStr(myCharStr, "i") > 0) Or _
    30.             (InStr(myCharStr, "o") > 0) Or _
    31.             (InStr(myCharStr, "u") > 0)
    32. End Function
    Last edited by zeneri; Sep 27th, 2004 at 11:21 AM.

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