Jump to content

Debugging: Why Does This Work In Some Situations, And Not Others?


Recommended Posts

The following is called when the user inputs data into a GUI, then clicks the 'Done' button. It should go take the inputs, do some math, then input it into a webpage. And, that it does. But, it does not enter the correct data in ALL circumstances. I have no idea why.

If the user enters a value for ALL 6 inputs ($CIS_inputa, $FA_inputa, $DA_inputa, $sf_input1a, $sf_input2a, $sf_input3a) the script runs perfect. Otherwise, if the user inputs 5 numbers or less, then the script will place the data in the wrong location on the webpage.

Somewhere along the way it will skip one entry onto the webpage, but input the rest. But, skipping that one, screws up the other inputs.

The webpage creates an equal amount of inputs boxes for an equal number of inputs into the GUI by the user. So, if the user inputs 1 number, 1 input box on the webpage is create. And likewise if 6 are inputted, then 6 are created on the webpage.

Please help, and thanks in advance.

Func Edit_Descriptions()
    $TMP = 0
    If $CIS_inputa > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page ($TMP);Edit Description on the IE Page
        Edit_Discounts ($TMP,$CIS_input,$CIS_inputa);Edit Discounts on the IE Page
    EndIf

    If $FA_inputa > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$FA_input,$FA_inputa)
    EndIf
    
    If $DA_inputa > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$DA_input,$DA_inputa)
    EndIf   

    If $sf_input1a > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$SF_input1,$SF_input1a )
    EndIf
    
    If $sf_input2a > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$SF_input2,$SF_input2a )
    EndIf
    
    If $sf_input3a > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$SF_input3,$SF_input3a )
    EndIf
EndFunc


Func Edit_Proposal_Page ($var)
;Edit Description on the IE Page
sleep (500)
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "description" & $var)
_IEAction($o_Keywords,"focus")
_IEAction($o_Keywords,"selectall")
Send("{CTRLDOWN}c{CTRLUP}")
$description_text = ClipGet ()

If $description_text = $CIS_Text Then
    _IEFormElementSetValue ($o_Keywords, $CIS_Text_NEW)
EndIf

If $description_text = $FA_Text Then
    _IEFormElementSetValue ($o_Keywords, $FA_Text_NEW)
EndIf

If $description_text = $DA_Text Then
    _IEFormElementSetValue ($o_Keywords, $DA_Text_NEW)
EndIf

Return
EndFunc

Func Edit_Discounts($var, $var1, $var2)
;Edit Discounts on the IE Page
sleep (1500)
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "discount" & $var)
$input1 = GUICtrlRead($var1)
$input2 = GUICtrlRead($var2)
$input3 = $input1 * $input2
$input3 = StringFormat("%.2f", $input3)
_IEFormElementSetValue ($o_Keywords, $input3)
Return
EndFunc

********EDIT*********

Added Full Script

This is the page the script does not work correctly with.

Edited by litlmike
Link to comment
Share on other sites

  • Moderators

Anyone have any thoughts?

This may not have anything to do with the problem, but I'd consider using <> (not equal to) rather than > (greater than).

Also if you could attach the rest of your script it would be easier to troubleshoot.

Edited by big_daddy
Link to comment
Share on other sites

This may not have anything to do with the problem, but I'd consider using <> (not equal to) rather than > (greater than).

Also if you could attach the rest of your script it would be easier to troubleshoot.

Hmm... thanks for the tip, whats the reason for that?

I am attaching the script to the original post. Attaching vs. Posting because its 900 lines of code. Beware, I am just teaching myself how to code, and I am sure it must look ugly to you experienced code-gods.

Also, I had to change the company name name to [secret Company], for confidentiality reasons. I am not sure they want their name published on forums. Even if you had the company name, you couldn't open the website without my password. If I gave that out, I would be fired immeadiately. Thanks for all the help.

Link to comment
Share on other sites

Hmm... thanks for the tip, whats the reason for that?

I am attaching the script to the original post. Attaching vs. Posting because its 900 lines of code. Beware, I am just teaching myself how to code, and I am sure it must look ugly to you experienced code-gods.

Also, I had to change the company name name to [secret Company], for confidentiality reasons. I am not sure they want their name published on forums. Even if you had the company name, you couldn't open the website without my password. If I gave that out, I would be fired immeadiately. Thanks for all the help.

no problem, i can completely respect the need for secrecy with corporate projects, it will just help the debugging to be able to see the whole picture. i'm going to start going through the code, and i'll let you know when i have something.
Link to comment
Share on other sites

  • Moderators

