|
|
Thank you, but I already saw it before and it is a litle complicated (I am beginner). I found exactly what I need.
Beginners, see following code:
Option Explicit On
Imports System.ComponentModel
Public Class Form1
Private worker As BackgroundWorker
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
worker = New BackgroundWorker()
worker.WorkerReportsProgress = True
AddHandler worker.DoWork, New DoWorkEventHandler(AddressOf OnWork)
AddHandler worker.ProgressChanged, New ProgressChangedEventHandler(AddressOf OnProgressChanged)
End Sub
Private Sub OnWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim i As Integer
For i = 1 To 100
System.Threading.Thread.Sleep(10)
worker.ReportProgress(i)
Next
End Sub
Private Sub OnProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
Invoke(New ChangeProgressBarHandler(AddressOf ChangeProgressBar), e.ProgressPercentage)
End Sub
Private Delegate Sub ChangeProgressBarHandler(ByVal percentage As Integer)
Private Sub ChangeProgressBar(ByVal percentage As Integer)
ProgressBar1.Value = percentage
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
worker.RunWorkerAsync()
End Sub
End Class
Eric H.
|
|
|
|
|
Here is 1 line that will stop that error and you can carry on using a thread.
Control.CheckForIllegalCrossThreadCalls = false
Just put it in the constructor of your form.
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Yes, but that sucks. The error is there for a reason.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You're just upset because you didn't think of it or you don't understand it.
I give lessons on Wednesdays and Thursdays if you'd like to attend.
I know that it could give problems but for basic applications where only one thread accesses a control it is perfect. I have used this plenty of times before and had no problems.
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
smyers wrote: You're just upset because you didn't think of it or you don't understand it.
ROTFL - I know about it and know exactly what it does.
smyers wrote: I have used this plenty of times before and had no problems.
If someone has crossed the road with a blindfold on once or twice without problems, does that make it a good thing to do ? I didn't think so.
I prefer to help people learn to code properly, rather than give them nasty shortcuts that are going to bite them down the track when their code gets a little more complex.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: If someone has crossed the road with a blindfold on once or twice without problems, does that make it a good thing to do
It wouldn't be a problem if no cars ever drove down that road.
Like I said, using one thread will give you no problems.
PS - What does ROTFL stand for?
PPS - The lessons offer is still open
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
smyers wrote: Like I said, using one thread will give you no problems.
Fair enough. You're welcome to offer whatever advice you see fit. Experience tells me that if your advice is easier to follow, people will prefer it, even if it's bad.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thak you,
I try this as following, but it doen't work
Public Class Form1
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ind As Integer
Button1.Enabled = False
ProgressBar1.Step = 5000
ProgressBar1.Value = 0
Dim trd As Threading.Thread = New Threading.Thread(AddressOf ThreadDo)
trd.Start()
ListBox1.Items.Clear()
For ind = 0 To 5000
ListBox1.Items.Add(ind)
ListBox1.SelectedIndex = ind
Next
Button1.Enabled = True
End Sub
Private Sub ThreadDo()
ProgressBar1.PerformStep()
If ProgressBar1.Value >= ProgressBar1.Maximum Then
Timer1.Enabled = False
End If
End Sub
End Class
Eric H.
|
|
|
|
|
It seems to me that you should do some reading, and perhaps not worry about threads for a while until you've got a greater understanding of more basic things.
When asking a question, you should also define 'doesn't work', that doesn't tell us anything. Does it blow up ? Does it not do what yuo wanted ? Does it do anyting at all ? We don't know. Telling us the line that blows up and the error would also help.
And, what you're doing now is telling the framework not to protect you from yourself. This may work fine for such a simple app, but you'd do better to learn how to use a more powerful thread class ( BackgroundWorker ) and to ensure that your UI access is all in one thread. Then you can write *good* code, instead of just code that compiles.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You right, when I am saying doesn't work, it means in this case that first the listbox fullfilled and then the progressbar get to 100%. I don't see any thread working.
I am sorry my english is not mother tongue, I hope you understand
Thanks
Eric H.
|
|
|
|
|
Your code makes no sense at all - your progress bar is running in a different thread to the thing you're tracking progress on. The thread that's adding to the listbox, should be the thread that runs the progress bar, otherwise there's no relationship between the progress made and the state of the bar.
The code also calls a thread, outside of a loop, which will just step the progress bar once. And then it stops a timer, which we can't even see.
Overall, this code shows every sign of you're being well out of your depth with the concepts you are playing with, I'd recommend working through a decent book and trying to learn some basics.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
If it is so easy for you to do this why don't you show me the solution like that I will be able to appropriate this easy example to my difficult application?
In my side, I will continue to learn VB.NET in my rythm.
Thank you
Eric H.
|
|
|
|
|
I just tried to run this code and it runs. Don't know what you trying to do though.
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
the listbox is fullfilled but the progressbar doesn't progress in parallel while the listbox is adding items.
First the listbox add items
second the progressbar =100%
Isn't it?
Thank you
Eric H.
|
|
|
|
|
I have finished my Project with no Errors, i try to Buld it, it will take time to Bring results and it will not Display my Results. it gives me an Errors saying"Just in Time Error" and it will Build
"
Preparing resources...
Updating references...
Performing main compilation...
"
for the Whole day. my sysytem is fast and i try to Google the Problem before i post.
Help
Vuyiswa
|
|
|
|
|
We really can't help, because you've posted no code and done nothing to explain what it's doing when yuo get this error
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Have you designed the component yourself or you are using any third party component.Make it Clear , as the error is of com+ component
please be clear of your problem you want to share.
thanks and wishes
Navneet Hegde
Nashik
Develop2Program & Program2Develop
|
|
|
|
|
Thank you i got the Solution, Just in time Debugger was not enabled
Thanks very much for your concern
Vuyiswa
|
|
|
|
|
Hello frnds,
Is there any code in vb.net to change the macro security to
"LOW"
i am using vb.net 2.0 and word2003
can i get the security options of a existing page ???
Means is it "Very High/High/Medium/Low"
please help...
Thankx to all and regards,
koolprasad2003
Life is swing with you..Enjoy..
|
|
|
|
|
If you would be able to change the macro security level programmatically, what would be the point of having macro security?
Although I am not sure, it seems entirely likely that the Microsoft people have hidden this setting from code, but if you can get to it, you should probably be looking at the properties of the application and not the document, as macro security level is set for the installation.
Now, more importantly, it sounds like you are trying to write a macro virus, otherwise there really is no reason to mess with macro security. If you really need some macro to work for legitimate reasons, you will have to inform the user in some other way that they should change the security level, for the document to be able to do what it is supposed to do, and preferably inform them of what the macro will do.
My advice is free, and you may get what you paid for.
|
|
|
|
|
can i add textboxes only in the first cell of datagridview?
I have four rows in the datagriddview.
I am using the following code
Private Sub dg1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg1.CellClick
If (e.ColumnIndex = 2) Then
TextBox1.Visible = True
TextBox1.Left = 42
TextBox1.Top = 19 * (Me.dg1.CurrentCell.RowIndex + 1)
TextBox1.Height = dg1.CurrentRow.Cells(0).Size.Height
TextBox1.Width = dg1.CurrentRow.Cells(0).Size.Width
End If
End Sub
as the row index increases , the coordinates flaws increases.
|
|
|
|
|
This doesn't place a textbox in the cell. It moves an existing textbox OVER a cell in the datagrid. The offset flaw increases as the textbox moves down because your probably off by one pixel in one side of the multiplication to set the Top value. Instead of 19, try multiplying the row height of the currently selected cell.
Though, why are you hovering a TextBox over a cell in a datagrid anyway?
|
|
|
|
|
Hi, I have a word template document and I need to programming in Access VBA code to create a new word document based on the template that i have. Suppose that my template is locate c:\mytemplate\MyTemplate.dot . I also need to write some value into the specific line of word document. If anyone have a sample code please let me know.
Thank in advance!
|
|
|
|
|
Can anyone tell me how to add a custom dll control at runtime? I can add the control at runtime but the control is not seen on the form. I can add the control at design time and everything works fine.
|
|
|
|