VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This function is very usefull for Hangmand type games, where you replace a blank character (like an

by DiskJunky (16 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 4th February 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This function is very usefull for Hangmand type games, where you replace a blank character (like and asterisk * or hyphen - ), with a letter.

Rate This function is very usefull for Hangmand type games, where you replace a blank character (like an



'This function will find all occurrences of a letter
'in a word and replace the corresponding character
'in the other word, with the letter.
'eg.        AddLetter("Hello","**ll*","E")
'returnes;  "*ell*"

Dim Counter As Integer
Dim LetterPos As Integer

'if the first two parameters are not the same length
'then exit function
If (Len(ActualWord) <> Len(DisWord)) Or (Len(Letter) > 1) Then
    'exit
    AddLetter = "Error"
    Exit Function
End If

Letter = LCase(Letter)

For Counter = 1 To Len(ActualWord)
    LetterPos = InStr(Counter, LCase(ActualWord), Letter)
    
    'if the letter was found past the current
    'position, then
    If LetterPos >= Counter Then
        'display the letter in the returned value
        DisWord = Left(DisWord, LetterPos - 1) & Mid(ActualWord, LetterPos, 1) & Right(DisWord, (Len(ActualWord) - LetterPos))
        
        Counter = LetterPos
    End If
Next

AddLetter = DisWord
End Function


Download this snippet    Add to My Saved Code

This function is very usefull for Hangmand type games, where you replace a blank character (like an Comments

No comments have been posted about This function is very usefull for Hangmand type games, where you replace a blank character (like an. Why not be the first to post a comment about This function is very usefull for Hangmand type games, where you replace a blank character (like an.

Post your comment

Subject:
Message:
0/1000 characters