Hmm... thanks for the tip, whats the reason for that?

This is the first thing that comes to mind:

If a string is used as a number and it doesn't contain a valid number, it will be assumed to equal 0.

I am attaching the script to the original post. Attaching vs. Posting because its 900 lines of code. Beware, I am just teaching myself how to code, and I am sure it must look ugly to you experienced code-gods.

Its a little hard to follow, but it doesn't look that bad.

Also, I had to change the company name name to [secret Company], for confidentiality reasons. I am not sure they want their name published on forums. Even if you had the company name, you couldn't open the website without my password. If I gave that out, I would be fired immeadiately. Thanks for all the help.

In your first post I thought you meant that your script was creating the webpage. If you could provide the source for proposals.cfm I will see what I can figure out.
Link to comment
Share on other sites

no problem, i can completely respect the need for secrecy with corporate projects, it will just help the debugging to be able to see the whole picture. i'm going to start going through the code, and i'll let you know when i have something.

ok, i bet this is probably it:

you have this whole section of blocks like this:

If $DA_inputa > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page($TMP)
        Edit_Discounts($TMP, $DA_input, $DA_inputa)
    EndIf

now functions being called have a counter, which iterates on each call right? so: when you call it 6 times (because 6 values greater than 0) each box is populated correctly on the page. now, if you have one that doesn't have a value greater than 0, the counter is not incremented, so the next time it is called, it sends to the wrong place. there are a few easy ways to fix this,

1) remove the conditions, so that the function is called every time, even if there is a value of 0 (won't hurt to have the boxes filled with 0's right?)

2) add an 'Else' for each condition, so that the $TMP variable is incremented even if the function is not called

Link to comment
Share on other sites

This is the first thing that comes to mind:

Its a little hard to follow, but it doesn't look that bad.

In your first post I thought you meant that your script was creating the webpage. If you could provide the source for proposals.cfm I will see what I can figure out.

Sure I think I can provide some/most of it. I will have to replace some things for confidentiality, but you should get the idea.

Also, it doesn't CREATE the webpage, but it does TELL the webpage WHAT to create. So if the user enters 1 CIS, and 1 FA, then the script enters the inpu on the First webpage, then clicks Next (Submit) and the website Creates a NEW page. Which is where the description/discount info goes.

I am getting ready to paste the source code in the original post. Thanks again!

Link to comment
Share on other sites

ok, i bet this is probably it:

you have this whole section of blocks like this:

If $DA_inputa > 0 Then
        $TMP = $TMP + 1
        Edit_Proposal_Page($TMP)
        Edit_Discounts($TMP, $DA_input, $DA_inputa)
    EndIf

now functions being called have a counter, which iterates on each call right? so: when you call it 6 times (because 6 values greater than 0) each box is populated correctly on the page. now, if you have one that doesn't have a value greater than 0, the counter is not incremented, so the next time it is called, it sends to the wrong place. there are a few easy ways to fix this,

1) remove the conditions, so that the function is called every time, even if there is a value of 0 (won't hurt to have the boxes filled with 0's right?)

2) add an 'Else' for each condition, so that the $TMP variable is incremented even if the function is not called

1) I had to look up the word "iterates". Lol! "To say or perform again; repeat"

2) When you say counter, I assume you mean $TMP = $TMP + 1. I think I need this because the webpage creates a 'box' that is numbered 1-6, depending on the number of inputs from the user. It is there for this line, $o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "description" & $var).

BUT maybe there is a better way to set this up.

3) You are right, it is okay to enter 0 in the boxes.

4) You are recomending removing the If...EndIf so it would look-like

$TMP = $TMP + 1
Edit_Proposal_Page($TMP)
Edit_Discounts($TMP, $DA_input, $DA_inputa)

5) The 'else' might work, but I am trying to visualize this for a second. I have a slow brain, so I will write back in a bit.

Link to comment
Share on other sites

1) I had to look up the word "iterates". Lol! "To say or perform again; repeat"

2) When you say counter, I assume you mean $TMP = $TMP + 1. I think I need this because the webpage creates a 'box' that is numbered 1-6, depending on the number of inputs from the user. It is there for this line, $o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "description" & $var).

BUT maybe there is a better way to set this up.

3) You are right, it is okay to enter 0 in the boxes.

4) You are recomending removing the If...EndIf so it would look-like

$TMP = $TMP + 1
Edit_Proposal_Page($TMP)
Edit_Discounts($TMP, $DA_input, $DA_inputa)

5) The 'else' might work, but I am trying to visualize this for a second. I have a slow brain, so I will write back in a bit.

