Jump to content

ComboBox with AddDir want to remove []


Recommended Posts

This is a cutout of some code that works but I don't want the brackets "[]" around the name ether/or listed in the Combo Box or when the Data is displayed/or used. What am I missing?

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <ButtonConstants.au3>
Local $item[20]
If $item[3] = "" Then $item[3] = "Missing"
Menu($item[3])
Exit
;-------------------------------------------
Func Menu(ByRef $03)
Local $hGui, $msg, $save, $02 = "NA"
$hGui = GUICreate("Inventory", 400, 200)
GUICtrlCreateLabel("Name", 10, 90)
  $item[3] = GUICtrlCreateCombo($03, 90, 90, 250, 30)
  _GUICtrlComboBox_BeginUpdate($item[3])
  _GUICtrlComboBox_AddDir($item[3], "C:\Documents and Settings\*",$DDL_DIRECTORY)
  _GUICtrlComboBox_EndUpdate($item[3])
$save = GUICtrlCreateButton("Save", 330, 160, 60, 30)
;-----------------------------------------------------------------------------------
GUISetState()
While 1
  $msg = GUIGetMsg()
  Switch $msg
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $save
    $item[3] = GUICtrlRead($item[3])
     ;remove the brackets from name
     If StringRegExp($item[3],"[][]",1) then
     $item[3] =StringTrimLeft(StringTrimRight($item[3],1),1)
     EndIf
     MsgBox(0,"Name","Name__"&$item[3])
    GUIDelete()
    ExitLoop
  EndSwitch
WEnd
GUIDelete()
EndFunc   ;==>Menu

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

The only time the $fBrackets parameter is used is when you're using it with $DDL_DRIVES, you'll probably have to create your own combo update routine to avoid getting those brackets around the names.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Look at source of _GUICtrlComboBox_AddDir() to see how $fBracketsparameter is implemented and accomodate it to your needs.

I have looked at the help page and I didn't see it. I was hoping that it was there but I just didn't see it there.

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

He was referring to the source code for the function in the GUICombBox.au3 file. Although, that probably won't help you much as it's using a pretty convoluted work-around to get rid of the brackets for the $DDL_DRIVES command that might be hard for a newcomer to understand right away.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This is still a work-in-progress but I did add an if statement to remove the brackets. I am not good with the StringRegExp syntax. It doesn't work.

Also, switching from win7 to XP, I can now see that I don't have the AddDir location correct.

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <ButtonConstants.au3>
Local $item[20]
If $item[3] = "" Then $item[3] = "Missing"
Menu($item[3])
Exit ;end of main
;----------------------Func call list-------------
Func Menu(ByRef $03)
Local $hGui, $msg, $save, $02 = "NA"
$hGui = GUICreate("Inventory", 400, 200)
GUICtrlCreateLabel("Name", 10, 90)
  $item[3] = GUICtrlCreateCombo($03, 90, 90, 250, 30)
  _GUICtrlComboBox_BeginUpdate($item[3])
  _GUICtrlComboBox_AddDir($item[3], 'C:"Documents and Settings"*',$DDL_DIRECTORY,False)
  _GUICtrlComboBox_EndUpdate($item[3])
$save = GUICtrlCreateButton("Save", 330, 160, 60, 30)
;-----------------------------------------------------------------------------------
GUISetState()
While 1
  $msg = GUIGetMsg()
  Switch $msg
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $save
    $item[3] = GUICtrlRead($item[3])
     ;remove the brackets from names
     If StringRegExp($item[3],"[][]",1) then
      $item[3] =StringTrimLeft(StringTrimRight($item[3],1),1)
     EndIf
     MsgBox(0,"Name","Name__"&$item[3])
    GUIDelete()
    ExitLoop
  EndSwitch
WEnd
GUIDelete()
EndFunc   ;==>Menu

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

