|
pashitech wrote: i am poor at english,
Do not cross post, means, please post your question in only one forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
following code I used to write text file.
IO.File.Create("C:\test.txt")<br />
IO.File.OpenWrite("C:\test.txt")<br />
For X = 1 To 20<br />
IO.File.AppendAllText("C:\test.txt", "myname")<br />
Next
but it apear foloowing ERROR messege
The process cannot access the file "C:\test.txt" because it is being used by another process.
what I want, that ones open the text file and write details what i want.
how can I handle this
Thiwa
|
|
|
|
|
Do you call Close on the file ? If you don't, then when you try to run it again, the first process may still have the file open. This is because .NET does not have proper destructors, this never happened in C++
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
There is no Close method in IO.File method
Thiwa
|
|
|
|
|
IO.File gives you access to static methods only. You should create a file object, instead of calling static methods, or you should call the WriteAllText method, which I know both opens and closes the file. Fact is, this error means your file is still open.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Dim FileStream As IO.StreamWriter
Dim x as integer
FileStream = New IO.StreamWriter("C:\Test.txt") , True)
for x= 1 to 20
FileStream.WriteLine("myname")
next
FileStream.Flush
FileStream.Close
Give that a try. It uses a stream and keeps it open till you are done writing your data.
|
|
|
|
|
Thank u very vary much........
|
|
|
|
|
I don't think that you have really gotten into the object oriented way of thinking... Let's look at your code.
First you create a file:
IO.File.Create("C:\test.txt")
The Create method returns a FileStream object, but you don't take care of the return value, so you have a open file with no means of writing to it or closing it.
Then you try to open the same file again:
IO.File.OpenWrite("C:\test.txt")
This of course fails, as the file is already open. Even if it did not fail, the OpenWrite method also returns a FileStream object that you just throw away.
Then you try to write to the file:
For X = 1 To 20<br />
IO.File.AppendAllText("C:\test.txt", "myname")<br />
Next
Even if this would work if the file wasn't already open, this is a very inefficient way of writing to a file. Each iteration in the loop would open the file, write a string to it, then close it.
For writing a text file, you should rather use a StreamWriter than a FileStream.
Dim file As StreamWriter<br />
Dim x as Integer<br />
file = IO.File.CreateText("c:\test.txt")<br />
For x = 1 to 20<br />
file.Write("myname")<br />
Next<br />
file.Close()
---
single minded; short sighted; long gone;
|
|
|
|
|
Can anyone give me a SQL statement to create table and field for MS Access?
Thanks
................
|
|
|
|
|
Does normal SQL not work ? I thought with Access you create them visually ? Or do you mean you want code that runs from VB ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Create Table MyTable(MyField1 Text(10), MyField2 Integer, ...)
|
|
|
|
|
|
Good Morning Freinds,
I wnt to generate report on selecting year from the ComboBox/DateTimePicker.
If I Wnt to display only year in combo/datetimepicker, Please tell me wht shuld i do?
My application is in vb.net(Winforms).
priya
|
|
|
|
|
If you want to use the datetimepicker control you need to do something like this:
datetimepicker1.Format =DateTimePickerFormat.Custom
datetimepicker1.CustomFormat ="yyyy"
this will still show the calender. I personally would use a normal combobox and fill it with the proper values
-- modified at 0:18 Tuesday 13th February, 2007
|
|
|
|
|
Thanks for ur help,
I used the same for dateTimepicker.
& this not solves problem.
As u say use combobox, Will you please tell me how should i feel all year values in combobox?
priya
|
|
|
|
|
give this a try
Dim x As Integer
Dim yearStart As Integer = 1900
Dim yearEnd As Integer = 2155
For x = yearStart To yearEnd
ComboBox1.Items.Add(x)
Next
ComboBox1.SelectedIndex = Now.Year - yearStart
|
|
|
|
|
hi!priya....
how r u?
try this code...
Dim I As Integer
Private Sub frmCalender_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For I = 1 To 12
cboMonth.Items.Add(I)
cboMonth.SelectedIndex = 0
Next
'get the years for combo box
Dim Year As Integer
For Year = 1900 To CInt(Val(Format(Now, "yyyy")))
cboYear.Items.Add(Year)
cboYear.SelectedIndex = 0
Next
End Sub
Private Sub cboMonth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboMonth.SelectedIndexChanged, cboYear.SelectedIndexChanged
cboDate.ValueMember = Str(Date.DaysInMonth((cboYear.SelectedIndex), cboMonth.SelectedIndex + 1))
End Sub
have a good day........
Imagine the I.T
|
|
|
|
|
"cbComLevel" is a combo box(dropdown list) and "ComLevelDetail" is a datatable contains data from database.
i using this method to bind data to combo box.
'---------------------------
With cbComLevel
.DataSource = ComLevelDetail
.DisplayMember = "ComLevel"
.ValueMember = "ID"
End With
Dim ComLevelID As Integer = CInt(cbComLevel.SelectedValue.ToString)
label1.text = ComLevelID
'---------------------------
so this code work fine while i compile the application.
but while i add new code below in order to get the selected value from this combo box while the combo box selected index changed:
'---------------------------
Private Sub cbComLevel_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbComLevel.SelectedIndexChanged
Dim ComLevelID As Integer = CInt(cbComLevel.SelectedValue.ToString)
label1.text = ComLevelID
End Sub
'---------------------------
the error message come out :
Conversion from string "System.Data.DataRowView" to type 'Integer' is not valid.
I still no idea how to solve it, Who know what happen?
Best regards,
Chee ken
|
|
|
|
|
It looks like the object you are returning is a DataRowView Object.
Try
Dim ComLevelID As Object = cbComLevel.SelectedValue
Set your breakpoint on the next line and look at the value of ComLevelId in Watch Window to see exactly what you are returning and modify your code to fit.
|
|
|
|
|
Thanks for reply.
i put a breakpoint on that code line, then the watch window return value "Nothing" for comlevelID, and i press F10,while it jump to next code line, the watch window show that the comlevelID is "{System.Data.DataRowView}". Is it cannot get the selectedvalue?
Best regards,
Chee ken
|
|
|
|
|
What is happening is you are returning a object not a integer, so what happens is when you use the toString method you get the text of the type, in this case the System.Data.DataRowView. If you made the changes I suggested you should be looking at the object and not the Text. You should be able to expand the object to see what property or method you need, most likely :
cbComLevel.SelectedValue.Value or cbComLevel.SelectedValue.Row
|
|
|
|
|
I wrote a macros for a customer in Excel 2003. He didn't tell me he used Excel 2000 until after the project and like an idiot I forgot to ask. The macros will not run on his version of Excel 2000.
So he got a version of Excel 2003 and the macros will still not work for him. I have tested this macros on other machines using 2003 and they all work correctly for me. I live in the US and the customer lives in the UK. When he runs the macros it immediately goes into the debugging window and highlights a bit of code that simply references the path of the existing folder to a variable. The exact code is:
DestFolder = ThisWorkbook.Path & "\"
There is a compile error with a message that the data folder or project cannot be accessed. The folder the macros resides in that I zipped and sent him was not password protected by me nor can I think of why he cannot access the path to the folder with this bit of code.
Does anyone know if there any issues between UK versions and US versions of Excel that I don't know about? Any ideas?
Also would it help for him to download .NET framework considering he is wishing to use macros? Would that clear up any of the compiler issues?
|
|
|
|
|
how to get the filename of the file being open and pass it to the associated application..
|
|
|
|
|
|
yeah i have it already.. my problem is how to get the filename of file being opened.. i want that my application know the filename of the file being opened..
|
|
|
|