Jump to content

Help with conditional statements


Recommended Posts

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 by homemade
Link to comment
Share on other sites

  • Moderators

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
EndIf

so 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! :evil: 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                                                            4

Then we make some suggestions. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by AdmiralAlkex
Link to comment
Share on other sites

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

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

  • Moderators

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

Let me know if this solves your problem. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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