| View previous topic :: View next topic |
| Author |
Message |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Thu Jan 28, 2010 7:34 am Post subject: Variable and Run Statement not Working as expected. |
|
|
I have a problem in trying to evaluate a simple run command using a variable in the path of a literal file name. My code is shown below.
I have checked this and rechecked it over and over again, used the debugger to look at the value of [ProgPath] and in every case my Result flag keeps getting returned as 'False' and my file is not executed.
If I substitute the literal path for [ProgPath] the file runs just fine. It's been commented out of the code shown below.
I'm beating my head against the wall with this one and I know it must be something really silly that I'm not seeing, but I'm running out of patience. The value for [ProgPath] is getting set from a parsed value being read from a file, but the debugger shows it as being read correctly. And yes, the file is located where this code is pointing to and the name is correct. I even highlighted the name in Windows and 'copy and pasted' it into my code just to be sure.
This is pretty basic and simple code, so that makes it more baffling as to why it's not running correctly. Any ideas where to look?
| Code: | AlertBox "Current Path =" "[ProgPath]"
. [ProgPath] Variable = \\VAMAIN\DATA\Apg\Program Control and Finance\Program Directory Standard\APG_Struct
FileExists "[ProgPath]\MASTER WBS Diagram.pdf" "[Result]"
If "[Result]" "=" "True"
Run "[ProgPath]\MASTER WBS Diagram.pdf" "" "Normal" "" ""
Else
AlertBox "Missing File!" "WBS Diagram file not found."
.Run "\\VAMAIN\DATA\Apg\Program Control and Finance\Program Directory Standard\APG_Struct\MASTER WBS Diagram.pdf" "" "Normal" "" ""
EndIf |
Thx,
redjr... |
|
| Back to top |
|
 |
Wrangler NeoBooker

Joined: 31 Mar 2005 Posts: 1331 Location: USA
|
Posted: Thu Jan 28, 2010 8:54 am Post subject: |
|
|
If [progpath] is outside the pub directory, did you try adding ! before the path? _________________ Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. - Wrangler
Software made with NeoBook
http://highdesertsoftware.com |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Thu Jan 28, 2010 9:27 am Post subject: |
|
|
| Wrangler wrote: | | If [progpath] is outside the pub directory, did you try adding ! before the path? |
Wrangler,
The ! does not make a difference. All of my folder paths are explicit locations on a server - regardless of where the app is running. That has generally not been a problem in the past.
Here's what I've discovered this morning. If I explicitly setvar [ProgPath] at the beginning as shown in the immediate code below, the execution of the run command works fine.
| Code: | SetVar "[ProgPath]" "\\VAMAIN\DATA\Apg\Program Control and Finance\Program Directory Standard\APG_Struct"
FileExists "[ProgPath]\MASTER WBS Diagram.pdf" "[Result]"
If "[Result]" "=" "True"
Run "[ProgPath]\MASTER WBS Diagram.pdf" "" "Normal" "" ""
Else
AlertBox "Missing File!" "WBS Diagram file not found."
EndIf |
However, what I need to happen is the value for [ProgPath] needs to be set after parsing a file and picking up the full path. The value that gets stuffed into [ProgPath] is the last entry on a line in my file.
So... I'm wondering if there's an ASCII control character at the end of the line I'm not accounting for and stripping off prior to setting the [ProgPath] variable. With the above test positive , I now believe there is an issue with [ProgPath] that I cannot see in the debugger.
Would there be a linefeed/CR command at the end of my file? Following is the code I'm using to read the file and parse into variables I'm using - including [ProgPath]. Note that [ProgPath] is set using the [PLinePart5] variable. If so, how do you strip off these non-visible characters prior to setting the variable?
Could you take a look and see the 'error of my ways'?
| Code: | SetVar "[ProgName]" "[ProgSelect1]"
FileRead "[GProgPath]\[ProgName]_Stub.ini" "1" "[Plinedata]"
..Parse the line
StrParse "[PLinedata]" "[#9]" "[PLinePart]" "[PLineNumParsed]"
SetVar "[ProgName]" "[PLinePart1]"
SetVar "[ProgMgr]" "[PLinePart2]"
SetVar "[ProgSD]" "[PLinePart3]"
SetVar "[ProgFD]" "[PLinePart4]"
SetVar "[ProgPath]" "[PLinePart5]"
ShowObject "Text154" "None" "0"
ShowObject "Text156" "None" "0" |
Thx much.
redjr... |
|
| Back to top |
|
 |