yes, iterate was a poor choice of words. but you did catch my meaning. without the condition that should work. or you could even just put the $TMP = $TMP + 1 before the condition, so that it is incremented regardless of the functions being called. that way $tmp will always be incremented correctly even if the functions are not called for that place.
Link to comment
Share on other sites

yes, iterate was a poor choice of words. but you did catch my meaning. without the condition that should work. or you could even just put the $TMP = $TMP + 1 before the condition, so that it is incremented regardless of the functions being called. that way $tmp will always be incremented correctly even if the functions are not called for that place.

I tried 2 variations of this, but it didn't work out right. I think it is because $TMP effects the "discount" and "description", and both have to equal the same every time. I am sensing we are on the right track, however. Gosh, I wish I was better at this.

Func Edit_Descriptions()
    $TMP = 0
    $TMP = $TMP + 1
    If $CIS_inputa > 0 Then
        Edit_Proposal_Page ($TMP);Edit Description on the IE Page
        Edit_Discounts ($TMP,$CIS_input,$CIS_inputa)
    EndIf
    
    $TMP = $TMP + 1
    If $FA_inputa > 0 Then
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$FA_input,$FA_inputa)
    EndIf
    
    $TMP = $TMP + 1
    If $DA_inputa > 0 Then
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$DA_input,$DA_inputa)
    EndIf   

    $TMP = $TMP + 1
    If $sf_input1a > 0 Then
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$SF_input1,$SF_input1a )
    EndIf
    
    $TMP = $TMP + 1
    If $sf_input2a > 0 Then
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$SF_input2,$SF_input2a )
    EndIf
    
    $TMP = $TMP + 1
    If $sf_input3a > 0 Then
        Edit_Proposal_Page ($TMP)
        Edit_Discounts ($TMP,$SF_input3,$SF_input3a )
    EndIf
EndFunc

Func Edit_Descriptions()
    $TMP = 0
    
    If $CIS_inputa > 0 Then
        Edit_Proposal_Page ();Edit Description on the IE Page
        Edit_Discounts ($CIS_input,$CIS_inputa)
    EndIf
    
    
    If $FA_inputa > 0 Then
        Edit_Proposal_Page ()
        Edit_Discounts ($FA_input,$FA_inputa)
    EndIf
    
    
    If $DA_inputa > 0 Then
        Edit_Proposal_Page ()
        Edit_Discounts ($DA_input,$DA_inputa)
    EndIf   

    
    If $sf_input1a > 0 Then
        Edit_Proposal_Page ()
        Edit_Discounts ($SF_input1,$SF_input1a )
    EndIf
    
    
    If $sf_input2a > 0 Then
        Edit_Proposal_Page ()
        Edit_Discounts ($SF_input2,$SF_input2a )
    EndIf
    
    
    If $sf_input3a > 0 Then
        Edit_Proposal_Page ()
        Edit_Discounts ($SF_input3,$SF_input3a )
    EndIf
EndFunc

Func Edit_Proposal_Page ()
;Edit Description on the IE Page
sleep (500)
$TMP = $TMP + 1
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "description" & $TMP)
_IEAction($o_Keywords,"focus")
_IEAction($o_Keywords,"selectall")
Send("{CTRLDOWN}c{CTRLUP}")
$description_text = ClipGet ()

If $description_text = $CIS_Text Then
    _IEFormElementSetValue ($o_Keywords, $CIS_Text_NEW)
EndIf

If $description_text = $FA_Text Then
    _IEFormElementSetValue ($o_Keywords, $FA_Text_NEW)
EndIf

If $description_text = $DA_Text Then
    _IEFormElementSetValue ($o_Keywords, $DA_Text_NEW)
EndIf

Return
EndFunc

Func Edit_Discounts($var1, $var2)
;Edit Discounts on the IE Page
sleep (1500)
$TMP = $TMP + 1
$o_SearchForm = _IEFormGetObjByIndex ($o_IE, 0)
$o_Keywords = _IEFormElementGetObjByIndex ($o_SearchForm, "discount" & $TMP)
$input1 = GUICtrlRead($var1)
$input2 = GUICtrlRead($var2)
$input3 = $input1 * $input2
$input3 = StringFormat("%.2f", $input3)
_IEFormElementSetValue ($o_Keywords, $input3)
Return
EndFunc
Link to comment
Share on other sites

Try outputting some values using consolewrite in SciTE for debugging purposes and seeing what values certain variables in your program get in certain steps. It would appear that you have not manually stepped thru the whole process and may be assuming certain values are there when they may not be.

Compile, run, curse. Recompile, rerun, recurse...

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