VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Given the first few letters of a window name, it will return the name in full. This function doesn'

by Ralph Barton (5 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 29th July 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Given the first few letters of a window name, it will return the name in full. This function doesn't even need APIs, and the returned window

Rate Given the first few letters of a window name, it will return the name in full. This function doesn'



Dim TmpStr As String

'Get user input.
TmpStr = InputBox("Please enter the start of the window text:", "Complete Title", "Works best with at least the first 3 letters.")
TmpStr = CompleteTitle(TmpStr) 'Processes the string.

AppActivate (Me.Caption) 'Bring us back to the top.
DoEvents 'Give everything a chance to slow down.
MsgBox (TmpStr) 'Show the results.

'At this point 'TmpStr' is ready to be used in a window API.
End Sub

Public Function CompleteTitle(InpStr As String) As String
Dim TmpStr As String
Dim TmpCnt As Byte
Dim OutStr As String
Dim BooBoo As Boolean

On Error GoTo NotFound

'Program Notes:
'Input is not case senstive.
'Won't find child windows.
'Won't check if the input is already the full name.
'An empty string input, will return the first window it finds.
'Only returns the first window it finds, not an array of windows.
'Returns the longest window name it finds, e.g If you have a window named 'moo', it won't find one named 'mo'.
'It searches in alphabetical order.
'Won't find windows that are not visible.

'Tells the program what characters it should look for in the window text.
'This can be changed to anything you like, currently it does space to ].
For TmpCnt = 32 To 93
TmpStr = TmpStr & Chr$(TmpCnt)
Next TmpCnt

'Adds a character at the end of the string, for the program to play with.
OutStr = InpStr & "*"

'This is the starting place in the string 'TmpStr'.
TmpCnt = 1

'Try the first bit of the text again, but with a different end character.
TryNext:

'Loop to try everything it could be.
For TmpCnt = TmpCnt To Len(TmpStr)
 Mid$(OutStr, Len(OutStr), 1) = Mid$(TmpStr, TmpCnt, 1)
 AppActivate (OutStr) 'The main command.

 If BooBoo Then
  'I tryed 'Err.Clear', but it didn't want to work.
  BooBoo = Not BooBoo
  GoTo TryNext
 End If

 'It found the string, so gets ready for the next character.
 TmpCnt = 1
 OutStr = OutStr & "*"
 GoTo TryNext
Next TmpCnt

'No more matches were found.

'Cuts of the last character.
OutStr = Mid$(OutStr, 1, Len(OutStr) - 1)

'Makes sure we have something better to put out, than came in.
CompleteTitle = StrConv(IIf(OutStr = InpStr, "not found", OutStr), vbProperCase)

'Returns the window name.
Exit Function

'This is my error handling.
NotFound:

TmpCnt = TmpCnt + 1
BooBoo = True
Resume Next
End Function

Private Sub Form_Load()
'Some helpful advise.
If App.ProductName = "" Then MsgBox ("Please compile this program for best results.")
End Sub

Download this snippet    Add to My Saved Code

Given the first few letters of a window name, it will return the name in full. This function doesn' Comments

No comments have been posted about Given the first few letters of a window name, it will return the name in full. This function doesn'. Why not be the first to post a comment about Given the first few letters of a window name, it will return the name in full. This function doesn'.

Post your comment

Subject:
Message:
0/1000 characters