homemade Posted January 7, 2010 Share Posted January 7, 2010 (edited) I need a little help with the conditionals and I'm not sure I'm doing it right. This is the logic that I'm trying to work with. If $sMail AND $nametrim > "0" is true then write to _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) but if it's not true and $sMail2 AND $nameTwo > "0" then have $sMail2 OR $nameTwo use _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) instead if $sMail AND $nametrim > "0" is true then write to _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) and if $sMail2 AND $nameTwo > "0" _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) What I currently have that seems to be wrong. If $sMail AND $nametrim > "0" Then _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) ElseIf $sMail2 AND $nameTwo > "0" Then _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) Else If $sMail2 AND $nameTwo > "0" Then _ExcelWriteCell($oExcel, $sMail2, $i, 2) _ExcelWriteCell($oExcel, $nameTwo, $i, 1) Else _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) EndIf EndIf Edited January 7, 2010 by homemade Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 7, 2010 Moderators Share Posted January 7, 2010 homemade,There is a serious logic problem in your code:If $sMail AND $nametrim > 0 Then ; If $sMail AND $nametrim > 0 you get this _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) ElseIf $sMail2 AND $nameTwo > 0 Then ; If $sMail2 And $nametwo > 0 you get this _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) Else If $sMail2 AND $nameTwo > 0 Then ; But this is the same as above(???) so you will never get here _ExcelWriteCell($oExcel, $sMail2, $i, 2) _ExcelWriteCell($oExcel, $nameTwo, $i, 1) Else ; And so you will always get this _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) EndIf EndIfso there is little wonder it does not work. There is also the fact that you were comparing to a string ("0") - I presume you meant to compare to a number (0) as in the code above?I also find your explanation a little confusing - age, no doubt! Could you try and set out a grid of what you want as conditions? Perhaps something like this (based on your code above):$sMail $sMail2 $nametrim $nameTwo Boolean Code block If True > 0 AND 1 ElseIf True > 0 AND 2 Else If True > 0 AND 3 Else 4Then we make some suggestions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 7, 2010 Share Posted January 7, 2010 (edited) You need to check the helpfile again, you're doing it all wrong! See "Conditional Statements" under "Language Reference" Edit: Also you check for "If $sMail2 AND $nameTwo > "0" Then" two times, wtf? Edited January 7, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
homemade Posted January 7, 2010 Author Share Posted January 7, 2010 Ok I decided to change the logic around a little bit but I still suck at this so here's my best explanation I have 2 sets of data that I'm working with. Pair 1 - $sMail and $nametrim and Pair 2 - $sMail2 and $nameTwo. I have a loop that puts Pair 1 into Excel into A*&B* and Pair 2 into A*+1&B*+1. What I'm trying to do is weed out pairs that have missing data such as a name with no email or email with no name. Right now, every loop always creates 2 rows. Since I run into a lot of missing data, I get a lot of empty rows. In order to avoid this I want to NOT create a row if any piece of data is missing from a Pair. So if Pair 1 is not created then Pair 2 gets put into A*B* instead of A*+1B*+1 IF Pair 2 contains both pieces of data. If both pairs are missing some data then nothing is written into excel. Hope my explanation is clear. If $sMail OR $nametrim = "" Then _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) EndIf If $sMail2 OR $nameTwo = "" Then _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) Link to comment Share on other sites More sharing options...
reb Posted January 8, 2010 Share Posted January 8, 2010 In order to avoid this I want to NOT create a row if any piece of data is missing from a Pair. So if Pair 1 is not created then Pair 2 gets put into A*B* instead of A*+1B*+1 IF Pair 2 contains both pieces of data. If both pairs are missing some data then nothing is written into excel. Hope my explanation is clear. Hi homemade, Could you do something like this $a = 'v' ; make $a or $d = "" and see what happens $d = 'x' if $a = "" then exit if $d = "" then Exit MsgBox(0,"","Both are present - continue with writing to excel") Regards REB MEASURE TWICE - CUT ONCE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 8, 2010 Moderators Share Posted January 8, 2010 homemade,I think this is what you want:; If Pair 1 is good put data into A*B If $sMail <> "" And $nametrim <> "" Then _ExcelWriteCell($oExcel, $sMail, $i, 2) _ExcelWriteCell($oExcel, $nametrim, $i, 1) ; If pair 2 is good put data into A+1*B+1 If $sMail2 <> "" And $nameTwo <> "" Then _ExcelWriteCell($oExcel, $sMail2, $i + 1, 2) _ExcelWriteCell($oExcel, $nameTwo, $i + 1, 1) EndIf ; If pair one is bad then Else ; If pair 2 is good put data into A*B If $sMail2 <> "" And $nameTwo <> "" Then _ExcelWriteCell($oExcel, $sMail2, $i, 2) _ExcelWriteCell($oExcel, $nameTwo, $i, 1) EndIf EndIf ; If pair 2 is bad do nothing!I changed the condition to check if the elements existed. There was nothing wrong with checking if either element was empty, but going the "other way round" made the logic flow easier in my opinion.Note the correct use of the IF syntax for multiple elements - BOTH must have the condition, not just the last one. Let me know if this solves your problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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