Anonymouse Posted June 20, 2008 Share Posted June 20, 2008 If anyone can think of a better topic title please let me know, it would be greatly appreciated I am attempting to.. well, here's the code. I just want an easier and more efficient way of writing the last section of this code so I don't have to be redundant when doing the final copy with 1000's of different variables -.- CODE #include <GUIConstantsEx.au3> #include <ExcelCOM_UDF.au3> Opt('MustDeclareVars', 1) Global $PAIGVEC, $PAICOS, $msg, $Company, $Export, $CI, $var1, $var2, $Select, $Value Dim $combo[4], $b GUICreate("My GUI combo") $PAIGVEC = IniReadSection("C:\\myfile.ini", "GVEC-Assembly") $PAICOS = IniReadSection("C:\\myfile.ini", "COS-Assembly") $CI = IniReadSection("C:\\myfile.ini", "Company") $combo[0] = GuiCtrlCreateCombo("", 10, 10) $combo[1] = GuiCtrlCreateCombo("", 10, 50) $combo[2] = GuiCtrlCreateCombo("", 10, 90) $combo[3] = GuiCtrlCreateCombo("", 10, 130) $Company = GUICtrlCreateCombo("", 10, 250) $Export = GuiCtrlCreateButton("Excel", 10, 170) $Select = GuiCtrlCreateButton("Select", 50, 170) For $a = 1 To $CI[0][0] GUICtrlSetData($Company, $CI[$a][1]) Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Export _Export() ; Case $combo ; _Company() Case $Select For $b = 0 To Ubound($combo) -1 GUICtrlSetData($combo[$b], "") Next GUISetState() $var1 = IniRead("C:\myfile.ini", "Company", "C1", "NotFound") $var2 = IniRead("C:\myfile.ini", "Company", "C2", "NotFound") $Value = GUICtrlRead($Company) If $Value = $var1 Then For $a = 1 To $PAIGVEC[0][0] For $b = 0 To Ubound($combo) -1 GUICtrlSetData($combo[$b], $PAIGVEC[$a][1]) Next Next GUISetState() Elseif $Value = $var2 Then For $a = 1 To $PAICOS[0][0] For $b = 0 To Ubound($combo) -1 GUICtrlSetData($combo[$b], $PAICOS[$a][1]) Next Next GUISetState() EndIf EndSwitch WEnd Func _Export() Dim $PAU0, $PAU1, $PAU2, $PAU3 $PAU0 = GUICtrlRead($combo[0]) $PAU1 = GUICtrlRead($combo[1]) $PAU2 = GUICtrlRead($combo[2]) $PAU3 = GUICtrlRead($combo[3]) Global $oExcel = _ExcelBookOpen("C:\Documents and Settings\Nicker\Desktop\template.xls", 0, False) _ExcelWriteCell($oExcel, $PAU0, 13, 1) _ExcelWriteCell($oExcel, $PAU1, 14, 1) _ExcelWriteCell($oExcel, $PAU2, 15, 1) _ExcelWriteCell($oExcel, $PAU3, 16, 1) _Price() EndFunc Func _Price() Local $GPAP1, $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar1, $pVar2, $pVar3, $pVar4 $GPAP1 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP0", "NotFound") $GPAP2 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP1", "NotFound") $GPAP3 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP2", "NotFound") $GPAP4 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP3", "NotFound") $GPAP5 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP4", "NotFound") $GPAP6 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP5", "NotFound") $GPAP7 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP6", "NotFound") $GPAP8 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP7", "NotFound") $pVar1 = _ExcelReadCell($oExcel, 13, 1) $pVar2 = _ExcelReadCell($oExcel, 13, 1) $pVar3 = _ExcelReadCell($oExcel, 13, 1) $pVar4 = _ExcelReadCell($oExcel, 13, 1) If $pVar1 = $PAIGVEC[1][1] Then _ExcelWriteCell($oExcel, $GPAP1, 13, 3) ElseIf $pVar1 = $PAIGVEC[2][1] Then _ExcelWriteCell($oExcel, $GPAP2, 13, 3) ElseIf $pVar1 = $PAIGVEC[3][1] Then _ExcelWriteCell($oExcel, $GPAP3, 13, 3) ElseIf $pVar1 = $PAIGVEC[4][1] Then _ExcelWriteCell($oExcel, $GPAP4, 13, 3) ElseIf $pVar1 = $PAIGVEC[5][1] Then _ExcelWriteCell($oExcel, $GPAP5, 13, 3) ElseIf $pVar1 = $PAIGVEC[6][1] Then _ExcelWriteCell($oExcel, $GPAP6, 13, 3) ElseIf $pVar1 = $PAIGVEC[7][1] Then _ExcelWriteCell($oExcel, $GPAP7, 13, 3) ElseIf $pVar1 = $PAIGVEC[8][1] Then _ExcelWriteCell($oExcel, $GPAP8, 13, 3) Else MsgBox(,"Error", "Unknown Unit In Cell A13") EndIf _ExcelShow($oExcel) EndFunc Func _Price() is just ridiculously written. children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
martin Posted June 20, 2008 Share Posted June 20, 2008 Maybe something like this Func _Price() ;Local $GPAP[8], $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar[4], $pVar2, $pVar3, $pVar4 Local $GPAP[8], $pVar[4], $n, $done = False For $n = 0 To 7 $GPAP[$n] = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP" & $n, "NotFound") Next For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13, 1) Next For $n = 0 To 7 If $pVar[0] = $PAIGVEC[$n + 1][1] Then _ExcelWriteCell($oExcel, $GPAP[$n], 13, 3) $done = True ExitLoop EndIf Next If Not $done Then MsgBox(, "Error", "Unknown Unit In Cell A13") EndIf _ExcelShow($oExcel) EndFunc ;==>_Price BTW, if you use SciTE then Ctrl T will neaten up your code if it's saved with the au3 extension. 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 More sharing options...
Anonymouse Posted June 20, 2008 Author Share Posted June 20, 2008 (edited) Maybe something like this Func _Price() ;Local $GPAP[8], $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar[4], $pVar2, $pVar3, $pVar4 Local $GPAP[8], $pVar[4], $n, $done = False For $n = 0 To 7 $GPAP[$n] = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP" & $n, "NotFound") Next For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13, 1) Next For $n = 0 To 7 If $pVar[0] = $PAIGVEC[$n + 1][1] Then _ExcelWriteCell($oExcel, $GPAP[$n], 13, 3) $done = True ExitLoop EndIf Next If Not $done Then MsgBox(, "Error", "Unknown Unit In Cell A13") EndIf _ExcelShow($oExcel) EndFunc;==>_Price BTW, if you use SciTE then Ctrl T will neaten up your code if it's saved with the au3 extension. Oh, I guess my Codebox tags messed my code up -.- I'm very neat and a bit OCD with script For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13, 1) Next That is reading what the cells in A13:A16 say, and if it says Unit1 then it puts Price1 in C13, if it says Unit2... etc [edit] my bad, guess i didnt complete those numbers from my sloppy copy/paste before I posted. I imagine that was confusing, you haven't learned to read my mind yet martin? Sorry, hehe.[/edit] Lemme give this a test.. I can't believe I still have such a bad problem with arrays. Edited June 20, 2008 by Anonymouse children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
Anonymouse Posted June 20, 2008 Author Share Posted June 20, 2008 Hrm, it does not work correctly Func _Price() ;Local $GPAP[8], $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar[4], $pVar2, $pVar3, $pVar4 Local $GPAP[8], $pVar[4], $n, $done = False For $n = 0 To 7 $GPAP[$n] = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP" & $n, "NotFound") Next For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13 + $n, 1) Next For $n = 0 To 3 For $a = 0 To 7 If $pVar[0] = $PAIGVEC[$a + 1][1] Then _ExcelWriteCell($oExcel, $GPAP[$n], 13 + $n, 3) $done = True ExitLoop EndIf Next Next If Not $done Then MsgBox(, "Error", "Unknown Unit In Cell A13") EndIf _ExcelShow($oExcel) EndFunc;==>_Price I edited some of it ($a) so that it would post in all columns. Unit1 should be equal to price one, and so on and so forth. Buuut, with the arrays it simply writes down the price in sequential order no matter what unit is selected from the combo box. Can you understand what i'm attempting or do you need more files? children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
martin Posted June 20, 2008 Share Posted June 20, 2008 Hrm, it does not work correctly Func _Price() ;Local $GPAP[8], $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar[4], $pVar2, $pVar3, $pVar4 Local $GPAP[8], $pVar[4], $n, $done = False For $n = 0 To 7 $GPAP[$n] = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP" & $n, "NotFound") Next For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13 + $n, 1) Next For $n = 0 To 3 For $a = 0 To 7 If $pVar[0] = $PAIGVEC[$a + 1][1] Then _ExcelWriteCell($oExcel, $GPAP[$n], 13 + $n, 3) $done = True ExitLoop EndIf Next Next If Not $done Then MsgBox(, "Error", "Unknown Unit In Cell A13") EndIf _ExcelShow($oExcel) EndFunc;==>_Price I edited some of it ($a) so that it would post in all columns. Unit1 should be equal to price one, and so on and so forth. Buuut, with the arrays it simply writes down the price in sequential order no matter what unit is selected from the combo box. Can you understand what i'm attempting or do you need more files?As far as I can see the version I posted will do exactly the same as the code you posted. If the code you posted works and mine doesn't then I'm wrong, but in your original post you didn't have a loop for each $var1,2,3. Also, I think the code needs to be modified to be more like this, though this won't make it work. Func _Price() ;Local $GPAP[8], $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar[4], $pVar2, $pVar3, $pVar4 Local $GPAP[8], $pVar[4], $n, $done = False For $n = 0 To 7 $GPAP[$n] = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP" & $n, "NotFound") Next For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13 + $n, 1) Next For $n = 0 To 3 $done = false For $a = 0 To 7 If $pVar[0] = $PAIGVEC[$a + 1][1] Then _ExcelWriteCell($oExcel, $GPAP[$n], 13 + $n, 3) $done = True ExitLoop EndIf Next If Not $done Then MsgBox(, "Error", "Unknown Unit In Cell A" & (13 +$n)) EndIf Next _ExcelShow($oExcel) EndFunc;==>_Price 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 More sharing options...
Anonymouse Posted June 20, 2008 Author Share Posted June 20, 2008 (edited) As far as I can see the version I posted will do exactly the same as the code you posted. If the code you posted works and mine doesn't then I'm wrong, but in your original post you didn't have a loop for each $var1,2,3. Also, I think the code needs to be modified to be more like this, though this won't make it work. Func _Price() ;Local $GPAP[8], $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar[4], $pVar2, $pVar3, $pVar4 Local $GPAP[8], $pVar[4], $n, $done = False For $n = 0 To 7 $GPAP[$n] = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP" & $n, "NotFound") Next For $n = 0 To 3;don't see what this is doing $pVar[$n] = _ExcelReadCell($oExcel, 13 + $n, 1) Next For $n = 0 To 3 $done = false For $a = 0 To 7 If $pVar[0] = $PAIGVEC[$a + 1][1] Then _ExcelWriteCell($oExcel, $GPAP[$n], 13 + $n, 3) $done = True ExitLoop EndIf Next If Not $done Then MsgBox(, "Error", "Unknown Unit In Cell A" & (13 +$n)) EndIf Next _ExcelShow($oExcel) EndFunc;==>_Price I would have eventually figured that out, heheh. CODEFunc _Price() Local $GPAP1, $GPAP2, $GPAP3, $GPAP4, $GPAP5, $GPAP6, $GPAP7, $GPAP8, $pVar1, $pVar2, $pVar3, $pVar4 $GPAP1 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP0", "NotFound") $GPAP2 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP1", "NotFound") $GPAP3 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP2", "NotFound") $GPAP4 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP3", "NotFound") $GPAP5 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP4", "NotFound") $GPAP6 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP5", "NotFound") $GPAP7 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP6", "NotFound") $GPAP8 = IniRead("C:\myfile.ini", "GVEC-AP", "GVECAP7", "NotFound") $pVar1 = _ExcelReadCell($oExcel, 13, 1) $pVar2 = _ExcelReadCell($oExcel, 13, 1) $pVar3 = _ExcelReadCell($oExcel, 13, 1) $pVar4 = _ExcelReadCell($oExcel, 13, 1) If $pVar1 = $PAIGVEC[1][1] Then _ExcelWriteCell($oExcel, $GPAP1, 13, 3) ElseIf $pVar1 = $PAIGVEC[2][1] Then _ExcelWriteCell($oExcel, $GPAP2, 13, 3) ElseIf $pVar1 = $PAIGVEC[3][1] Then _ExcelWriteCell($oExcel, $GPAP3, 13, 3) ElseIf $pVar1 = $PAIGVEC[4][1] Then _ExcelWriteCell($oExcel, $GPAP4, 13, 3) ElseIf $pVar1 = $PAIGVEC[5][1] Then _ExcelWriteCell($oExcel, $GPAP5, 13, 3) ElseIf $pVar1 = $PAIGVEC[6][1] Then _ExcelWriteCell($oExcel, $GPAP6, 13, 3) ElseIf $pVar1 = $PAIGVEC[7][1] Then _ExcelWriteCell($oExcel, $GPAP7, 13, 3) ElseIf $pVar1 = $PAIGVEC[8][1] Then _ExcelWriteCell($oExcel, $GPAP8, 13, 3) Else MsgBox(,"Error", "Unknown Unit In Cell A13") EndIf _ExcelShow($oExcel) EndFunc See how if $pvar = PAIGVEC[1][1] then it writes $GPAP1? and if it Pvar = 2 then it writes 2, etc etc. I don't get how to do THAT part with arrays.. i look at mine, then I look at the array and my brain tries to process all of the possible outcomes of the 64 choices and my brain looks like those old "this is your brain on drugs" eggs in a frying pan. Edited June 21, 2008 by Anonymouse children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
Anonymouse Posted June 21, 2008 Author Share Posted June 21, 2008 After analyzing this for a few hours I have actually started to understand arrays a bit. But after agonizing my roommates with this equation (I wrote it out as a math problem thinking it would be easier to understand, and printed out the script), I have decided to come back to the forum with a bowed head. Is this equation possible? I even tried writing another statement to further define the arrays, no luck. children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
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