Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with VBA code (2002/SP3)

    The code that I have put together (attached) looks for the occurances of "CHASIS_1" and returns the value next to "T 12=" in the file called "a_test.txt" (also attached). The problem that I get the "T 12=" values for CHASIS_2 rather than CHASIS_1. When I use the "step in" function in the VBA editor everything seems to works fine, but when I run the procedure "TestProc", I get this:

    CHASIS_1 0 23
    CHASIS_1 120 99.999
    CHASIS_1 240 99.999

    What I should be gettign is this:
    CHASIS_1 0 23
    CHASIS_1 120 21.765
    CHASIS_1 240 21.765

    Can anyone give me some idea as to why this happens?
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: problem with VBA code (2002/SP3)

    Are you sure that you posted the correct files? When I try it, your code produces nothing that remotely resembles either of the results that you posted.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: problem with VBA code (2002/SP3)

    I found out why I didn't get a result resembling yours. If there is more than one text file in the folder, the code overwrites the same cells.

    There is no check for CHASIS_2 anywhere in your code. I think you should add that.

  4. #4
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: problem with VBA code (2002/SP3)

    Hans, thanks for your help here.

    I still don't see the problem. I made a duplicate of this file "a_test.txt" to "a2_test.txt" and re-ran the procedure. Note that I added more data to this file, so that now there are four instances of "CHASIS_1" and five instances of "CHASIS_2". I've attached the file so you can see what I mean. Running the program yields:

    CHASIS_1 0 23.555 |
    CHASIS_1 120 99.999 |
    CHASIS_1 240 99.001 | < value for "T 12=" at CHASIS_2, not CHASIS_1 as coded
    CHASIS_1 360 99.011 |

    This outcome doesn't change whether I run both text files or just "a2_test.txt". Also note that the instances for "SUBMODEL NAME = CHASIS_1" are identified correctly by the code. What makes this even more confusing to me is that the code seems to work as planned when I used F8 to step through each line in the code.

    Lastly, this sample file only lists "CHASIS_1" and "CHASIS_2" as the "submodel" criteria. In the actual files that I deal with I have close to 20 different "submodels".
    Attached Files Attached Files

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: problem with VBA code (2002/SP3)

    I'm afraid I can't help you - I don't understand what the code tries to do. Sorry!

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: problem with VBA code (2002/SP3)

    The problem seems to be that after you get the temp Value at "12=" for Chassis 1, you continue mark it in column C, but keep looking for it since you need the time. Thus you overwrite the value in col C when you find a value for "12=" for Chassis 2 which comes between the chassis1 and the time value.

    What you need to do is stop looking for a temperature after you find it, but continue to look for the time. does the Attached modification work for you?

    I added a variable "bNeedsTemp" which gets changed after a temp is found and reset after a time is found [I also defined some of your variable types. The lines:
    Dim r, d, i As Long
    Dim strName, strNode As String

    Will only set i as long and strNode as a string. The other variables will be set as variants since you don't explicitly define them. VBA does not have implicit definitions (r and d being long or strName as a string) as you want them to be.

    Steve
    Attached Files Attached Files

  7. #7
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: problem with VBA code (2002/SP3)

    Steve, the code works as planned. Thanks you very much for your help. :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •