Bert Posted January 2, 2009 Posted January 2, 2009 Ok, I've been working on this for a while now, and I do not understand why this is happening. You have a ini file ($inifile = @ScriptDir & "/temp/usage.ini") The ini is named with the following information: [John Smith] 1=User1 Now when you run this script, select the name from the combo. If you have the INI setup right, the 3 input fields will populate with the data from the ini. Click the OK button. I made a msgbox to show the problem. The stringsplit will show the stringlen being 4, while $InputGUI_ControlREAD_2 will show it being 5. When you do a count, it should be 4. What am I missing here? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <String.au3> Dim $string0 DIM $string1 DIM $inifile = @ScriptDir & "/temp/usage.ini" DIM $InputGUI_ControlREAD_1 DIM $InputGUI_ControlREAD_2 DIM $InputGUI_Input_2 DIM $InputGUI_Input_3 _getnamelist() _Get_Name_At_Start() Func _Get_Name_At_Start() $InputGUI = GUICreate("Enter you name or select your name from the list", 410, 205, 193, 115) ;$InputGUI_Icon = GUISetIcon("I:\autoit scrips\icons\97.ico") $InputGUI_Label_0 = GUICtrlCreateLabel("Select your name if listed", 16, 4, 252, 17) $InputGUI_list_0 = GUICtrlCreateCombo("", 16, 20, 353, 24) GUICtrlSetData($InputGUI_list_0, $string1) $InputGUI_Label_1 = GUICtrlCreateLabel("Screen name if available", 16, 48, 352, 17) $InputGUI_Input_1 = GUICtrlCreateInput("", 16, 64, 353, 21) $InputGUI_Label_2 = GUICtrlCreateLabel("First name", 16, 88, 52, 17) $InputGUI_Input_2 = GUICtrlCreateInput("", 16, 104, 353, 21) $InputGUI_Label_3 = GUICtrlCreateLabel("Last Name", 16, 132, 55, 17) $InputGUI_Input_3 = GUICtrlCreateInput("", 16, 148, 353, 21) $InputGUI_Button_1 = GUICtrlCreateButton("Ok", 16, 177, 89, 25, 0) $InputGUI_Button_2 = GUICtrlCreateButton("Cancel", 152, 177, 89, 25, 0) $InputGUI_Button_3 = GUICtrlCreateButton("Exit", 296, 177, 73, 25, 0) GUISetState(@SW_SHOW, $InputGUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $InputGUI_Button_3, $GUI_EVENT_CLOSE Exit Case $InputGUI_list_0 $picklist_select = GUICtrlRead ($InputGUI_list_0) $stringlen_picklist = stringlen ($picklist_select) $inireadhandle = IniRead ($inifile, $picklist_select, '1', "") GUICtrlSetData($InputGUI_Input_1, $inireadhandle) $splitname = StringSplit ($picklist_select, " ") GUICtrlSetData($InputGUI_Input_2, $splitname[1]) GUICtrlSetData($InputGUI_Input_3, $splitname[2]) Case $InputGUI_Button_1 ;name from pick list has match from inireadsections ;name is new ;name is updated ;name is in error $InputGUI_ControlREAD_1 = GUICtrlRead($InputGUI_Input_1) $InputGUI_ControlREAD_2 = GUICtrlRead($InputGUI_Input_2) $InputGUI_ControlREAD_3 = GUICtrlRead($InputGUI_Input_3) $StringLenFirstName = StringLen ($InputGUI_ControlREAD_2) $StringLenLastName = StringLen ($InputGUI_ControlREAD_3) $picklist_select = GUICtrlRead($InputGUI_list_0) If $StringLenFirstName > 0 And $StringLenLastName > 0 And $stringlen_picklist > 0 Then ;first, last, and picklist have data $InputGUI_ControlREAD_2 = _Cleanup($InputGUI_ControlREAD_2, True) ;removes " " from name $InputGUI_ControlREAD_3 = _Cleanup($InputGUI_ControlREAD_3, True) ;removes " " from name _getnamelist() ;$string1 is the array that is made into a string ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;checks to see if picklist and ini data have a match $len = StringLen($InputGUI_ControlREAD_2&" "&$InputGUI_ControlREAD_3) $len2 = StringLeft($string1, $len) $stringcheck = StringInStr($string1, $len2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;split the first and last name from the ini if $InputGUI_ControlREAD_1 <> 0 then $splitname = StringSplit($picklist_select, " ") endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;msgbox showing the problem. How can the strings be 2 different lengths? MsgBox(0, "",$splitname[1]& @crlf _ &"Lenth of split for first name: "&StringLen($splitname[1])& @CRLF _ &$InputGUI_ControlREAD_2& @crlf _ &"Lenth of name from control: "&StringLen($InputGUI_ControlREAD_2) Else IniWrite($inifile, $InputGUI_ControlREAD_2 & " " & $InputGUI_ControlREAD_3, '1', $InputGUI_ControlREAD_1) GUIDelete($InputGUI) ExitLoop EndIf Case $InputGUI_Button_2 $InputGUI_Question = MsgBox(36, "Exit?", "Do you wish to exit?") If $InputGUI_Question = 6 Then GUIDelete($InputGUI) _exit() EndIf Case $InputGUI_Button_3 GUIDelete($InputGUI) _exit() EndSwitch WEnd EndFunc ;==>_Get_Name_At_Start Func _Cleanup($iName, $Space = False) $iName = StringReplace($iName, " ", "") If $Space Then $iName &= " " Return _StringProper($iName) EndFunc ;==>_Cleanup Func _getnamelist() $var = IniReadSectionNames($inifile) If @error Then ConsoleWrite("Error occurred, probably no INI file.") Else $string0 = _ArrayToString($var) $pipecheck = StringInStr($string0, "|") $string1 = StringTrimLeft($string0, $pipecheck) EndIf Return $string1 EndFunc ;==>_getnamelist Func _exit() Exit EndFunc ;==>_exit The Vollatran project My blog: http://www.vollysinterestingshit.com/
DeeRiee Posted January 2, 2009 Posted January 2, 2009 I pressed the OK button, but... Au3Check Errors C:\Documents and Settings\AutoIt Scripter\Desktop\testforum.au3(80,87) : ERROR: syntax error &"Lenth of name from control: "&StringLen($InputGUI_ControlREAD_2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Documents and Settings\AutoIt Scripter\Desktop\testforum.au3(82,125) : ERROR: MsgBox() [built-in] called with wrong number of args. IniWrite($inifile, $InputGUI_ControlREAD_2 & " " & $InputGUI_ControlREAD_3, '1', $InputGUI_ControlREAD_1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Documents and Settings\AutoIt Scripter\Desktop\testforum.au3 - 2 error(s), 0 warning(s) If i continue, no message box, but exiting
ResNullius Posted January 2, 2009 Posted January 2, 2009 Ok, I've been working on this for a while now, and I do not understand why this is happening. You have a ini file ($inifile = @ScriptDir & "/temp/usage.ini") The ini is named with the following information: [John Smith] 1=User1 Now when you run this script, select the name from the combo. If you have the INI setup right, the 3 input fields will populate with the data from the ini. Click the OK button. I made a msgbox to show the problem. The stringsplit will show the stringlen being 4, while $InputGUI_ControlREAD_2 will show it being 5. When you do a count, it should be 4. What am I missing here?Looks llike you're calling your _Cleanup function with the $space parameter set to True. According to your _Cleanup() If $Space Then $iName &= " " So the String length is being increased there!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now