If all you're doing is getting the user folders and putting them into a combobox here's a snippet of code I made that should help with that. It will list all the users under XP and above, without listing the Administrator account or any of the other default user accounts like All Users, Default User, etc.

If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
    $NewOS = True
Else
    $NewOS = False
EndIf
If Not $NewOS Then
    $UserList = _FileListToArray("C:Documents and Settings", "*.*", 2)
    For $I = 1 To $UserList[0]
        ReDim $aUserList[$X + 1]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "NetworkService"
            Case $UserList[$I] = "LocalService"
            Case $UserList[$I] = "Administrator"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
        EndSelect
    Next
Else
    $UserList = _FileListToArray("C:Users", "*.*", 2)
    For $I = 1 To $UserList[0]
        ReDim $aUserList[$X + 1]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "Public"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
        EndSelect
    Next
EndIf
$sUserList = _ArrayToString($aUserList, "|")
; to add this list to a combo box
Global $UserName = GUICtrlCreateCombo("", 40, 130, 100)
GUICtrlSetData(-1, $sUserList)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH,

Thanks for the snippet, but I was hoping someone had a fix that was more in line with what I started with. It looks like I will need to do some more coding when I thought that I found a shortcut.

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

How do I get this to strip out everything but Letters. I want only letters ether capital or lower case.

StringRegExpReplace($item[3], "[^sa-zA-Z0-9òàùèéì]", "")

Edited by roofninja

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

Why are you so dead set to use a function that doesn't do what you want it to do? It would be far easier to write your own routine to get the information from a directory and put it into a combobox than trying to rewrite one that doesn't work right for the results you want.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I can be very single minded at times and don't want to deviate from it. It's character flaw that I have. Leighann says that it drives her crazy. It is Like, if I start something, it bothers me that I can't finish it. Especially on the same day. I have stayed up for 16 hours trying to finish something before I realize that I have to go to work the next day. That is why, at times, I don't want to ask for help and when I don't get what I am trying to do, it frustrates me to no end. I can't help it. My father and grandfather are the same way. Sorry.

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

I was able to finally solve my problem. Here is what my code looks like.

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
If _Singleton("Warning", 1) = 0 Then
MsgBox(0, "Warning", "An occurence of your program is already running")
Exit
EndIf
Local $item[20]
If $item[3] = "" Then $item[3] = "Missing"
Menu($item[3])
Exit ;end of main
;----------------------Func call list-------------
Func Menu(ByRef $03)
Local $hGui, $msg, $save, $02 = "NA", $dfiles
$hGui = GUICreate("Inventory", 400, 200)
GUICtrlCreateLabel("Name", 10, 90)
  $item[3] = GUICtrlCreateCombo($03, 90, 90, 250, 30)
  _GUICtrlComboBox_BeginUpdate($item[3])
  $search = FileFindFirstFile("C:Documents and Settings*.*") ;C:Documents and Settings
  While 1
   $dfiles = FileFindNextFile($search)
   If @error Then ExitLoop
   Switch $dfiles
    Case "All Users";skip
    Case "Default User";skip
    Case "NetworkService";skip
    Case "LocalService";skip
    Case "Administrator";skip
    Case "Default";skip
    Case "Public";skip
    Case Else
    _GUICtrlComboBox_AddString($item[3],$dfiles)
   EndSwitch
  WEnd
  FileClose($search); Close the search handle
  _GUICtrlComboBox_EndUpdate($item[3])
$save = GUICtrlCreateButton("Save", 330, 160, 60, 30)
;-----------------------------------------------------------------------------------
GUISetState()
While 1
  $msg = GUIGetMsg()
  Switch $msg
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $save
    $item[3] = GUICtrlRead($item[3])
    MsgBox(0,"Name","Name__"&$item[3])
    GUIDelete()
    ExitLoop
  EndSwitch
WEnd
GUIDelete()
EndFunc   ;==>Menu
Exit

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Link to comment
Share on other sites

Looks familiar, but at least it's working for you.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...