Wrangler NeoBooker

Joined: 31 Mar 2005 Posts: 1331 Location: USA
|
Posted: Thu Jan 28, 2010 9:37 am Post subject: |
|
|
First we would need to determine what the unwanted character is. I open up the text file in NoteTab Pro, which shows me hidden characters. I then use StrReplace to replace the unwanted character with "". You can get the hex number for the character from an ascii table.
You may also want to look at what WRITES to the file. You could maybe nip it in the bud to prevent it from writing unwanted characters in the first place.
Your code looks fine to me. The problem seems to be a hidden character in the read file. _________________ Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. - Wrangler
Software made with NeoBook
http://highdesertsoftware.com |
|
| Back to top |
|
 |
Gaev NeoBooker

Joined: 01 Apr 2005 Posts: 4321 Location: Toronto, Canada
|
Posted: Thu Jan 28, 2010 10:05 am Post subject: |
|
|
redjr:
Step 1 - see if the [ProgPath] content from the two methods are identical | Code: | SetVar "[WorksProgPath]" "\\VAMAIN\DATA\Apg\Program Control and Finance\Program Directory Standard\APG_Struct"
StrLen "[WorksProgPath]" "[WorksProgPathSize]"
Alert "this works" "[WorksProgPath][#13][#10][WorksProgPathSize]"
SetVar "[ProgName]" "[ProgSelect1]"
FileRead "[GProgPath]\[ProgName]_Stub.ini" "1" "[Plinedata]"
..Parse the line
StrParse "[PLinedata]" "[#9]" "[PLinePart]" "[PLineNumParsed]"
SetVar "[ProgName]" "[PLinePart1]"
SetVar "[ProgMgr]" "[PLinePart2]"
SetVar "[ProgSD]" "[PLinePart3]"
SetVar "[ProgFD]" "[PLinePart4]"
SetVar "[ProgPath]" "[PLinePart5]"
StrLen "[ProgPath]" "[ProgPathSize]"
Alert "this does not" "[ProgPath][#13][#10][ProgPathSize]"
If "[ProgPath]" "<>" "[WorksProgPath]"
Alert "compare" "Not Equal"
Else
Alert "compare" "Ding Ding Ding Ding"
EndIf |
Step 2 - depends on results of Step 1 _________________ Gaev
http://www.scriptedlogic.com/ |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Thu Jan 28, 2010 1:36 pm Post subject: |
|
|
| Gaev wrote: | redjr:
Step 1 - see if the [ProgPath] content from the two methods are identical | Code: | SetVar "[WorksProgPath]" "\\VAMAIN\DATA\Apg\Program Control and Finance\Program Directory Standard\APG_Struct"
StrLen "[WorksProgPath]" "[WorksProgPathSize]"
Alert "this works" "[WorksProgPath][#13][#10][WorksProgPathSize]"
SetVar "[ProgName]" "[ProgSelect1]"
FileRead "[GProgPath]\[ProgName]_Stub.ini" "1" "[Plinedata]"
..Parse the line
StrParse "[PLinedata]" "[#9]" "[PLinePart]" "[PLineNumParsed]"
SetVar "[ProgName]" "[PLinePart1]"
SetVar "[ProgMgr]" "[PLinePart2]"
SetVar "[ProgSD]" "[PLinePart3]"
SetVar "[ProgFD]" "[PLinePart4]"
SetVar "[ProgPath]" "[PLinePart5]"
StrLen "[ProgPath]" "[ProgPathSize]"
Alert "this does not" "[ProgPath][#13][#10][ProgPathSize]"
If "[ProgPath]" "<>" "[WorksProgPath]"
Alert "compare" "Not Equal"
Else
Alert "compare" "Ding Ding Ding Ding"
EndIf |
Step 2 - depends on results of Step 1 |
Gaev,
Well the length is different by 1 character, but the difference is not a character I can see. I have to believe it's either a LF, CR, EOL, or End of Paragraph marker - the little backwards P symbol. I can see it when I open the file in the Neobook Editor, but not familar with what ASCII character it is for sure. How do I parse that out of the line?
redjr...
Edit... I tried reading the length of the line and then reducing it by 1, but that removed a printable character, the 't' in my 'APG-Struct'. Not what I had in mind. |
|
| Back to top |
|
 |
