MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 28th, 2002, 12:25 AM   #1
John Yazou
New Member
 
Join Date: Mar 2002
Posts: 49
Default

Hi,
I have a file that contains
Line1
Line2
Line3

Am using something like

while not eof(filenumber)
if Condition1 = True then
copied = copied + 1
do something....
end if
total = total + 1
loop

Which is fine... but now i want to add a progress bar.. but I will need to set the ProgressBar1.Max = total, so I will need to know the # of lines contained in the file beforehand. How to do this??

want it to be something like

ProgressBar1.Max = # of lines
ProgressBar1.Min = 0

while not eof(filenumber)
if Condition1 = True then
copied = copied + 1
do something...
end if
ProgressBar1.Value = total + 1

loop

John Yazou is offline   Reply With Quote
Old Mar 28th, 2002, 12:31 AM   #2
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

John

Not to sure what you are doing but

Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
MsgBox LastRow
End If

Dave Hawley is offline   Reply With Quote
Old Mar 28th, 2002, 12:35 AM   #3
John Yazou
New Member
 
Join Date: Mar 2002
Posts: 49
Default

That would work if the data is in a sheet correct?? But the data is in a text file.
The code is a simplified text file parsing program. I want the users the see the progress.
John Yazou is offline   Reply With Quote
Old Mar 28th, 2002, 12:39 AM   #4
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Have you looked at the automating the Text import wizard?






Dave Hawley is offline   Reply With Quote
Old Mar 28th, 2002, 12:47 AM   #5
John Yazou
New Member
 
Join Date: Mar 2002
Posts: 49
Default

Yup,
Here's the problem:
- The raw data file is about 20+ MB, text file, containing about 1 million rows; so using Text Import wizard, or using Application.OpenText is out
- However, the actual meaningful data is only a fraction of the file, and would actually fit in Excel

So, the full import function looks something like..
FilterRawData("temp.txt") ' As previous posting
Application.OpenText xxx yyy zzz

Its been working fine.. but my boss, wants to see the progress.. I don't know why.. If there's no solution I guess would have to tell him to live with it... Thanks

John Yazou is offline   Reply With Quote
Old Mar 28th, 2002, 01:00 AM   #6
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi John

Tell your boss if he has nothing better to do than watch a progress bar he should retire Joking of course!

I am a little confused, if there are one million or so lines and you only want x number of these, your progress bar max Property will have to be set to ONLY the lines you need. I assume you your loop actually does this for you?

I guess what I am saying is, even it there is a way to get the number of lines from the Text File (don't think there is) it would be wrong.





Dave Hawley is offline   Reply With Quote
Old Mar 28th, 2002, 01:52 AM   #7
John Yazou
New Member
 
Join Date: Mar 2002
Posts: 49
Default

Thanks Dave...
Well, good point.. my boss does have nothing better to do... ... he's one of those ppl who thinks just because the UI is a bit unresponsive .. it hangs...

Guess i'll just tell him it cannot be done... no harm done... cheers dave




John Yazou is offline   Reply With Quote
Old Mar 28th, 2002, 02:06 AM   #8
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
There are several ways you could do it.

Use file length function.

If the data lines are made up of variable length strings, just give a good guess for an average number of bytes per line. A variable length string is numCharacters + 2
Spaces count as characters.

For an open file use LOF(File#)/EstimatedBytesPerLine


For a closed file use FileLen(Path/Name)/EstimatedBytesPerLine

If the data is stored in the file on each line as a Data type such as date, byte, integer, ect...
Then search help for the byte count for whichever data type applies...

Here is an example given the most difficult situation: Variable length strings per line on your file.


Dim EstimatedBytesPerLine
Dim LengthOfThisFile
Dim ProgressBarMax_Value
Dim CurrentFileNum

CurrentFileNum = FreeFile

Open your file as #CurrentFileNum

ProgressBarMax_Value = LOF(CurrentFileNum)/EstimatedBytesPerLine

Anyway, I hope this helps you...
Tom


Tom Schreiner is offline   Reply With Quote
Old Mar 28th, 2002, 02:11 AM   #9
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Tom, the problem is that there are a million or so lines, but only x amount are needed, not all of them.

John, you may find the method I often use to inform a user of a very long macro running.
http://www.mrexcel.com/board/viewtop...c=3412&forum=2

The advantage of this method is it will not slow down an already slow prodedure, something the Progress bar does. It Catch 22


Dave Hawley is offline   Reply With Quote
Old Mar 28th, 2002, 03:21 AM   #10
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

I agree Dave.
I don't use them myself.
Not with Excel.
I just throw the code into a userform and place the wait message on the caption. Will check out your idea too!
Am learning too much here.
Head might explode soon.
Have a nice day!
Tom
Tom Schreiner is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes