Jump to content

search as you type but with a twist


bimini07
 Share

Recommended Posts

Hi Gurus,

I am a newbie at this and don't even know if this is possible or not. A while back while searching I found some excellent code written by someone on this forum. This code is an example on how to search as you type. It references a txt file data.txt which it loads in a list box and lets you search as you type. What I want to do is to be able to use files in a directory for the listing instead of a text file... and then once the right file in the list is found to be able to double click it to execute it. Obviously a yes/no box before I can execute the file just to make sure the right file was clicked? Is it possible? and if so how? With a work schedule of 60 to 70 hrs a week it will take me quite a while to figure this out so hence I am turning to you all for help... Thank you in advance...

Here is the original code:

This is my second time posting only so forgive me if I mess up in attaching the original code:

CODE
#include

Dim $buffer

$data = StringReplace(FileRead("data.txt"), @CRLF, "|")

Opt("GUIDataSeparatorChar", "|")

$split = StringSplit($data, "|")

GuiCreate("Search as typing", 179, 336,-1, -1)

$input = GuiCtrlCreateInput("", 10, 10, 160, 20)

$list = GUICtrlCreateList("", 10, 40, 160, 271)

GuiCtrlSetData($list, $data)

$case = GUICtrlCreateCheckbox("Case sensitive", 10, 311, 160, 20)

GuiSetState()

While 1

$msg = GuiGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exit

If GuiCtrlRead($input) <> "" Then

$savetext = GuiCtrlRead($input)

For $i = 1 to $split[0]

If GuiCtrlRead($case) = $GUI_CHECKED Then

If StringLeft($split[$i], StringLen(GuiCtrlRead($input))) == $savetext Then

$buffer &= $split[$i] & "|"

EndIf

Else

If StringLower(StringLeft($split[$i], StringLen(GuiCtrlRead($input)))) == StringLower($savetext) Then

$buffer &= $split[$i] & "|"

EndIf

EndIf

Next

$buffer = StringTrimRight($buffer, 1)

GuiCtrlSetData($list, "")

GuiCtrlSetData($list, $buffer)

$buffer = ""

;========================================GUI Main Loop========================================

Do

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case Else

;;;

EndSelect

Until GuiCtrlRead($input) <> $savetext

;============================================GUI Main Loop End=====================================================

If GuiCtrlRead($input) = "" Then

GuiCtrlSetData($list, "")

GuiCtrlSetData($list, $data)

EndIf

EndIf

WEnd

data.txt

Link to comment
Share on other sites

What I want to do is to be able to use files in a directory for the listing instead of a text file... and then once the right file in the list is found to be able to double click it to execute it. Obviously a yes/no box before I can execute the file just to make sure the right file was clicked? Is it possible? and if so how? With a work schedule of 60 to 70 hrs a week it will take me quite a while to figure this out so hence I am turning to you all for help... Thank you in advance...

Since I only work 75 to 80 hours a week I'll help you out.

Replace

$data = StringReplace(FileRead("data.txt"), @CRLF, "|")

with

$SearchFolder = @ScriptDir
$runType = '.au3'
$search = FileFindFirstFile($SearchFolder & '\*.*')
$data = ''

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $attr = FileGetAttrib($file)
    If Not @error And StringInStr($attr, 'D') = 0 And StringRight($file, StringLen($runType)) = $runType Then
        $data = $data & '|' & $file
    EndIf
WEnd

FileClose($search)

$data = StringLeft($data,StringLen($data) - 1);remove last separator
$data = StringRight($data,StringLen($data) - 1);remove first separator

;MsgBox(0,'',$data)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Since I only work 75 to 80 hours a week I'll help you out.

Replace

$data = StringReplace(FileRead("data.txt"), @CRLF, "|")

with

$SearchFolder = @ScriptDir
$runType = '.au3'
$search = FileFindFirstFile($SearchFolder & '\*.*')
$data = ''

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $attr = FileGetAttrib($file)
    If Not @error And StringInStr($attr, 'D') = 0 And StringRight($file, StringLen($runType)) = $runType Then
        $data = $data & '|' & $file
    EndIf
WEnd

FileClose($search)

$data = StringLeft($data,StringLen($data) - 1);remove last separator
$data = StringRight($data,StringLen($data) - 1);remove first separator

;MsgBox(0,'',$data)
:D ... LOL!!! I thought I was the only nut that worked long hours every week. My hats off to you for being able to work that long and being able to master AutoIT!!!

Can you also please provide help with the double click event... How would I go about executing the double click event as such that when someone double clicks on the searched item (file in the script directory) it gets executed?

Thanks...

Link to comment
Share on other sites

:D ... LOL!!! I thought I was the only nut that worked long hours every week. My hats off to you for being able to work that long and being able to master AutoIT!!!

Can you also please provide help with the double click event... How would I go about executing the double click event as such that when someone double clicks on the searched item (file in the script directory) it gets executed?

Thanks...

Searching would probably find this but I haven't got time for such things :D .
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 2 weeks later...

O.K stuck again

The double click function works fine. I can call a message box and it will show me the list item that was clicked on... but when I try to use the run command to call a config file (config file being the double clicked file) VNC says it can't find the config file.

How do I fix this? Please help... thanks..

A little summary on the program:

VNC supports config files. We have 2000 machines that we vnc into. The whole idea behind this is to let the end user search for the config file... double click on the config file... and in turn launch the vnc program with that specific config file.

Thanks,

Here is the code:

#include <GuiConstants.au3>
#Include <GuiListView.au3>
Dim $buffer
$SearchFolder = @ScriptDir
$runType = '.vnc'
$search = FileFindFirstFile($SearchFolder & '\*.*')
$data = ''

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $attr = FileGetAttrib($file)
    If Not @error And StringInStr($attr, 'D') = 0 And StringRight($file, StringLen($runType)) = $runType Then
        $data = $data & '|' & $file
    EndIf
WEnd

FileClose($search)

;$data = StringLeft($data,StringLen($data) - 1);remove last separator
$data = StringRight($data,StringLen($data) - 1);remove first separator

;MsgBox(0,'',$data)
Opt("GUIDataSeparatorChar", "|")
$split = StringSplit($data, "|")
GuiCreate("Search as typing", 179, 336,-1, -1)
$input = GuiCtrlCreateInput("", 10, 10, 160, 20)
$list = GUICtrlCreateList("", 10, 40, 160, 271)
GuiCtrlSetData($list, $data)
$case = GUICtrlCreateCheckbox("Case sensitive", 10, 311, 160, 20)
GuiSetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If GuiCtrlRead($input) <> "" Then
    $savetext = GuiCtrlRead($input)
    For $i = 1 to $split[0]
        If GuiCtrlRead($case) = $GUI_CHECKED Then
            If StringLeft($split[$i], StringLen(GuiCtrlRead($input))) == $savetext Then
            $buffer &= $split[$i] & "|"
        EndIf
            Else
        If StringLower(StringLeft($split[$i], StringLen(GuiCtrlRead($input)))) == StringLower($savetext) Then
            $buffer &= $split[$i] & "|"
        EndIf
        EndIf
    Next
    $buffer = StringTrimRight($buffer, 1)
    GuiCtrlSetData($list, "")
    GuiCtrlSetData($list, $buffer)
    $buffer = ""
   ;========================================GUI Main Loop========================================
    Do
        $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case Else
       ;;;
    EndSelect
Until GuiCtrlRead($input) <> $savetext
;============================================GUI Main Loop End=====================================================
If GuiCtrlRead($input) = "" Then 
    GuiCtrlSetData($list, "")
    GuiCtrlSetData($list, $data)
    EndIf
        EndIf
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($list) Then $hWndListBox = GUICtrlGetHandle($list)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF); Low Word
    $iCode = BitShift($iwParam, 16); Hi Word

    Switch $hWndFrom
        Case $list, $hWndListBox
            Switch $iCode
   Case $LBN_DBLCLK; Sent when the user double-clicks a string in a list box
     $n = GUICtrlRead($list)
        Run ("C:\Program Files\RealVNC\VNC4\VNCVIEWER.EXE -config ($n)", "", @SW_MINIMIZE)
       Msgbox(0, "The selected vnc config file is:", GUICtrlRead($list))
            EndSwitch
    EndSwitch
EndFunc  ;==>WM_COMMAND
Link to comment
Share on other sites

just looking at the code I noticed you're not giving the path to the .vnc file

and I think that's the whole problem

just trying the run command from your script failed for me unless I added the path also

edit:

I just tried this and it's still not working but I have some time to kill so i'll keep at it and try and figure it out

Msgbox shows the full path to file, so don't know why it don't work

ultravnc cmd line uses / instead of - but otherwise the same

