|
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..
|
|
|
|
|
This is in the article that he referenced.
Click on "&Open". You will see in the Properties window "Name", "Arguments", "Verb". Verb is hidden from the user, but is the key that is stored in the registry. Leave it the same as the name, but without the "&". The default for "Arguments" is "%1", which means to pass the full path and filename to your application. You can add other stuff here as well, if you need to pass flags to your application to do special stuff. All this information is getting passed to your application on the command line, so you'll need to be familiar with the "Environment.CommandLine" object.
It looks like the information you need will be passed in the command line that starts your application. So use enviroment.commandline to access it
|
|
|
|
|
tnx a lot
|
|
|
|
|
Hello everyone,
In our project, we created a SSIS package to load data from Excel into SQL2005 database.
Right now, I want to write code (whatever is vb.net, Vbscrip, or SQL code) to change the existed excel worksheet name. If anyone can give me any suggestion with it, I will really appreciate it.
Jane
|
|
|
|
|
Sub Summary_cells_from_Different_Workbooks_1()
Dim FileNameXls As Variant
Dim SummWks As Worksheet
Dim ColNum As Integer
Dim myCell As Range, Rng As Range
Dim RwNum As Long, FNum As Long, FinalSlash As Long
Dim ShName As String, PathStr As String
Dim SheetCheck As String, JustFileName As String
Dim JustFolder As String
ShName = "summary" '< Change
Set Rng = Range("D3") '< Change
'Select the files with GetOpenFilename
FileNameXls = Application.GetOpenFilename(filefilter:="Excel Files, *.xls", _
MultiSelect:=True)
If IsArray(FileNameXls) = False Then
'do nothing
Else
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Add a new workbook with one sheet for the Summary
Set SummWks = Workbooks.Add(1).Worksheets(1)
'The links to the first workbook will start in row 1
RwNum = 0
For FNum = LBound(FileNameXls) To UBound(FileNameXls)
ColNum = 1
RwNum = RwNum + 1
FinalSlash = InStrRev(FileNameXls(FNum), "\")
JustFileName = Mid(FileNameXls(FNum), FinalSlash + 1)
JustFolder = Left(FileNameXls(FNum), FinalSlash - 1)
'copy the workbook name in column A
SummWks.Cells(RwNum, 1).Value = FileNameXls(FNum)
'build the formula string
PathStr = "'" & JustFolder & "\[" & JustFileName & "]" & ShName & "'!"
On Error Resume Next
SheetCheck = ExecuteExcel4Macro(PathStr & Range("A1").Address(, , xlR1C1))
If Err.Number <> 0 Then
'If the sheet name not exist in the workbook the row color will be Yellow.
SummWks.Cells(RwNum, 1).Resize(1, Rng.Cells.Count + 1).Interior.Color = vbYellow
Else
For Each myCell In Rng.Cells
ColNum = ColNum + 1
SummWks.Cells(RwNum, ColNum).Formula = "=" & PathStr & myCell.Address
Next myCell
End If
On Error GoTo 0
Next FNum
' Use AutoFit for setting the column width in the new workbook
SummWks.UsedRange.Columns.AutoFit
SummWks.UsedRange.Value = SummWks.UsedRange.Value
SummWks.UsedRange.Columns("B:B").TextToColumns Destination:=Columns("E:E"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, _
TrailingMinusNumbers:=True
SummWks.UsedRange.Columns("C").Formula = "=sum(E1:IV1)"
MsgBox "The Summary is ready, save the file if you want to keep it"
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End If
End Sub
try it............
Imagine the I.T
|
|
|
|
|
Someone please help!
I am using the following code:
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
Me.Text = "Local IP: " & CType(h.AddressList.GetValue(0), IPAddress).ToString
In Windows XP, this results in the top bar showing the local first ip address
eg:
Local IP: 192.168.1.11
When this same code is executed on Windows Vista,
it gives:
Local IP: fe80::7811:d6fc:e34d:2102%8
which is the ipv6 address.
My question is - how can I make sure my code retrieves the ipv4 address (always - even on vista).
I am stumped...
(I already have a way of detecting if I am running on Vista or not as the OS - in case it requires
different code..)
I can't find anything on this issue on the net either which is annoying...
Thank you for any feedback on this..
|
|
|
|