Wrangler NeoBooker

Joined: 31 Mar 2005 Posts: 1331 Location: USA
|
Posted: Thu Jan 28, 2010 1:39 pm Post subject: |
|
|
Try opening the file in a raw text editor like UltraEdit. Most of these editors can be made to show hidden characters. _________________ Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. - Wrangler
Software made with NeoBook
http://highdesertsoftware.com |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Thu Jan 28, 2010 2:26 pm Post subject: |
|
|
| Wrangler wrote: | | Try opening the file in a raw text editor like UltraEdit. Most of these editors can be made to show hidden characters. |
Wrangler,
Here's what happening... See code below.
| Code: | ..Parse the line
StrParse "[PLinedata]" "[#9]" "[PLinePart]" "[PLineNumParsed]"
SetVar "[ProgName]" "[PLinePart1]"
SetVar "[ProgMgr]" "[PLinePart2]"
SetVar "[ProgSD]" "[PLinePart3]"
SetVar "[ProgFD]" "[PLinePart4]"
SetVar "[ProgPath]" "[PLinePart5]" |
Eureka! When I parse the line into the different variables shown above, I notice in the debugger that there's an extra leading space(or some character) before each, EXCEPT for the first one - [ProgName]. That's why the length is different and why the resulting path can not be found! Is there something different I should be doing in the parse function to remove this - as yet - unknown character when extracting to each variable?
I tried removing the leading space from a temp variable using,
| Code: | | StrDel "[PLinePart5]" "1" "1" "[PLinePart5a]" |
prior to setting [ProgPath], but alas that didn't seem to work. Maybe it's not a 'space' but some other non-printing character. I'll scope out UltraEdit.
redjr... |
|
| Back to top |
|
 |
Gaev NeoBooker

