7 Replies - 20519 Views - Last Post: 11 June 2010 - 10:50 PM Rate Topic: -----

#1 dominion_vortar  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 07-November 09

Using a progress bar in a form

Posted 06 January 2010 - 03:29 PM

Hi guys!

I have a form which allows me to search through a binary file for a record, but it takes a while, so I want to use a progress bar so the user knows the program is working!

My search code is as follows

  filename1 = "F:\Program\CustomersFile.bin"
		Dim RecordNumber As Integer
		Dim found As Boolean
		Dim searchcustid As String

		searchcustid = txtSearchCustID.Text
		found = False



		FileOpen(1, filename1, OpenMode.Random, , , Len(OneCustomer))

		Do While (Not EOF(1)) And (found = False)

			RecordNumber = RecordNumber + 1
			' FileGet(1, filename, RecordNumber)'error in book should be like below!!!!
			FileGet(1, OneCustomer, RecordNumber)
			If OneCustomer.CustID = searchcustid Then
				found = True
			End If
		Loop

		If found Then
			Call DisplayOneCustomer(OneCustomer)
			'FileClose(1)
		Else
			MsgBox("Customer ID CANNOT BE FOUND!!", MsgBoxStyle.Critical)

		End If
		FileClose(1)



I have no experience with progress bars at all. I've looked at a few examples, but struggle to link it with my search code, please could someone advise me on how I would go about this? It would be much appreciated :)

Thanks very much.

Is This A Good Question/Topic? 0
  • +

Replies To: Using a progress bar in a form

#2 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Using a progress bar in a form

Posted 06 January 2010 - 05:14 PM

Hmm. You can use Progressbar1.Value += 1 to add more progress to a progressbar. The only problem would be trying to find an appropriette time to do it. Especially if you're using a backgroundworker.
Was This Post Helpful? 0
  • +
  • -

#3 billyboy630  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 94
  • Joined: 09-October 09

Re: Using a progress bar in a form

Posted 06 January 2010 - 05:29 PM

Couple of ways I do it,
1 if i have several steps my program is going through
i wil do something like
progressbar1. value = 10
progressbar1.value = 20
etc... create intervals after each step program goes through till you get to 100
then progressbar1.visible = false when done

2 you can guesstimate the time your program takes and put the progressbar with a timer, so its showing it might not be in perfect sync but it will give user the appearence something is happening

I am still new and these might be the "BEST way" but they work for me especially the first one

But like Jack said finding the time to start and end and increase value might be a challenge with your code
Make the progressbar visible as soon as you want the user to see it then think through the steps your code does and try and put a value increase as it goes through those steps
Was This Post Helpful? 0
  • +
  • -

#4 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Using a progress bar in a form

Posted 07 January 2010 - 12:10 AM

Hi,

You can set the Progress bar's Style to "Marquee" if you have "Visual Styles" enabled in Win Xp or you can set it to "Continuous" when "Visual Styles" is not enabled. This is great if you do not know how many items are being searched (maximum number)

So how to use it...

Option 1

Add the Progress bar and make sure the Style Property is set to "Blocks".

When you start searching the file you set the Style Property to "Marquee"

When you have finished searching set the Style Property back to "Blocks"

   ProgressBar1.Style = ProgressBarStyle.Marquee
   'start searching your file here


   'You might need to add this to your code (loop)
   'Application.DoEvents()

   'when finished set it to blocks
   ProgressBar1.Style = ProgressBarStyle.Blocks



Option 2

Add the Progress bar and set the Style Property to "Marquee".

Make the Progess bar invisible

When you start searching the file make the Progess bar visible

When you have finished searching make the Progess bar in-visible.


   ProgressBar1.Visible = True
   'start searching your file here


   'You might need to add this to your code (loop)
   'Application.DoEvents()

   'when finished set it to blocks
   ProgressBar1.Visible = False



Bear in mind that with some operations, the progress bar seems to hang. Thus you would use a background worker, but thats a bit more advanced.
Was This Post Helpful? 0
  • +
  • -

#5 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Using a progress bar in a form

Posted 07 January 2010 - 12:31 AM

Why was I so thick that I didn't think of marquee before? lol.
Was This Post Helpful? 1
  • +
  • -

#6 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Using a progress bar in a form

Posted 07 January 2010 - 12:52 AM

hehe, it took me quite a while to figure that one out, but that was way back....
Was This Post Helpful? 0
  • +
  • -

#7 dominion_vortar  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 07-November 09

Re: Using a progress bar in a form

Posted 07 January 2010 - 10:35 AM

Thanks very much for all your responses, I appreciate them. Will try to implement the ideas into my code tonight, and report back!

Thanks again :^:
Was This Post Helpful? 0
  • +
  • -

#8 Guest_brijmohan singh bhadauria*


Reputation:

Re: Using a progress bar in a form

Posted 11 June 2010 - 10:50 PM

Thankx ... i m appreciate your codeing which u hav to writen .. this is real help ful 4 me ...thankx once again....


Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1



End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

If (Me.ProgressBar1.Value < 100) Then
Me.ProgressBar1.Value += 4
Else
Me.Timer1.Enabled = False
End If
If ProgressBar1.Value = 100 Then
Form1.Show()
Me.Hide()

End If
Return
End Sub 'Timer1_Tick

End Class

Attached File(s)


Was This Post Helpful? 0

Page 1 of 1