|
I need this to update a progress bar.First a DOS service is run in the background , which writes a log file as it runs , the percentage info can be retrieved (there is no other way to get the percentage since this is a dos service) from the log file,but i get an error that the file is being used by another process(the DOS one).Its pointless to get info from the log file after the DOS process completes,as i need it to update a progress bar.Is there any solution to this?
Thanks in Advance,
Regards,
Vivek
|
|
|
|
|
Hi,
two attempts:
1.
I think the following code works even when the file is still open (and being written to)
by another process:
FileInfo fi=new FileInfo(filename);
log("size="+fi.Length);
2.
there is a solution if the other process has created the file with a share mode of
read or readwrite, meaning it allows other processes to simultaneously read or readwrite
the same file.
If it did, you now can open the same file with FileMode.Read and FileShare.ReadWrite
(i.e. "I want to read" and "I allow others to read and write").
And one remark:
files get buffered, the buffer gets written to disk for sure only when one closes the
file, or performs a flush operation (forcing the physical write). So for small files
that dont flush, watching the size might not be a good progress indication.
|
|
|
|
|
Thanks a lot for giving the idea of using the file's length.
Vivek
|
|
|
|
|
If the other process opens and writes to it's file, denying shared read, there's nothing you can do. If it allows shared read by other applications while it's writing, then you can open the file using:
Dim fs As New FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
|
|
|
|
|
I'm struggling to work out how to iterate through treenodes. What I've done is programmatically created a TreeView, creating a (DatabaseName) header as follows:
trvDbNameNormal = Me.TreeView1.Nodes.Add("DatabaseName", "Common tables: " & Me.cmbDatabases.Text.ToUpper, 0, 0)
The children (table names) within this node are created by:
nodeTable = trvDbNameNormal.Nodes.Add(strTable, strTable, 1, 1)
What I want to do is iterate through these children to perform some SQL on the table names - but I can't figure out how to get the contents of these nodes.
|
|
|
|
|
The TreeNodesCollection class has an indexer so you can access each Node by trvDbNameNormal(0) or trvDbNameNormal(strTable) .
The TreeNode class has a Text property which will return strTable name in the case of your code.
Then simply write a recursive algorithm to walk the tree.
something like:
Private Sub walkTree(t as TreeNode)
For i as Integer = 0 To T.Nodes.Count -1
' Do something usefull here
walkTree(T.Nodes(i))
Next
End Sub
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
hi
I want to convert a HTML document into a PDF/CHM. Could someone help me? Thanks.
|
|
|
|
|
For PDFs...
Pdfizer, a dumb HTML to PDF converter[^]
CHMs are a bunch of html files compiled together. You can't directly convert an html to chm because you have to know where each page begins and ends and edit the TOC, search, and index.
|
|
|
|
|
I've been looking at my (very simple) code for the better part of 2 hours now and just can't seem to find my mistake.
I want to draw an arrow (pointing down) on a label.
so I used the fillpath methode but it doesn't work, the strange thing is that when I use the drawpath methode it does work.
here is my code:
Private Sub drawarrow(ByVal g As Graphics)<br />
If Me.Height > 30 Then<br />
Dim widtharrow As Integer = 4<br />
Dim heightarrow As Integer = 4<br />
Dim heightmargin As Integer = 3<br />
Dim x1 As Integer = (Me.Width / 2) - (widtharrow / 2)<br />
Dim y1 As Integer = Me.Height - (heightarrow + heightmargin)<br />
Dim x2 As Integer = (Me.Width / 2) + (widtharrow / 2)<br />
Dim y2 As Integer = Me.Height - (heightarrow + heightmargin)<br />
Dim gp As New GraphicsPath<br />
gp.AddLine(x1, y1, x2, y2)<br />
x1 = (Me.Width / 2) - (widtharrow / 2)<br />
y1 = Me.Height - (heightarrow + heightmargin)<br />
x2 = Me.Width / 2<br />
y2 = Me.Height - heightmargin<br />
gp.AddLine(x1, y1, x2, y2)<br />
x1 = (Me.Width / 2) + (widtharrow / 2)<br />
y1 = Me.Height - (heightarrow + heightmargin)<br />
x2 = Me.Width / 2<br />
y2 = Me.Height - heightmargin<br />
gp.AddLine(x1, y1, x2, y2)<br />
gp.CloseFigure()<br />
'gp.CloseAllFigures()<br />
'gp.FillMode = FillMode.Alternate<br />
<br />
g.FillPath(Brushes.Blue, gp)<br />
'g.DrawPath(Pens.Black, gp)<br />
gp.Dispose()<br />
End If<br />
End Sub
if anyone spots what my mistake is please let me know
thanks
|
|
|
|
|
Hi,
you want a filled triangle, right ?
I am afraid FillPath is not smart enough to correctly fill a path specified in
random order, as you did.
I would use fewer formula, set three points (x1,y1), (x2,y2) and (x3,y3)
then do AddLine(1,2), AddLine(2,3), AddLine(3,1) so the path steps through the points
1,2,3 in the right order and closes back on itself. This will give no difference to DrawPath
but it will allow FillPath to understand and fill your polygon.
BTW: in fact you dont need the third line, FillPath closes the shape all by itself
if first and last point are not the same.
Hope this helps.
|
|
|
|
|
works perfectly now
thanks
and with way less code then I did it (I think I'll take a break now )
|
|
|
|
|
you're welcome.
yes, one of my rules is: when it is wrong, trim it rather than grow it ...
Greetings from Antwerp.
|
|
|
|
|
I'm making a log file and want to have a string of apostrophes to separate parts of the log file.
Dim divider As String
Dim t As TextStream
'other declarations are there like FileSystemObject but its irrelevant. The log works besides this string I desire'
divider = "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''"
t.WriteLine(divider)
Now I've tried using the escape character \', using hyphens (-) and asterisks(*). Any ideas?
|
|
|
|
|
Hi, string class has a constructor specially for you: new String(char, repeatCount)
|
|
|
|
|
Just curious if there is some simple code, which can be modified and implemented to click a button in an app.
|
|
|
|
|
No. Controlling an application through it's user interface is complicated and problematic at best.
|
|
|
|
|
This requires getting the handle of the other app's windows including the button that you want to click. You can then send it a message that tells the button it has been clicked. It's all Win32 API work, not terribly hard, but you can cause problems if you don't follow the rules, and you may never know all of the rules. I don't have the code any more, or I don't know where it is, but I adapted it from Bill McKinney's excellent book: Hardcore Visual Basic, Second Edition, Copyright 1997, Microsoft Press. Unfortunately it is no longer in print.
If this is important enough, and there is no other way, then I recommend you find a used copy of it. Another excellent resource is: Visual Basic Programmer's Guide to the Win32 API bu Dan Appleman. This is still in print and I consider it to be the bible of Win API programming.
Test, test, and test again.
Tom Garth
Developer
R. L. Nelson and Associates, Inc., Virginia
|
|
|
|
|
Thank you very much. I will look into these books.
If any one has general code using Win32 API involving a simple
button click, this will save me time.
Until then, I am off to the library!
|
|
|
|
|
I want to update a quantity field in SQL Server from VB. First I have to check the value of the quantity field and then subtract a given amount from it. I thought I have to do a SQL select first to get the value and then do an SQL update. After the Sql select I need to lock the record until the Sql update is done. How can I lock the record? Or can I somehow update the record with the new quantity without using an Sql select?
|
|
|
|
|
update table set column = column - substraction
|
|
|
|
|
Locking a record is just about never a good idea, and in your case, you don't need to do this. If you have to update a column, all you have to do is execute a single SQL statement. Say you want to reduce a value by 5:
UPDATE tableName
SET columnName = columnName - 5
WHERE someRecordId = someIdValue
|
|
|
|
|
hi
am working on a project of a school that has many hostels. looking out for someone that will give me a code that will automatically select a hostel from a list of hostels and give it to the client filling the form. am using VB 6.0 fr this particular project
thanks
Daser solomon
Nigeria
Helping someone is simply helping oneself
|
|
|
|
|
What exactly do you want here is what I understand:
You're client logs in (or something) then you want a hostel that is pecificly for that client to be displayed.
If this is the case you'll have to keep track of wich hostel is 'linked' to wich client (you can do this in you're db if you use one)
then it is only a mater of selecting the right hostel from the list (wich I presume is gathered from a db) and this can be done in de sql string with an ID or something like it.
if ofcourse it doesn't matter wich hostel you give to the client (random one) look at the function random and give you're hostels an numeric id that way you can easly select one.
|
|
|
|
|
a tanks
i agree with this:
if ofcourse it doesn't matter wich hostel you give to the client (random one) look at the function random and give you're hostels an numeric id that way you can easly select one.
i have a thought question from your answer. is it that you are going to put those hostel in an array? if it is write then can u plz help me with a little code that will take care of that case
helping someone is automatically helping self
|
|
|
|
|
here a (very) simpel example of how you can do this
Public Class Form1<br />
Dim l As New List(Of hostels)<br />
Private Sub RibbonDropDownButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonDropDownButton1.Click<br />
Dim i As Integer<br />
Dim r As New Random<br />
i = r.Next(0, 10)<br />
For Each h As hostels In l<br />
If h.id = i Then<br />
MessageBox.Show(h.name)<br />
End If<br />
Next<br />
End Sub<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim i As Integer<br />
For i = 0 To 10 'just to fill the list with some values<br />
l.Add(New hostels(i, "test" & i))<br />
i += 1<br />
Next<br />
End Sub<br />
End Class<br />
<br />
<br />
Public Class hostels<br />
Dim iid As Integer<br />
Dim sname As String<br />
Public Property id() As Integer<br />
Get<br />
Return iid<br />
End Get<br />
Set(ByVal value As Integer)<br />
iid = value<br />
End Set<br />
End Property<br />
Public Property name() As String<br />
Get<br />
Return sname<br />
End Get<br />
Set(ByVal value As String)<br />
sname = value<br />
End Set<br />
End Property<br />
Public Sub New(ByVal iid As Integer, ByVal sname As String)<br />
Me.id = iid<br />
Me.name = sname<br />
End Sub<br />
End Class
as I said: very simpel one
if you work with a db you'l have to fill the list with what you extract from you're db
depending on wich version you use of vb you might have to use an 2 dimansial array instead of a list
hope this helps you on you'r way
|
|
|
|