|
This code is not displaying the contents of my text file.. Am I missing something?
Dim TestFile As StreamReader
Dim LineofText As String
TestFile = File.OpenText("C:\dvdpath.txt")
Do Until TestFile.Peek = -1
LineofText = TestFile.ReadLine()
Console.WriteLine(TestFile)
Loop
TestFile.Close()
I'm actually trying to read a file that is over 800k in size and am just trying to learn how to open and read simple text files first. I've already added the System.IO namespace and it compiles fine.. When I execute it an empty window shows and it should show at least 4 lines of text.
Thanx in advance for any assistance!
-mark-
|
|
|
|
|
Try this:
Dim TestFile As StreamReader
Dim LineofText As String
TestFile = File.OpenText("C:\x.txt")
Do Until TestFile.Peek = -1
LineofText = TestFile.ReadLine()
Console.WriteLine(LineofText)
Loop
TestFile.Close()
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
Thanx!! Was a basic mistake I guess
-Mark-
|
|
|
|
|
I have a program that accepts an Arrival Date and a Departure Date. I need to calculate the number of "Years if any, Months if any, Weeks if any and Days if any" between the arrival and departure date. Datediff does not work for me. Any Idea's
Regards
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
What do you mean that datediff doesn't work?
If you want something like "1 year, 2 months, 3 weeks and 5 days" then you have to implement the function yourself.
E.g.: you can use DateDiff to find out how many years is the difference between Arrival and Departure, display year, then use DateAdd to change one of the dates (e.g. add the years to Arrival Departure date) and use DateDiff to find out how many months the difference is now, display months, then use DateAdd to add months to Arrival date, display weeks difference, and so on...
Hope it helps
|
|
|
|
|
can you elaborate?
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
What I meant was, if you need to get the date difference between arrival and departure dates in terms of X years, Y months, Z weeks, and Q days then you need to write your own function.
Your function should first calculate the year difference between the arrival and departure date.
Then you need to either:
- add the years to departure date; or
- deduct the years from arrival date.
After this, you can calculate the remaining month difference between the arrival and departure date by using the modified date and so on.
Example
Departure date = 01/01/2005
Arrival date = 03/02/2006 05/03/2006
Year difference = DateDiff('y', '01/01/2005', '05/03/2006') = 1
Modified departure date = DateAdd('y', 1, '01/01/2005') = 01/01/2006
Arrival date = 03/02/2006
Months difference = DateDiff('m', '01/01/2006', '05/03/2006') = 2
...
and so on till you get the difference in days.
Got it?
Edbert
|
|
|
|
|
Edbert, How did you get the date of 05/03/2006 for a departure date...
Regards
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
Whoops.. sorry . The example arrival date was 03/02/2006 but I changed it to 05/03/2006 because I feel it's a better date example (has 1 year and 2 months difference to the departure date).
I've modified the post. You can check the modified one now.
I hope that explains it,
Edbert
|
|
|
|
|
Thanks, Thought you might like a copy of the finised product...
Dim days As Date
Dim weeks As Date
Dim months As Date
Dim years As Date
Dim numofyears As Integer
Dim numofmonths As Integer
Dim numofdays As Integer
Dim numofweeks As Integer
Dim y As Long = DateDiff(DateInterval.Year, Convert.ToDateTime(dtArrival.Text), Convert.ToDateTime(dtDeparture.Text))
years = DateAdd(DateInterval.Year, y, Convert.ToDateTime(dtArrival.Text))
numofyears = DatePart(DateInterval.Year, years) - DatePart(DateInterval.Year, Convert.ToDateTime(dtArrival.Text))
lblYears.Text = numofyears.ToString
Dim m As Long = DateDiff(DateInterval.Month, Convert.ToDateTime(dtArrival.Text), Convert.ToDateTime(dtDeparture.Text))
months = DateAdd(DateInterval.Month, m, Convert.ToDateTime(dtArrival.Text))
numofmonths = DatePart(DateInterval.Month, months) - DatePart(DateInterval.Month, Convert.ToDateTime(dtArrival.Text))
lblMonths.Text = numofmonths.ToString
Dim d As Long = DateDiff(DateInterval.Day, Convert.ToDateTime(dtArrival.Text), Convert.ToDateTime(dtDeparture.Text))
days = DateAdd(DateInterval.Day, d, Convert.ToDateTime(dtArrival.Text))
numofdays = DatePart(DateInterval.Day, days) - DatePart(DateInterval.Day, Convert.ToDateTime(dtArrival.Text))
lblDays.Text = numofdays
Regards
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
Well....it's not exactly what I had in mind.
But if that works for you then it's fine (does it work? Somehow I feel the logic isn't quite right).
My code (untested):
Dim years As Integer
Dim months as Integer
Dim days as Integer
Dim arrivalDate As Date
Dim departureDate As Date
<code>'Use variables instead of doing Convert repeatedly</code>
arrivalDate = Convert.ToDateTime(dtArrival.Text)
departureDate = Convert.ToDateTime(dtDeparture.Text)
years = DateDiff(DateInterval.Year, arrivalDate, departureDate))
lblYears.Text = years.ToString
<code>'This adds years to departure so we can get only the difference in months</code>
departureDate = DateAdd(DateInterval.Year, years, departureDate)
months = DateDiff(DateInterval.Month, arrivalDate, departureDate)
lblMonths.Text = months.ToString
<code>'This adds months to departure so we can get only the difference in days</code>
departureDate = DateAdd(DateInterval.Month, months, departureDate)
days = DateDiff(DateInterval.Day, arrivalDate, departureDate)
lblDays.Text = days
...
|
|
|
|
|
Thanks for the tips........;)
"The things that will destroy us are: politics without principle; pleasure without conscience; wealth without work; knowledge without character; business without morality; science without humanity; and worship without sacrifice."
-Mahatma Gandhi (1869-1948)
|
|
|
|
|
Hi
i have a problem with the crystal reports, in vb.net. i m not using c# as scripting language. i m using vbscript.
at the time of passing the parameter from the form(textboxes), to the crystal reprt. i m not able to do so.
And one intermediate Dialogue box is getting popped up, on which i dont have an control.
Give some preicse information about this information about it, as i have to
DEADLINE to complete this task..
Thanks
Samani Umang N.
22#Golden Jubilee
Mithpur-361345
|
|
|
|
|
|
I am new to the Visual Studio .NET world but would like to control some small ovens with this software. I am planning on using devices from Measurement Computing for my interface out to the world. Also plan on using Softwire for some of the programming. I would like to use as much code that has been already been developed. I am very interested in finding where I can get an already programmed item for PID control. Does anybody know where I can get this code?? Also where is a good place for finding free code for industrial controls???
Thanks for any help!!
|
|
|
|
|
I have created a VB webform to manage my router and wireless clients. I don't now how to submit a username and password to the login page of the router and clients (Linksys and senao web browser config). I must always do this manually. How might I code a username and password routine? Any help is appreciated. Go easy on me, I am a pre-beginner.
Thanks
Ryan
|
|
|
|
|
i want to ask u all that what is better to have more then one object of connection in a application or only one object for every transaction.
and next is what is better to close connection with database at the closing of application or when work completes with db, means i want to ask that should i open and close connection many times or better to open once and close it at the end of appli
|
|
|
|
|
|
It is generally accepted that you get the best performance when:
1) Opening a connection as late as possible
2) Closing that connection as early as possible.
in pseudo code.
Define connection
Setup queries/state etc
Open Connection
Use Connection
Close Connection
|
|
|
|
|
how to insert data in data grid in vb.net
|
|
|
|
|
Try this...
dim conn = new sqlconnection(connstring)
dim cmd = new sqlcommand
cmd.connection = conn
cmd.commandtype = command.text
cmd.commandtext = "SELECT ...."
dim da = new sqldataadapter
da.selectcommand = cmd
dim ds = new dataset
da.fill(ds, "tblname")
dg.datasource = ds.tables(0)
Feng Screwed, the art of moving to a new place because it would just be too much to clean the old place
|
|
|
|
|
I am making an FTP application that needs to have support for an UploadDir function. And I can't seem to make it work correctly. Does anyone know how to do this, or where I can get some open source FTP Class that supports uploads of Directories? I'm begging you, please help.
~Kc
|
|
|
|
|
It's no different than uploading files one at a time, because, that what you actually have to do. If your going to upload an entire directory, you have to keep track of the list of files you have to upload, the files that you've sent, and if you want, you have to track the directory tree you must create on the FTP server. If you use a simple, recursive, tree-walking algorithm on your source directory, this is easy to do.
Each iteration of the alorgithm will simply upload any files it in the current directory, then iterate through the directories in the source directory, create the folder on the FTP server, then calls itself with the new path to the new souce directory and the destination path on the FTP server.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you very much Dave! I actually got this working today. The recursion was throwing me off, but I found the problem by stepping into the code slowly with the debugger. Thanks again, your answer is 100% correct.
~Kc
|
|
|
|
|
i currently has an backup of a database (called ybam) in a sql script (called c:\20053131028.sql)...
now i want to create a button where an user can restore the ybam database by click on restore button on the vb .net form....
what should i code in the button.... thank you very much....
|
|
|
|