Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,300 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,458 people online right now. Registration is fast and FREE... Join Now!




pausing script while other parts finish

 
Reply to this topicStart new topic

pausing script while other parts finish, forcing the script to wait for something else to finish

cmount
19 Aug, 2008 - 05:05 AM
Post #1

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
I've looked at Wait()...
But that seems to just be a pre-defined amount of time to wait

Since changing some code, it's become necessary to have my code wait until an external .bat file finishes processing. Sometimes this can be a matter of seconds, but sometimes it can take minutes. So, obviously...the wait() method wouldn't be the way to go as I'd have no idea how long it would take to profile the disc with the MD5 check.

This is a snippet of my existing code (my full code is around 14 pages, I think)--this shows the sequence of events.

I have it prompt the user before clicking OK to make sure they entered everything correctly.
If the user hits OK (to continue), it then will run the .bat file, which, as I mentioned, can run very quickly or very slowly depending on what's on the disc.

The problem arises in that it wants to import the data from the CSV .txt file before the .bat file is finished writing the contents to the text file, so only some of the data gets entered. I need to force the rest of the code to wait until the .bat file is done.

Suggestions?

[edit: for some reason, it keeps screwing up my code...deleting parts of it & submitting the you entered: "&vb script:

Crap...it's still doing the annoying stuff...even outside the code tags. I'm adding semicolons to the start of each line to hopefully fool it. Obviously, the semicolons should not be there (I know)

;BeforeScriptRun:
; lastPrompt = MsgBox("You entered: " & vb script:

CODE

BeforeScriptRun:
    lastPrompt = MsgBox("You entered:  " & vb script:

    
'THIS CODE IS USED TO IMPORT THE DATA FROM THE CSV .TXT FILE WRITTEN BY FILELIST.EXE:
    
    If sFilename <> False Then
    Sheets("Temp").Select  '<--this makes temp the active sheet
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & sFilename, Destination:=Range("B1"))
            '.Name = "CSV"
            Worksheets("Temp").Cells.ClearContents
            Columns("A:I").Select
            Selection.Delete Shift:=xlToLeft
            ActiveWindow.SmallScroll Down:=-15  '! check this out
            Range("B1").Select
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 4   'if want to skip headers, make this 4, if
                                    'want to have headers, make =3
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    
    Sheets("Temp").Select
    With ActiveSheet
        nBottomRow = .Range("B" & .Rows.Count).End(xlUp).Row
        'This represents # completed rows in column B of sheet Temp
'    MsgBox (nBottomRow & " is the last row of column B in Temp") 'Old Diagnostic code; Ignore
    
    End With
        
    Set shtMain = Sheets("Main")
    Set shtTemp = Sheets("Temp")
    Set shtFull = Sheets("Full")
    
    Sheets("Temp").Select
    r1 = shtFull.Range("A" & Rows.Count).End(xlUp).Row + 1
    ' MsgBox (r1 & " is r1, or the cell after the last non-blank row") ' AGAIN, commenting out
    ' to avoid user having to click.  This option was for diagnostic purposes during development
    
    
    rowCountTemp = 0
    For rowOfAFull = r1 To r1 + nBottomRow - 1
        rowCountTemp = rowCountTemp + 1
        shtFull.Cells(rowOfAFull, 1) = "Disc " & DiscNumber
        shtFull.Cells(rowOfAFull, 2) = shtTemp.Cells(rowCountTemp, 2).Text
        shtFull.Cells(rowOfAFull, 3) = shtTemp.Cells(rowCountTemp, 3).Text
        shtFull.Cells(rowOfAFull, 4) = shtTemp.Cells(rowCountTemp, 4).Text
        shtFull.Cells(rowOfAFull, 5) = shtTemp.Cells(rowCountTemp, 5).Text
        shtFull.Cells(rowOfAFull, 6) = shtTemp.Cells(rowCountTemp, 6).Text ' I used .Text to get around issue of date screwing up
        shtFull.Cells(rowOfAFull, 7) = shtTemp.Cells(rowCountTemp, 7).Text
        shtFull.Cells(rowOfAFull, 8) = shtTemp.Cells(rowCountTemp, 8).Text
        shtFull.Cells(rowOfAFull, 9) = shtTemp.Cells(rowCountTemp, 9).Text
        
    Next rowOfAFull



I give up...no matter what I do it's screwing stuff up. I guess if you want to see my full code, pm me & I'll have to use my personal email to send it.

This post has been edited by cmount: 19 Aug, 2008 - 05:16 AM
User is offlineProfile CardPM
+Quote Post

young7
RE: Pausing Script While Other Parts Finish
19 Aug, 2008 - 08:18 AM
Post #2

New D.I.C Head
*

Joined: 19 Aug, 2008
Posts: 1

To have the code wait until the “.bat file” finishes processing try this:
Have the “.bat file” create a file when it finishes. Call the file (for example) “imfinished.txt.” Look for and delete this file before waiting (of course). Wait for the file to age a few seconds using “datediff (second resolution).” Continue processing…


[quote name='cmount' date='19 Aug, 2008 - 06:05 AM' post='403168']
I've looked at Wait()...
But that seems to just be a pre-defined amount of time to wait

...
User is offlineProfile CardPM
+Quote Post

cmount
RE: Pausing Script While Other Parts Finish
19 Aug, 2008 - 11:04 AM
Post #3

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
[quote name='young7' date='19 Aug, 2008 - 09:18 AM' post='403241']
To have the code wait until the “.bat file” finishes processing try this:
Have the “.bat file” create a file when it finishes. Call the file (for example) “imfinished.txt.” Look for and delete this file before waiting (of course). Wait for the file to age a few seconds using “datediff (second resolution).” Continue processing…


[quote name='cmount' date='19 Aug, 2008 - 06:05 AM' post='403168']
I've looked at Wait()...
But that seems to just be a pre-defined amount of time to wait

...
[/quote]

Thanks. I'll look into using that as soon as I get the rest of my code working properly. On that note: I've been running into a REALLY STRANGE situation with my code:

Attached is a .txt file with the code. I'm doing this because the code tags seem to be cutting out parts of my code.

Please note the link to download the external filelist.exe is accessible in the other thread I started. This project is a little different from the one in the other thread---as this time I'm using a FORM rather than just the old module with the code.


OK here's what I'm noticing:

If a person enters everything correctly the first time, there's no problem. If they leave something blank/there's a mistake, it will ask the user to re-enter the stuff (using the .show code). It will then perform the operation correctly (if they enter everything correctly & there are no conflicts). However, it then wants to run the old data in the form (before they corrected it). This is what it seems to be wanting to do.

Also, if they click the option to Re-enter (if they entered everything correctly & are taken to the final prompt asking them if everything is correct)...and when it pops up the form for them to edit/change values...if they enter the same thing, it wants to run the code TWICE that does the .bat file stuff & imports the stuff from the .txt file generated. SO...then the code inserts the data TWICE into the spreadsheet (basically imports the data from the text file twice).

Sometimes, it will give the user the prompt "click ok once the command window has automatically closed"...TWICE...after the first time they click OK...it briefly does the command window again & imports the data again. Or sometimes it will give you the error/warning (that I programmed into it) saying the file or data in the spreadsheet already exists.

I'm very frustrated & stumped as to why it's doing this. I think it probably has something to do with the .show code...but I don't know what or why

Please help. If you can't...it's ok, but I'd rather like to get the code working with this form...if possible




Attached File(s)
Attached File  cmountformcode.txt ( 15.56k ) Number of downloads: 8
User is offlineProfile CardPM
+Quote Post

cmount
RE: Pausing Script While Other Parts Finish
19 Aug, 2008 - 12:11 PM
Post #4

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
[edit]: Ack...I spoke too soon...the prompting for it to do the thing multiple times & the command prompt issue went away...but it looks like it still imported the stuff twice during several tests

I originally said I figured it out & this is what fixed it...but I just realized I still had a problem

Unload InputExperiment
End

right before my End Sub. This caused whatever other weird stuff that was going on from the old form entries/cancellings/etc. to be ignored/closed out as soon as the thing successfully ran all the way through one time. I still have no idea why it was doing what it was doing...if anyone knows I'd like to know. However, problem seems fixed.

You know...it would be helfpul if someone wrote up a guide of things to check if you get a certain error & stickied it.

I would just type a random number for the disc number as I was testing this...and suddenly one time I got an overflow error...I'm like wtf? overflow? Sounds like something ran out of memory...I get to thinking...and I figure it out, but for a lot of ppl...they might get an error & not know the common things to check.

My issue was...the time I got an overflow...I entered a disc # greater than 32,767 or whatever the limit is for an integer. I figured the problem out fairly quickly, but a guide like that might be helpful to others (I think).

Just a thought

[edit]: Still need your help

This post has been edited by cmount: 19 Aug, 2008 - 12:16 PM
User is offlineProfile CardPM
+Quote Post

cmount
RE: Pausing Script While Other Parts Finish
19 Aug, 2008 - 12:36 PM
Post #5

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
Too many edits on the last post...so I decided to make a new reply

I got it...I think. I'm not sure...maybe I was wrong about it doing the duplicates in my last edit on the previous post. I think I might have been looking at earlier tests before I added the unload me & end part.

Still no clue why it was doing that & would like to know if anyone else has any ideas
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:24AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month