Jump to content

How to replace text in a control from value in an INI file.


Recommended Posts

I have a listbox containing items like so:

JDM
BCC
PAJ
REP

I want to replace each item in the listbox with a corresponding item in an INI file:

INI:

[Names]
JDM=Mack, Joe (JDM)
BCC=Carver, Brian (BCC)
PAJ=Johnson, Paul (PAJ)
REP=Plink, Ralph (REP)

So, after it's done, my listbox will have:

Mack, Joe (JDM)
Carver, Brian (BCC)
Johnson, Paul (PAJ)
Plink, Ralph (REP)

How do I do this?

Link to comment
Share on other sites

GUICtrlSetData() is used to change list items. The values can be read in using IniRead()'s.

Perhaps I didn't explain what I'm looking for well enough.

I'm looking for instruction on how to compare the items in my listbox to those in the INI file to get the full name and then place the full name in the listbox.

Link to comment
Share on other sites

Perhaps I didn't explain what I'm looking for well enough.

I'm looking for instruction on how to compare the items in my listbox to those in the INI file to get the full name and then place the full name in the listbox.

Like evilertoaster says:

Comparing:

Read the values stored in the INI file and listbox [GUICTRLRead()], use the '=' operator or StringInStr().

Replacing:

GUICtrlSetData() or some UDF function(GuiList UDF) for this task.

You need some help in the code? Please, try post your code first.

Link to comment
Share on other sites

Here's the code that I have so far:

Func OnList()
    GUICtrlSetData($lblStatus, "Getting Providers...")
    $dictationPath = @UserProfileDir & "\Desktop\Dictation\"
    $provArray = _FileListToArrayEx($dictationPath, '*.dss')

    If (Not IsArray($provArray)) Or (@error = 1) Then
            MsgBox(262208, "List Providers Error", "No Files\Folders Found.   ")
        Return
    EndIf
    $pArray = '';$pArray has to be declared first since are using &= below to add to it
    For $x = 1 To $provArray[0] ; for loop to place the files in the list.
        $pArray &= StringLeft($provArray[$x], 3) & Chr(1); Notice &= to add each element to $pArray and notice & Chr(1) to use a delimiter for the next array
    Next
    $pArray = StringSplit(StringTrimRight($pArray, 0), Chr(1));StringTrimRight() is used to get rid of the last delimiter or we will have an empty element.
    _ArrayUnique($pArray, Chr(1), 1);Depending on which _ArrayUnique() you are using, you may have to do:  $pArray = _ArrayUnique($pArray)
    GUICtrlSetData($lstProviders, $pArray)
    ;Now we have to loop through each one to make it one string to add to the $lstproviders... of course, I can only assume that $lstProviders is an edit
    GUICtrlSetData($lstProviders, '');Empty the control $lstProviders
    $sHoldNewList = '';We will use this to hold the new list.
    For $iCC = 1 To UBound($pArray) - 1
        $sHoldNewList &= $pArray[$iCC] & Chr(124)
    Next
    $sHoldNewList = StringTrimRight($sHoldNewList, 2);@CRLF is 2 Chars, have to trim the fat off the ends
    GUICtrlSetData($lstProviders, $sHoldNewList)
    
    
    $provNames =  IniReadSection(@ScriptDir & "\providers.ini", "Names") ;Read provider names into a 2D array
    
    ; Code to place names into Listbox goes here.
    
EndFunc
Link to comment
Share on other sites

  • Moderators

Bump.

That code looks familiar :rolleyes:

You have to read it into an array (the section) $inireadsection = IniReadSection()... Then you have to read the Control List into an array $splitcontrol = StringSplit(StringStripCR(GUICtrlRead(Control)), @LF), then go through the Section If $inireadsection[n][0] = $splitcontrol[n] Then do something.

There's your foundation... look forward to seeing what you come up with.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

That code looks familiar :rolleyes:

You have to read it into an array (the section) $inireadsection = IniReadSection()... Then you have to read the Control List into an array $splitcontrol = StringSplit(StringStripCR(GUICtrlRead(Control)), @LF), then go through the Section If $inireadsection[n][0] = $splitcontrol[n] Then do something.

There's your foundation... look forward to seeing what you come up with.

Heh, I wonder why it looks familiar. :rambo:

Anyway, let me bang on it for a while and see what I can do. I will post whatever I come up with here.

Link to comment
Share on other sites

Ugh, I totally suck at this, I'm coming up empty here.

;--------------- Functions ---------------
Func OnList()
    GUICtrlSetData($lblStatus, "Getting Providers...")
    $dictationPath = @UserProfileDir & "\Desktop\Dictation\"
    $provArray = _FileListToArrayEx($dictationPath, '*.dss')

    If (Not IsArray($provArray)) Or (@error = 1) Then
            MsgBox(262208, "List Providers Error", "No Files\Folders Found.   ")
        Return
    EndIf
    $pArray = '';$pArray has to be declared first since are using &= below to add to it
    For $x = 1 To $provArray[0] ; for loop to place the files in the list.
        $pArray &= StringLeft($provArray[$x], 3) & Chr(1); Notice &= to add each element to $pArray and notice & Chr(1) to use a delimiter for the next array
    Next
    $pArray = StringSplit(StringTrimRight($pArray, 0), Chr(1));StringTrimRight() is used to get rid of the last delimiter or we will have an empty element.
    _ArrayUnique($pArray, Chr(1), 1);Depending on which _ArrayUnique() you are using, you may have to do:  $pArray = _ArrayUnique($pArray)
    ;Now we have to loop through each one to make it one string to add to the $lstproviders... of course, I can only assume that $lstProviders is an edit
    ;GUICtrlSetData($lstProviders, '');Empty the control $lstProviders
    ;$sHoldNewList = '';We will use this to hold the new list.
    ;For $iCC = 1 To UBound($pArray) - 1
    ;    $sHoldNewList &= $pArray[$iCC] & Chr(124)
    ;Next
    ;$sHoldNewList = StringTrimRight($sHoldNewList, 2);@CRLF is 2 Chars, have to trim the fat off the ends
    ;0GUICtrlSetData($lstProviders, $sHoldNewList)
    
    GUICtrlSetData($lstProviders, '');Empty the control $lstProviders   
    $provNames = IniReadSection(@ScriptDir & "\providers.ini", "Names") ;Read provider names into a 2D array
    ;_ArrayDisplay($provNames)
    For $z = 1 To UBound($pArray) - 1
        If $provNames[$z][0] = $pArray[$z] Then
            CtrlSetData($lstProviders, $provNames[0][$z])
        EndIf
    Next
EndFunc

--> Array variable has incorrect number of subscripts or subscript dimension range exceeded

I have no idea why this is happening, although, I guess if I knew more about arrays I might be able to figure it out, but I've gone through what seems like a hundred examples and I'm even more confused.

Link to comment
Share on other sites

Ugh, I totally suck at this, I'm coming up empty here.

;--------------- Functions ---------------
Func OnList()
    GUICtrlSetData($lblStatus, "Getting Providers...")
    $dictationPath = @UserProfileDir & "\Desktop\Dictation\"
    $provArray = _FileListToArrayEx($dictationPath, '*.dss')

    If (Not IsArray($provArray)) Or (@error = 1) Then
            MsgBox(262208, "List Providers Error", "No Files\Folders Found.   ")
        Return
    EndIf
    $pArray = '';$pArray has to be declared first since are using &= below to add to it
    For $x = 1 To $provArray[0] ; for loop to place the files in the list.
        $pArray &= StringLeft($provArray[$x], 3) & Chr(1); Notice &= to add each element to $pArray and notice & Chr(1) to use a delimiter for the next array
    Next
    $pArray = StringSplit(StringTrimRight($pArray, 0), Chr(1));StringTrimRight() is used to get rid of the last delimiter or we will have an empty element.
    _ArrayUnique($pArray, Chr(1), 1);Depending on which _ArrayUnique() you are using, you may have to do:  $pArray = _ArrayUnique($pArray)
    ;Now we have to loop through each one to make it one string to add to the $lstproviders... of course, I can only assume that $lstProviders is an edit
    ;GUICtrlSetData($lstProviders, '');Empty the control $lstProviders
    ;$sHoldNewList = '';We will use this to hold the new list.
    ;For $iCC = 1 To UBound($pArray) - 1
    ;    $sHoldNewList &= $pArray[$iCC] & Chr(124)
    ;Next
    ;$sHoldNewList = StringTrimRight($sHoldNewList, 2);@CRLF is 2 Chars, have to trim the fat off the ends
    ;0GUICtrlSetData($lstProviders, $sHoldNewList)
    
    GUICtrlSetData($lstProviders, '');Empty the control $lstProviders   
    $provNames = IniReadSection(@ScriptDir & "\providers.ini", "Names") ;Read provider names into a 2D array
    ;_ArrayDisplay($provNames)
    For $z = 1 To UBound($pArray) - 1
        If $provNames[$z][0] = $pArray[$z] Then
            CtrlSetData($lstProviders, $provNames[0][$z])
        EndIf
    Next
EndFunc

--> Array variable has incorrect number of subscripts or subscript dimension range exceeded

I have no idea why this is happening, although, I guess if I knew more about arrays I might be able to figure it out, but I've gone through what seems like a hundred examples and I'm even more confused.

Looks something wrong in $provNames[$z][0] variable, maybe it's exceeding its dimension. Check it.

Link to comment
Share on other sites

Looks something wrong in $provNames[$z][0] variable, maybe it's exceeding its dimension. Check it.

Well, this is trimming zero characters from the right:

StringTrimRight($pArray, 0)oÝ÷ ٩ݶ¬$²X¤{*.­ëޮǶ¬¹»®*mÓ~³ÒÚ4Ó~³jëh×6        If $provNames[$z][0] = $pArray[$z] Then
            CtrlSetData($lstProviders, $provNames[0][$z])
        EndIf

:rolleyes:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...