|
There's at least one article on CP about this, I am sure.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
Hi, the example u link me to is done by C programming. Is there any in vb.net language?
|
|
|
|
|
Actually, it's done in C# and should be easily translatable into VB.NET. Just Google for "C# to VB.NET conversion" and you'll find some online tools to do it. You will, of course, have to clean up the code by hand since no tool is 100% perfect.
|
|
|
|
|
You expect him to write actual code ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
No, not really!
|
|
|
|
|
i am a new to visual basic .net and have a question. i was wondering if there is a book available that contains sample projects that i can build to gain experience with vb .net?
Thanks.
Dave.
|
|
|
|
|
That's an awesome question to be asking. Most books come with sample projects. The other option is to look through the articles here on Code Project, download and build some. But, working through a book is almost certainly the best first step. I'd suggest you look up some books on Amazon, look for books with a good rating, then before buying, check on the publishers website for code downloads ( unless the book comes with a CD, then you're pretty safe I reckon )
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I'm sorry if there is already a post somewhere about this, I obviously didn't find it. I was wondering if there is a way in VB.NET to make a string variable or object in to actual executable code. For example.
Dim S1 As String = Textbox1.text
Dim S2 As String = Textbox2.text
S1
S2
Whereas S1 and S2 are input codes form the textboxes. Thanks in advance.
modified 8-Sep-21 21:01pm.
|
|
|
|
|
|
I've made a simplified VB.NET project that more or less isolates the problem I'm running into. It can be downloaded here:
http://www.4shared.com/file/74297380/b8e060ed/parserprog.html
Before running this, you'll need a fairly large file (2GB should do it). Any file will do if it's big enough. Copy it into the debug directory where the executable is compiled, and rename it "file.bin."
I'm trying to make a function that parses a large amount of data, and opens up a form that displays an animation that shows this function's progress. The problem is that if you alt+tab to another window and then alt+tab back, the form stops responding and the animation stops until the parsing is complete. I've tried experimenting with threads, but none of the multithread approaches I've attempted made a difference.
The form1.vb code for the simplified project, which currently does not use multithreading, looks like this:
Imports System.IO
Public Class Form1
Public Sub drawlazor(ByVal progress As Double)
lazorbar.Size = New Size(lazorbar.Size.Width, 330 * progress)
Refresh()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Dim oRead As New FileStream("file.bin", FileMode.Open)
Dim index As Int64 = 0
Dim filesize As Int64 = New FileInfo("file.bin").Length
Dim count As Int32 = 1024 * 1024
Dim oBuf(count) As Byte
dostuff(oBuf)
While index < filesize
If (count > filesize - index) Then
count = filesize - index
Array.Resize(oBuf, count)
End If
oRead.Read(oBuf, 0, count)
index += count
drawlazor(index / filesize)
End While
End Sub
Private Sub dostuff(ByVal oBuf() As Byte)
' pretend this is a parsing function that takes exactly 20ms to parse 1MB
Threading.Thread.Sleep(20)
End Sub
End Class
|
|
|
|
|
Well, it has to be done using a background thread. Move the file operation code to the background and have it report it's status. This will free up the UI thread for repainting when Windows needs you to.
Check into the BackgroundWorker class for examples.
|
|
|
|
|
Hi,
With a single thread it will never work the way it should.
I have seen many examples of splash screens and progress dialogs that work the wrong way.
AFAIK there is only one right way to do any one of them:
1. keep the splash screen, progress dialog, animation, whatever, in the GUI thread.
2. put the time consuming stuff in a separate thread or backgroundworker.
That way, the time consuming stuff will run independent of what happens to your forms; and your forms (including the ones that show animation) will continue to interact with you, no matter what.
|
|
|
|
|
Here's my current attempt to make it work using a background worker. Am I doing this wrong? Because it still stops responding under the same circumstances as when I do it single threaded:
Imports System.IO
Imports System.ComponentModel
Public Class Form1
Private worker As System.ComponentModel.BackgroundWorker
Private progress As Double
Public Sub drawlazor(ByVal progress As Double)
lazorbar.Size = New Size(lazorbar.Size.Width, 330 * progress)
Refresh()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
progress = 0
worker = New System.ComponentModel.BackgroundWorker
worker.WorkerReportsProgress = True
worker.WorkerSupportsCancellation = True
AddHandler worker.DoWork, New _
DoWorkEventHandler(AddressOf OnWork)
worker.RunWorkerAsync()
While progress < 1
System.Threading.Thread.Sleep(20)
drawlazor(progress)
End While
worker.CancelAsync()
End Sub
Private Sub OnWork(ByVal sender As Object, _
ByVal e As DoWorkEventArgs)
Dim oRead As New FileStream("file.bin", FileMode.Open)
Dim index As Int64 = 0
Dim filesize As Int64 = New FileInfo("file.bin").Length
Dim count As Int32 = 1024 * 1024
Dim oBuf(count) As Byte
dostuff(oBuf)
While index < filesize
If (count > filesize - index) Then
count = filesize - index
Array.Resize(oBuf, count)
End If
oRead.Read(oBuf, 0, count)
index += count
progress = index / filesize
End While
End Sub
Private Sub dostuff(ByVal oBuf() As Byte)
' pretend this is a parsing function that takes exactly 20ms to parse 1MB
Threading.Thread.Sleep(20)
End Sub
End Class
|
|
|
|
|
Hi,
your computations now are on a separate thread/BGW which is good.
but you still have a Thread.Sleep running on the GUI thread, which is a very bad idea.
and your Form1_Load handler still is waiting for the calculation to have finished,
which is absolutely not good. It prevents the GUI to do normal stuff, such as redrawing everything when you uncover the form.
It is the calculating thread/BGW that should trigger the animation/progress reporting;
that is what BGW.ReportProgress() is for.
Hence:
- remove the Sleep in Form_Load
- remove the while loop from Form_Load
- add animation to dostuff() through ReportProgress (which optionally accepts an object)
|
|
|
|
|
I think I got it working. Thanks!
|
|
|
|
|
you're welcome.
|
|
|
|
|
ikantspelwurdz wrote: While progress < 1
System.Threading.Thread.Sleep(20)
drawlazor(progress)
End While
It seems you don't get how threads work. Your thread will post an event when it's finished. This is where your program should hide the UI and continue. Until then, any progress bar should be updated in the progress changed event, and this sort of code just plain should not exist in your project.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi all...
I want to create a program using VS2005 (VB) that read an image file(.jpg,.bmp extension) and edit it into a text editor.
Text written in image can be edited using text editor and modified document can be again save to a image file.
Give me suggestions that how can I do it.
Thanks.
Gagan
|
|
|
|
|
This might be able to help: http://www.codeproject.com/KB/recipes/Image-Steganography.aspx[^]
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
How do you want to edit it in a text editor ? Do you mean read the text off the image ? You need an OCR library for that.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I have the name of a range stored in a string, I wish to change the contents of a specific cell. I have the row number saved in a variable, usually I would do this by typing
[ColumnName].Cells(index) = value
If I have ColumnName stored in a variable, how could I change a cell based off an index?
(Note: I tried [ & ColumnName & ].Cells(index)...)
|
|
|
|
|
I'm not Excel VBA expert, but I think you're looking for the Range object. Maybe something like:
Range("B2").Cells(1).Value = something
|
|
|
|
|
Yeah that solved it alright, just had to do Range(ColumnNameVariableNoQuotes).Cells(Index).Value = Something
thanks Dave
|
|
|
|
|
I have 6 checkbox in my form. I have to export the name of checkbox into database in a single field. It depands on the user how many checkbox he selects.
|
|
|
|