|
OK, sounds good. Thank you.
|
|
|
|
|
Hi to all, am new with VB.net an need help with events handling.
From the following code, How can I identify which of the two event was triggered. Is this possible?
Private Sub BHDay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHDay.TextChanged, BHDay.LostFocus
Some Validation Code...
End Sub
Thanks,
|
|
|
|
|
There's no way to tell which event triggered the handler using this code.
A better method would be to break this into two seperate handlers.
Private Sub BHDay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHDay.TextChanged
' Code to handle specific case of TextChanged
' Then call CommonCode to execute code that should run if either event is triggered.
End Sub
Private Sub BHDay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHDay.LostFocus
' Code to handle specific case of LostFocus
' Then call CommonCode to execute code that should run if either event is triggered.
End Sub
Private Sub CommonCode()
End Sub
|
|
|
|
|
Abit stuck at the moment
I need some help all i need to do is to copy the content of a.txt into b.txt?
i don't really know where to start, so if anybody can help that would be great
Cheers
Dan
|
|
|
|
|
Like d@nisch explained[^], check out the System.IO namespace. The method CopyTo [^] does what you're looking for - it copies the contents of file A into file B.
I are Troll
|
|
|
|
|
Dim contents As String = My.Computer.FileSystem.ReadAllText("a.txt")
My.Computer.FileSystem.WriteAllText("b.txt", contents, False)
|
|
|
|
|
This is the third time you've asked this. The second time was only a few hours before this time. Perhaps you should continue to reply on the older thread, when it's still visible ? Perhaps when you decide you need to ask again, you should explain what you were told before, what you tried, and why you're still stuck ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
This is the code:
With Adodc1.Recordset
.MoveFirst()
Do While .EOF = False
Debug.Print(.Fields("Name").Value)
.MoveNext()
Loop
End With
The problem: Adodc1.Recordset.Eof is never set to False thus the loop never ends. Is this a bug in VB or is there some option/parameter that I'm not using?
|
|
|
|
|
If you are using VB Express 2008, why are you still using RecordSet?
Shouldn't you be trying to move this to DataSet?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for your reply. Use of Datasets is another topic. The VB Express documentation clearly states "You can use the BOF and EOF properties to determine whether an Recordset object contains rows or whether you have gone beyond the limits of an Recordset as you move from row to row."
|
|
|
|
|
Sorry for the delay in responding, I had to step out for a while.
Les Singletary wrote: The VB Express documentation clearly states "You can use the BOF and EOF properties to determine whether an Recordset object contains rows or whether you have gone beyond the limits of an Recordset as you move from row to row."
What a shame they don't give an example.
I searched on my local MSDN before my previous reply and all I could find was the ADO compared to ADO.Net page for a search for RecordSet. For EOF I got a reference to a completely unrelated Eof() function.
Since your reply I Googled Recordset.EOF and got quite a lot of hits although not many had code samples. One I looked at suggested
Do While Not .EOF
........
.......
Loop
If you haven't already solved this, I hope that this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks again. I too found lots of usless post on the web for RecordSet.Eof. The example you posted depends on VB correctly setting the .Eof property when that event occurs, which as far as I can determine, it does not.
|
|
|
|
|
Yes, it does. I tried it with a small query and had no issues. VB doesn't set that value, the internals of the ADODB object does.
|
|
|
|
|
Yes, I know that the AdoDb works as I said. The problem is with AdoDc.
|
|
|
|
|
The answer doesn't change. That property value is only set by the internals of the object, not by VB.
|
|
|
|
|
I am trying to remember something weird about the .BOF and .EOF properties from certain data access controls from my Delphi Days. It went something along the lines that if you set .BOF to true it actually 'points' to an imaginary record one before the physical BOF. So I am wondering if there might be something similar going on in your case. i.e. Is there just one record returned and .EOF is pointing past that record.
I hope that that makes some sort of sense. Trying to explain it to anyone always confused me in Delphi and it appears not to have got any better.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You have VB.NET Express and you're using the old ADO Data Control?? Why?? The ADO.NET methods are faster and more flexible.
No, this isn't a bug in VB. How many records were returned in the query?
|
|
|
|
|
Thanks for your reply. Using ADO.NET is another matter. The number of records returned depends on the number of records in the database at the time. I know how to "get around" this problem. However, I am searching for an answer to how to get the ADODC control to function properly using the .RecordSet.Eof property. BTW, the ADODB object functions correctly.
|
|
|
|
|
Les Singletary wrote: Using ADO.NET is another matter.
That doesn't answer the question. Using ADO.NET instead of deprecated, obsolete objects, would most assuredly solve your problem, as well as prevent others, such a binding controls to your data. You cannot bind any .NET control or class to the data held in the old ADOxx objects. This severely limits your ability to do data manipulation while using those objects.
|
|
|
|
|
Thanks again for your reply. However, your last reply opens up a whole "can of worms" that I prefer not to get into with this particular problem. I would like to use ADODC if it can be made to work. I will try to post the complete zipped "solution" file later.
|
|
|
|
|
Don't bother to post the project. Noone will download it and execute untrusted code.
|
|
|
|
|
Here is the code for the entire program demostrating the problem. I don't seem to be able to attach a zipped file. You will need to create a form with three controls: Button1, Button2, and Adodc1. Name the form "frmAdoDc". You will need a simple MS Access DB named "Stu" with a table named "Student". The table contains 2 columns: "Id" and "Name". Put the database in the same folder where you store the code below. I hope some one can find how to make this code work. Thanks!
---------------------------------------------------------
Imports ADODB
Public Class frmAdoDc
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iX As Integer
With Adodc1.Recordset
.MoveFirst()
Do While Adodc1.EOF = False And iX < 10
iX = iX + 1 'needed because of problem
Debug.Print(.Fields("Name").Value)
.MoveNext()
Loop
End With
End Sub
Private Sub frmAdoDc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sDir As String = "AdoDc_Example" 'path of root folder for solution
Dim sDb As String = "Stu.Mdb" 'name of database
Dim sFid As String 'path & name of database
Dim iPos As Integer
'---build path where DB is regardless of where this test is stored
sFid = My.Application.Info.DirectoryPath
iPos = sFid.IndexOf(sDir)
sFid = sFid.Substring(0, iPos + sDir.Length + 1) & sDb
With Adodc1
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFid & ";"
.RecordSource = "Student"
.Refresh()
End With
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim iX As Integer
Dim db As New ADODB.Connection
Dim rs As New ADODB.Recordset
db.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\VbNet_Test\AdoBasics\Stu2.mdb;")
rs.Open("Select * From Student", db, CursorTypeEnum.adOpenDynamic)
With rs
.MoveFirst()
Do While iX < 10 And .EOF = False
Debug.Print(.Fields("Name").Value)
iX = iX + 1
.MoveNext()
Loop
End With
rs.Close()
db.Close()
End Sub
End Class
|
|
|
|
|
In the code that I posted earlier, Button2 works (AdoDb) whereas Button1 does not (AdoDc) yet the code for both is essentially the same. If I understand Dave Kreskowiak correctly, the problem is in AdoDc object and not in VB. I find this interesting for an OOL. One would think that both objects (adodc & abodb) would take advantage of the same underlying objects and classes for the same methods (e.g. MoveNext) since it represents the same functionality. In any event, it appears that the bug in AdoDc unless someone can demonstrate otherwise.
|
|
|
|
|
HEllo,
I depretly need someones help,
i am using vb.net and have nearly finished a program all i need to do is basically clear data in a txt document after reading it e.g hello.txt
i am using
Dim objReader As New System.IO.StreamReader(FILE_NAME)
where i have dimed the FILE_NAME as string ("hello.txt")
however i then added
Dim objwriter As New System.IO.Streamwriter(FILE_NAME)
and tried
objwriter.writeline("")
which then came up with an error message saying file currently in use. Is there no way that you can read the file and then write data into i?????
If anybody can help me that would be very good
Thanks
Dan
|
|
|
|
|
AFAIK you can't edit a file. You will need to recreate it.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|