Joined: 01 Apr 2005 Posts: 4321 Location: Toronto, Canada
|
Posted: Thu Jan 28, 2010 2:33 pm Post subject: |
|
|
redjr:
| Quote: | | I can see it when I open the file in the Neobook Editor, but not familar with what ASCII character it is for sure. How do I parse that out of the line? | Step 1 - we know that there is a difference.
Step 2 - figure out what is different ... try and download this (free) Hex Editor ... http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm ... it will show you the Hexadecimal code for each byte ... post the results here ... then, its just a matter of using StrReplace to replace the extraneous character with nothing e.g. ... | Code: | | StrReplace "string" "[#240]" "" "variable" "options" | ... will replace all bytes whose content has the decimal code value of 240 (Hex:F0) to nothing. _________________ Gaev
http://www.scriptedlogic.com/ |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Fri Jan 29, 2010 7:20 am Post subject: |
|
|
Gaev/Wrangler,
Thanks for all your help with this. I discovered what the problem was and have worked out what appears to be a relatively simple fix.
Early on in my code I parse the line in my file as such;
| Code: | ..Parse the line
StrParse "[PLinedata]" "[#9]" "[PLinePart]" "[PLineNumParsed]"
SetVar "[ProgName]" "[PLinePart1]"
SetVar "[ProgMgr]" "[PLinePart2]"
SetVar "[ProgSD]" "[PLinePart3]"
SetVar "[ProgFD]" "[PLinePart4]"
SetVar "[ProgPath]" "[PLinePart5]" |
Unfortunately, the StrParse line was not robust enough and left unwanted characters before and after the tab [#9] - between the parsed fields/variables. This was clearly evident in reviewing the debugger. I later confirmed the unwanted characters were spaces, or [#32]. So I revised the StrParse line to read like this;
| Code: | | StrParse "[PLinedata]" "[#9][#32]" "[PLinePart]" "[PLineNumParsed]" |
Now when the parsed line gets separated into the variables, the space[#32] is removed from the begining of the next variable. After putting all my code back together, it appears to work fine.
This was an important find because this [ProgPath] variable will be used throughout my app, so I needed to get it working correctly.
If you have any further ideas to streamline my process and make the code more efficient, I'm willing to adopt a different solution.
Thx again,
redjr... |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Tue Feb 02, 2010 12:15 pm Post subject: More Issues with a ListBox?? |
|
|
Hi Guys,
I'm adding more code to my app, and basically I'm trying to populate a list box with the matching results read in from a text file(MASTER_List). This is basically the same code we discussed in the thread last week with a few key changes to add the items it loops through to a ListBox instead of a ComboBox. In fact, some of the code is verbatim. I copied and pasted it into another object.
I can't for the life of me figure out why my ListBox25 is not showing anything after the code is executed. I've gone thru it line by line, compared it to what I did last week, examined output from the debugger and still I'm coming up empty.
Perhaps some additional set of eyes may discover something either fundamentally flawed, or basicially pretty silly that I'm not doing correctly, or simply overlooking. As always, any input would be appreciate.
| Code: | SetVar "[Path]" "[GProgPath]"
FileRead "[Path]\[Prog_Ini]" "1" "[Plinedata]"
..Parse the line
StrParse "[PLinedata]" "[#9][#32]" "[PLinePart]" "[PLineNumParsed]"
SetVar "[ProgName]" "[PLinePart1]"
SetVar "[ProgMgr]" "[PLinePart2]"
SetVar "[ProgSD]" "[PLinePart3]"
SetVar "[ProgFD]" "[PLinePart4]"
SetVar "[ProgPath]" "[PLinePart5]"
..Build Program User list
ListBoxDeleteItem "ListBox25" "ALL"
Loop "1" "[flen]" "[Y]"
FileRead "[GProgPath]\MASTER_List.txt" "[Y]" "[Linedata]"
..Parse the line
StrParse "[Linedata]" "[#9]" "[LinePart]" "[LineNumParsed]"
..Check for Duplicate Items and Add Item
If "[LinePart2]" "=" "[ProgName]"
ListBoxFindItem "ListBox25" "[LinePart1]" "[Found1]"
If "[Found1]" "=" "0"
ListBoxAddItem "ListBox25" "0" "[LinePart1]"
EndIf
EndIf
EndLoop |
Thx,
redjr...
Edit: For clarity... LinePart1 is the username associated with progname (LinePart2). Once [ProgName] is set, it loops through the MASTER_List finding the list of users and adding their names to ListBox25. At least that's what I want it to do!  |
|
| Back to top |
|
 |
Gaev NeoBooker

Joined: 01 Apr 2005 Posts: 4321 Location: Toronto, Canada
|
Posted: Tue Feb 02, 2010 12:36 pm Post subject: |
|
|
redjr:
Whenever you have a situation where the encountered behaviour differs from the expected result ... it helps to break up the process into smaller chunks and see (eliminate) the parts that do behave according to expectations.
In your case ...
a) Immediately before the Loop command, place an AlertBox command to show the value of variable [flen] ... i don't see where this variable is populated !!!
b) Assuming it contains the correct value (i.e. number of lines in the MASTER_List.txt file) ... insert another AlertBox command immediately after the FileRead command to show both [Y] and [Linedata]
This will confirm (or not) whether you are correctly reading the lines.
If you are ... the next step is to see see how each line in the file navigates through your remaining code e.g. | Code: | If "[LinePart2]" "=" "[ProgName]"
AlertBox "[Y]" "LinePart2 equals ProgName"
ListBoxFindItem "ListBox25" "[LinePart1]" "[Found1]"
If "[Found1]" "=" "0"
AlertBox "[Y]" "Not Found LinePart1"
ListBoxAddItem "ListBox25" "0" "[LinePart1]"
EndIf
EndIf | ... by noting down the sequence of AlertBox messages, you can zoom in to where reality differs from expectation !!! _________________ Gaev
http://www.scriptedlogic.com/ |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Tue Feb 02, 2010 2:09 pm Post subject: |
|
|
Gaev,
You are correct. I should have put some AlertBoxes in. The 'flen', 'Y' and LinePart data are correct. I can get down to the following section of code and even though the AlertBox shows the record #(Y) and LinePart2 being equal to ProgName, the If condition is not being evaluated for some odd reason. Really weird. I know there's a perfectly logical reason why it's not - I just haven't found it yet. The two AlertBoxes inside the If statement are never displayed. So, it's back to more detective work. My first thought was more embedded non-displayable characters in what I'm parsing, but I viewed the file in a Hex editor and the only thing between them is the tab [#9]. No space, or anything else.
| Code: | AlertBox "[Y][LinePart2]" "[ProgName]"
If "[LinePart2]" "=" "[ProgName]"
AlertBox "[Y]" "LinePart2 equals ProgName"
ListBoxFindItem "ListBox25" "[LinePart1]" "[Found1]"
If "[Found1]" "=" "0"
AlertBox "[Y]" "Not Found LinePart1"
ListBoxAddItem "ListBox25" "0" "[LinePart1]"
EndIf
EndIf |
I'll keep at it, but finding these 'bugs' can be a real challenge. 'Knocks head against wall.."
redjr... |
|
| Back to top |
|
 |
Gaev NeoBooker

Joined: 01 Apr 2005 Posts: 4321 Location: Toronto, Canada
|
Posted: Tue Feb 02, 2010 2:45 pm Post subject: |
|
|
redjr: | Quote: | | the AlertBox shows the record #(Y) and LinePart2 being equal to ProgName | Obviously this is an eye-ball comparison ... however if ... | Quote: | | The two AlertBoxes inside the If statement are never displayed. | .. it means that ... | Code: | | If "[LinePart2]" "=" "[ProgName]" | ... is found to be NOT true ... so the two values are NOT equal ... must be some extraneous (unprintable) character in one of them ... try checking the StrLen of each variable ... and for a byte-for-byte comparison, check out the values using the Hex Editor Utility I mentioned in a previous post. _________________ Gaev
http://www.scriptedlogic.com/ |
|
| Back to top |
|
 |
redjr NeoBooker

Joined: 06 Jan 2009 Posts: 103 Location: NY
|
Posted: Wed Feb 03, 2010 5:17 am Post subject: |
|
|
Gaev,
I used the hex-editor and sure enough there was an additional space [#32] following LinePart2. Not sure how all these 'spaces' are getting into my text file. Is there a preferred, or eloquent way to check for these spaces - either during data entry, or when parsing the lines in the file while reading? I'd like to clean these up at the point of writing to the file rather then later. Obviously, there are spaces within some of the text, but not before or after the text block(s) I'm trying to parse into variables. Suggestions?
Thx again for your help and insight.
redjr... |
|
| Back to top |
|
 |
|