Run ("E:\Internet\UltraVNC\vncviewer.exe /config " & @ScriptDir & "\" & $n, "", @SW_MINIMIZE)
       Msgbox(0, "VNC Config File", "The selected vnc config file is: " & @ScriptDir & "\" & $n, 0)oÝ÷ Ù·Ý¿nØb±Ú³
+'íêÞj·§¢ÊZqë"Ø^¥«a¡ûazùÜ~)^±©Ýº[k¾wj{¬yÊ'~((¯÷(ø ÖÞv+wý¼R¢wmºÇºW§¢è!¶­!×׶譺x¯z»¼¡jø§+e¢¢»çrøÁêÞÅ觶«z¬¶¼ºÚ"µÍH ÌÍÝÝY]ÙHYÔXY
    ][ÝÒÑVWÓÐÐSÓPPÒSIÌLÔÓÑÐTIÌLÓZXÜÜÛÙ   ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[ÛÌLÐ]ÉÌLÝÝY]Ù^I][ÝË  ][ÝÉ][ÝÊB[
    ÌÍÝÝY]Ù    [È ][ÝÈXÛÛYÈ  ][ÝÈ  [ÈØÜ [È ][ÝÉÌLÉ][ÝÈ   [È ÌÍÛ  ][ÝÉ][ÝËÕ×ÓRSSRVJ
Edited by CWorks
Link to comment
Share on other sites

just looking at the code I noticed you're not giving the path to the .vnc file

and I think that's the whole problem

just trying the run command from your script failed for me unless I added the path also

edit:

I just tried this and it's still not working but I have some time to kill so i'll keep at it and try and figure it out

Msgbox shows the full path to file, so don't know why it don't work

ultravnc cmd line uses / instead of - but otherwise the same

Run ("E:\Internet\UltraVNC\vncviewer.exe /config " & @ScriptDir & "\" & $n, "", @SW_MINIMIZE)
       Msgbox(0, "VNC Config File", "The selected vnc config file is: " & @ScriptDir & "\" & $n, 0)oÝ÷ Ù·Ý¿nØb±Ú³
+'íêÞj·§¢ÊZqë"Ø^¥«a¡ûazùÜ~)^±©Ýº[k¾wj{¬yÊ'~((¯÷(ø ÖÞv+wý¼R¢wmºÇºW§¢è!¶­!×׶譺x¯z»¼¡jø§+e¢¢»çrøÁêÞÅ觶«z¬¶¼ºÚ"µÍ  ÌÍÝÝY]ÙHYÔXY
    ][ÝÒÑVWÓÐÐSÓPPÒSIÌLÔÓÑÐTIÌLÓZXÜÜÛÙ   ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[ÛÌLÐ]ÉÌLÝÝY]Ù^I][ÝË  ][ÝÉ][ÝÊB[
    ÌÍÝÝY]Ù    [È ][ÝÈXÛÛYÈ  ][ÝÈ  [ÈØÜ [È ][ÝÉÌLÉ][ÝÈ   [È ÌÍÛ  ][ÝÉ][ÝËÕ×ÓRSSRVJ

Thanks for your help Cworks.... but If I use the RegRead and execute the script it errors out with unable to execute external program... The system cannot find the file specified.. But If I hardcode the path to vncviewer then everything works fine.

I looked into the registry and the vncviewer.exe app path actually doesn't exist for me. I did a search and found it in the shell open command entry... so I modified it with the following:

$vncviewer = RegRead("HKEY_CLASSES_ROOT\Applications\vncviewer.exe\shell\open\command", "")
$vncpath = StringTrimRight($vncviewer, 12)

And then used the following:

Run ($vncpath & " -config " & @ScriptDir & "\" & $n, "", @SW_MINIMIZE)

And this seems to work for me...

I have a few questions though...

Just curious if it is possible to make this app work with spaces in the path to .vnc file?

Also... can you guide me on how to minimize the current gui window? Meaning whenever you double click on vnc file to execute it... VNC software runs in the background with the gui window still showing up front... how do you minimize the main gui window within this script?

Thanks...

Another thing I just realized is that if the vnc file listes has spaces in its name then it will not execute.... for example if I use test.vnc then it works, but If I use copy of test.vnc then it will not execute b/c of the spaces.

Thanks...

Edited by bimini07
Link to comment
Share on other sites

o.k I think I got the minimize part down:

$hMyGUI = GuiCreate("Search as typing", 179, 336,-1, -1)

WinSetState($hMyGUI, '', @SW_MINIMIZE)
Run ($vncpath & " -config " & @ScriptDir & "\" & $n, "", @SW_MAXIMIZE)

Is this the right way of doing this?

Thanks

Edited by bimini07
Link to comment
Share on other sites

Ok no problem with spaces anymore for config file or viewer

$c_file = GUICtrlRead($list)
     $c_file = FileGetShortName(@ScriptDir & "\" & $c_file)
        $vncviewer = RegRead("HKEY_CLASSES_ROOT\Applications\vncviewer.exe\shell\open\command", "")
        $vncviewer = FileGetShortName($vncviewer)
        Run ($vncviewer & " -config " & $c_file, "", @SW_MINIMIZE)
       Msgbox(0, "VNC Config File", "The selected vnc config file is: " & $c_file, 0)oÝ÷ Ù8^¾w/쯧vj}ýµ·¦x¦7²)ÜzØ^Â)Ý£b¶W¢±¶¬yÚ'¶¢wââéÚ殶­sdWFôDuT6WE7FFR5uôÔäÔ¤RÂgV÷C·&æFöÕö&6VEööåö6öæfuöfÆUöæÖR

oh yea the reg path does not work on my end

I'll need to search reg for vncviewer.exe and find a common place that works for all vnc flavors

nope UltraVNC uses VncViewer.Config as the type of file and thats all that I found

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\VncViewer.Config\shell\open\command

Edited by CWorks
Link to comment
Share on other sites

Ok no problem with spaces anymore for config file or viewer

$c_file = GUICtrlRead($list)
     $c_file = FileGetShortName(@ScriptDir & "\" & $c_file)
        $vncviewer = RegRead("HKEY_CLASSES_ROOT\Applications\vncviewer.exe\shell\open\command", "")
        $vncviewer = FileGetShortName($vncviewer)
        Run ($vncviewer & " -config " & $c_file, "", @SW_MINIMIZE)
       Msgbox(0, "VNC Config File", "The selected vnc config file is: " & $c_file, 0)oÝ÷ Ù8^¾w/쯧vj}ýµ·¦x¦7²)ÜzØ^Â)Ý£b¶W¢±¶¬yÚ'¶¢wââéÚ殶­sdWFôDuT6WE7FFR5uôÔäÔ¤RÂgV÷C·&æFöÕö&6VEööåö6öæfuöfÆUöæÖR

oh yea the reg path does not work on my end

I'll need to search reg for vncviewer.exe and find a common place that works for all vnc flavors

nope UltraVNC uses VncViewer.Config as the type of file and thats all that I found

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\VncViewer.Config\shell\open\command

Thanks.. Cworks... It does take the spaces now but still comes up with a prompt about unable to find configuration file.. and once you click o.k. then it launches vnc with no problem... it also shows the long path in the msg box.

Thanks

Link to comment
Share on other sites

hmm.. no problems with it here

some stuff to play with

vncviewer should now minimize

but not if Msgbox is used, for some reason it scews it up

$c_file = GUICtrlRead($list)
     $title = StringTrimRight($c_file, 4)
     $c_file = FileGetShortName(@ScriptDir & "\" & $c_file)
        $vncviewer = RegRead("HKEY_CLASSES_ROOT\Applications\vncviewer.exe\shell\open\command", "")
        $vncviewer = FileGetShortName($vncviewer)
        Run ($vncviewer & " -config " & $c_file, "", @SW_MINIMIZE)
       ;Msgbox(0, "VNC Config File", "The selected vnc config file is: " & $c_file, 0)
        Msgbox(0, "VNC Config File", "The selected vnc config file is: " & $c_file, 3) ; well it works if closed quickly

        ;MsgBox(0, "Full title read was:", $title)
        WinWait($title)
        WinSetState($title, "", @SW_MINIMIZE)oÝ÷ Ù·ßÛë-i÷°r§ë"ƬzÇ«½êâ²z-®éçxºÚ"µÍ    ÌÍØ×Ù[HHÕRPÝXY
    ÌÍÛÝ
B   ÌÍÝ]HHÝ[Õ[TYÚ
    ÌÍØ×Ù[K
B   ÌÍØ×Ù[HH[]ÚÜ[YJØÜ   [È ][ÝÉÌLÉ][ÝÈ   [È ÌÍØ×Ù[JBH  ÌÍÝÝY]ÙHYÔXY
    ][ÝÒÑVWÐÓTÔÑT×ÔÓÕ    ÌLÐXØ][ÛÉÌLÝÝY]Ù^IÌLÜÚ[ ÌLÛÜ[ÌLØÛÛ[X[    ][ÝË  ][ÝÉ][ÝÊBH  ÌÍÝÝY]ÙH[]ÚÜ[YJ   ÌÍÝÝY]ÙBH[
    ÌÍÝÝY]Ù    [È ][ÝÈXÛÛYÈ  ][ÝÈ  [È ÌÍØ×Ù[K    ][ÝÉ][ÝËÕ×ÓRSSRVJBÙØÞ
    ][ÝÕÈÛÛYÈ[I][ÝË ][ÝÕHÙ[XÝYÈÛÛYÈ[][ÝÈ  [È ÌÍØ×Ù[KÊBH    ÌÍÝ]HHÚ[Ù]]J   ÌÍÝ]K    ][ÝÉ][ÝÊNÈÙ][]H[YBHÚ[ØZ]]J   ÌÍÝ]K    ][ÝÉ][ÝË
JNÈÝÜÈØZ][È[
HÙXÛÛ[ØÙHÙÝ[[ÈÈÜÛÛ]ÈÙHÚ[Ù]Ý]J  ÌÍÝ]K    ][ÝÉ][ÝËÕ×ÓRSSRVJBHÙÐÞ
    ][ÝÑ[]HXYØÎ][ÝË   ÌÍÝ]H
J
Edited by CWorks
Link to comment
Share on other sites

hmm.. no problems with it here

some stuff to play with

vncviewer should now minimize

but not if Msgbox is used, for some reason it scews it up

$c_file = GUICtrlRead($list)
     $title = StringTrimRight($c_file, 4)
     $c_file = FileGetShortName(@ScriptDir & "\" & $c_file)
        $vncviewer = RegRead("HKEY_CLASSES_ROOT\Applications\vncviewer.exe\shell\open\command", "")
        $vncviewer = FileGetShortName($vncviewer)
        Run ($vncviewer & " -config " & $c_file, "", @SW_MINIMIZE)
       ;Msgbox(0, "VNC Config File", "The selected vnc config file is: " & $c_file, 0)
        Msgbox(0, "VNC Config File", "The selected vnc config file is: " & $c_file, 3) ; well it works if closed quickly

        ;MsgBox(0, "Full title read was:", $title)
        WinWait($title)
        WinSetState($title, "", @SW_MINIMIZE)oÝ÷ Ù·ßÛë-i÷°r§ë"ƬzÇ«½êâ²z-®éçxºÚ"µÍ    ÌÍØ×Ù[HHÕRPÝXY
    ÌÍÛÝ
B   ÌÍÝ]HHÝ[Õ[TYÚ
    ÌÍØ×Ù[K
B   ÌÍØ×Ù[HH[]ÚÜ[YJØÜ   [È ][ÝÉÌLÉ][ÝÈ   [È ÌÍØ×Ù[JB   ÌÍÝÝY]ÙHYÔXY
    ][ÝÒÑVWÐÓTÔÑT×ÔÓÕ    ÌLÐXØ][ÛÉÌLÝÝY]Ù^IÌLÜÚ[ ÌLÛÜ[ÌLØÛÛ[X[    ][ÝË  ][ÝÉ][ÝÊB   ÌÍÝÝY]ÙH[]ÚÜ[YJ   ÌÍÝÝY]ÙB[
    ÌÍÝÝY]Ù    [È ][ÝÈXÛÛYÈ  ][ÝÈ  [È ÌÍØ×Ù[K    ][ÝÉ][ÝËÕ×ÓRSSRVJBÙØÞ
    ][ÝÕÈÛÛYÈ[I][ÝË ][ÝÕHÙ[XÝYÈÛÛYÈ[][ÝÈ  [È ÌÍØ×Ù[KÊB ÌÍÝ]HHÚ[Ù]]J   ÌÍÝ]K    ][ÝÉ][ÝÊNÈÙ][]H[YBÚ[ØZ]]J    ÌÍÝ]K    ][ÝÉ][ÝË
JNÈÝÜÈØZ][È[
HÙXÛÛ[ØÙHÙÝ[[ÈÈÜÛÛ]ÈÙÚ[Ù]Ý]J   ÌÍÝ]K    ][ÝÉ][ÝËÕ×ÓRSSRVJBÙÐÞ
    ][ÝÑ[]HXYØÎ][ÝË   ÌÍÝ]H
J

Cworks thanks for all your help... If you don't mind can you attach your .au3 file so I can see where in the world I am messing up? I still keep on getting the cannot read vnc file name error and once you click o.k. it launches fine.

Thanks

Link to comment
Share on other sites

Cworks thanks for all your help... If you don't mind can you attach your .au3 file so I can see where in the world I am messing up? I still keep on getting the cannot read vnc file name error and once you click o.k. it launches fine.

Thanks

O.k I think I figured the problem out... I don't know what I am doing is optimal or not but when doing a RegRead:

$vncviewer = RegRead("HKEY_CLASSES_ROOT\Applications\vncviewer.exe\shell\open\command", "")

It picks up the %1 variable from the registry. So I added the following:

$vncpath = StringTrimRight($vncviewer, 12)

And that seems to have fixed the problem.

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...