Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 13th, 2011, 06:09 PM
Authorized User
Points: 193, Level: 3
Points: 193, Level: 3 Points: 193, Level: 3 Points: 193, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Question Reseting A Counter

Special Thanks to Rod Stephens for answering my previous two questions. Programming is tough and I really appreciate your input.

In a particular application, I need a counter to count up to 108 as it is counting the 108 lines of text in a text file. The problem comes when I need to repeat the same process without leaving the application, with many successive text files.

I need the counter to count only to 108 and then reset before counting the lines of text in the next text file. By setting up multiple counters I can partially remedy this situation, but since the process is repeated thousands of times in a day, this method is rather burdensome. The best solution would be to reset the counter to 0 each time the lines of a text file will be counted without closing the application. Is there a way to do that?



If DataLoadingView.txtCounter.Text = "1" Then

Static strCounter1 As Integer
strCounter1 = 1 + strCounter1
DataLoadingView.txtTextLoadingCounter.Text = strCounter1

End If


If DataLoadingView.txtCounter.Text = "2" Then

Static strCounter2 As Integer
strCounter2 = 1 + strCounter2
DataLoadingView.txtTextLoadingCounter.Text = strCounter2

End If
Reply With Quote
  #2 (permalink)  
Old December 14th, 2011, 11:00 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

It sounds like you might need two loops here. It depends on how you're getting the list of files to process. Here are two possibilities:

1) If you have the file names in a list:

Code:
For Each file_name As String in file_names
    ' Process this file.
    For i As Integer = 1 To 108
        ' Do something with line i.
        ...
    Next i
Next file_name
If you use a file method to list the files in a directory, that should work, too.

2) If the user enters a file name in a TextBox and clicks a button, then the button's code can define the variable.

Code:
' Process the file.
For i As Integer = 1 To 108
    ' Do something with line i.
    ...
Next i
3) If you want to do something more elaborate such as processing a single line each time the user presses a button, then you might try something like this:

Code:
' Declare LineNumber at the module level outside of any routine.
Private LineNumber As Integer = 0

' Handle the button click.
Private Sub btnProcessLine_Click(...)
    ' If we don't have a line number, open the next file.
    ... open a file here ...

    ' Process line number LineNumber.
    ...

    ' Move to the next line.
    LineNumber += 1

    ' If we have processed 108 lines in this file,
    ' get ready to open the next file.
    If (LineNumber > 108) Then LineNumber = 0
End Sub
If you can give us a little more information about how things are controlled, for example how you know which file to open, we might be able to give a bit more help.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
Gary108 (December 15th, 2011)
  #3 (permalink)  
Old December 15th, 2011, 11:10 AM
Authorized User
Points: 193, Level: 3
Points: 193, Level: 3 Points: 193, Level: 3 Points: 193, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Smile Thank you Rod

Hi Rod,

I just wanted to thank you once again. By adding the following line (with a change of the variable name) into my existing code, which already included a Loop, I was able to solve my problem. I had spent many hours trying to figure that out and the solution was so easy with your help.

If (LineNumber > 108) Then LineNumber = 0

Gary108
Reply With Quote
Reply


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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# classes working for multiple forms w/ reseting Nathan Fleming C# 2005 1 September 11th, 2006 04:45 PM
counter keeps reseting FlashMan Classic ASP Professional 7 September 30th, 2004 12:56 PM
Counter tp194 Javascript 1 September 2nd, 2004 08:02 AM
counter Adam H-W Classic ASP Basics 15 August 15th, 2003 11:18 AM



All times are GMT -4. The time now is 05:43 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.