Help needed in visual basic 2008

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 7:56 am

I need to create an application that compares two text files (plain text). It has to compare these text files on file system level (at least 3 attributes) and also compare the contents of these files. And then the program points out the differences.

since im a total beginner i could use some help. It would be very good, if anybody could tell me which functions to use to compare text files? any info that would help me writing that application, is very appreciated..
Knobot
Gerbil In Training
 
Posts: 5
Joined: Tue Nov 04, 2008 7:55 am

Re: Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 8:18 am

Sounds like a homework assignment and requests for others to do your homework don't go over well here. If you can make some effort yourself, show some code that you have tried to get working, talk about functions that you have looked at but don't quite seem to do what you want and where they don't quite match up, then people here tend to be a lot more friendly and more likely to post hints / suggestions of what to look at next.

I'm a C guy, never done Visual Basic so I can't help either way. :)
notfred
Grand Gerbil Poohbah
 
Posts: 3490
Joined: Tue Aug 10, 2004 9:10 am
Location: Ottawa, Canada

Re: Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 8:34 am

yes, this is a homework.. but im not expecting anybody to do it for me.. all i need is some info about the functions that can be used to compare text files.. if somebody could give me some hints then i could try and if im still in trouble then i could post the code and maybe then some of u could tell what am i doing wrong..
Knobot
Gerbil In Training
 
Posts: 5
Joined: Tue Nov 04, 2008 7:55 am

Re: Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 8:58 am

Have you tried the help file? Or looking at MSDN online? Seriously these lots of built in string manipulation functions. So go out and read about them toy with them. Learn how they work.

Not to mention any basic learn to program book (which I am assuming you have one for this class) will cover working with strings.
"I used to think the brain was the most amazing organ in the entire body. Then I realized who was telling me this."
If ignorance were painful, half the posters here would be on morphine drips.
zgirl
Grand Gerbil Poohbah
 
Posts: 3892
Joined: Tue Jan 01, 2002 6:00 pm
Location: The dark side of the moon

Re: Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 9:03 am

There are a bunch of old functions in VB that date back to the early days of Basic (FileAttr etc) but I expect and would hope that you're supposed to be learning and using the .NET class libraries, and not those ancient creaking functions. So you'll want to be working with the System.IO namespace. This article is for VS 2005 but should work without any changes, and should help you with some of the basics. For looking at the contents of the files, you'll need to know about strings.

MSDN is a great resource. Learn to use it. You can use the search feature (though sometimes it works better to use use google with site:microsoft.com )
UberGerbil
Gerbil Khan
 
Posts: 9836
Joined: Thu Jun 19, 2003 2:11 pm

Re: Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 11:34 am

Your need to look at System.IO, StreamReader and String.Compare
SN95G5v3/A64 3500+ 2.2ghz@1.2v 800mhz@0.8v/1gb Geil UltraX/Seagate 250gb/Seagate 320gb/Liteon DVD/XFX 6600GT/2x2005FPW
Rainbows lie in corded knots
While thunder wakes the sleeping crocs.
dragmor
Grand Gerbil Poohbah
 
Posts: 3561
Joined: Mon Sep 23, 2002 6:24 pm
Location: Oz

Re: Help needed in visual basic 2008

Postposted on Tue Nov 04, 2008 11:58 am

Is there really nothing in your textbook or your lecture notes?
Image
Think for yourself, schmuck!
i5-2500K@4.3|Asus P8P67-LE|8GB DDR3-1600|Powercolor R7850 2G|1.5TB 7200.11|1988 Model M|Saitek X-45 & P880|Logitech MX 518|Dell 2209WA|Sennheiser PC151|Asus Xonar DX
bthylafh
Minister of Gerbil Affairs
 
Posts: 2813
Joined: Mon Dec 29, 2003 10:55 pm
Location: Southwest Missouri, USA

Re: Help needed in visual basic 2008

Postposted on Wed Nov 12, 2008 2:23 pm

thanks for all the replies.. first of all i have to say that we dont have a textbook.. this is more like a self study class. they showed us the basics (how to use vb, create classes and interfaces etc) and all the other things we have to learn our own.

i have tried different functions and i was able to get file directory, name and length.. but i have problems with getting the number of characters in a txt file. I was able to open the file and read it..

Dim path As String = "..."
Dim sr As StreamReader = File.OpenText(path)

Do While sr.Peek() >= 0
output = sr.ReadLine()
Loop

sr.Close()

in that way i got all the text in the file.. but i dont need that text in the output.. i would like to get the number of characters instead.. is it possible with the streamreader function or is there any other function for that?
Knobot
Gerbil In Training
 
Posts: 5
Joined: Tue Nov 04, 2008 7:55 am

Re: Help needed in visual basic 2008

Postposted on Wed Nov 12, 2008 3:37 pm

To get the length of characters, the LEN function accepts a string as an argument. So take your file, read it in as you have to a variable, and pass that variable as the argument.

Code: Select all
Dim strLength = LEN(output)


http://www.example-code.com/vb/lenString.asp

That should get the number of characters for assuming your loop is reading properly.

edit: Changed the link for VB, not VBScript.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
 
Posts: 11762
Joined: Mon May 26, 2003 4:55 am
Location: Pittsburgh PA

Re: Help needed in visual basic 2008

Postposted on Wed Nov 12, 2008 8:42 pm

pete_roth wrote:That should get the number of characters for assuming your loop is reading properly.
Well, no, as written above, that will get the length of the last read line in the file -- which is only going to give you the full length of the file in the pathological case where there's no CR/LF chars -- ie, it's just one long line.

Of course you could keep a running accumulation as you loop through the lines of the file, but that's unnecessary if you're just trying to grab the length. Both the filestream class and the FileInfo class have .Length properties. Note also that the StreamReader class has a ReadtoEnd method that will suck in the entire file without requiring a loop -- but again, that's only necessary if you're planning to do something with the contents of the file. If you just want to know how big it is, the FileInfo Length property will give that to you.

(I am ignoring a technical issue here wrt bytes vs characters -- without knowing the encoding of the text file, it's not really possible to know how many characters there are in the file. If it's ASCII/ANSI, then every byte is a character; if it's unicode, then every two bytes define a character (approximately); but it could be one of several other encodings, including compressed ones. For the most part, you shouldn't have to worry about that.)
UberGerbil
Gerbil Khan
 
Posts: 9836
Joined: Thu Jun 19, 2003 2:11 pm

Re: Help needed in visual basic 2008

Postposted on Wed Nov 12, 2008 8:47 pm

He made it seem like he was taking every line and concatenating it into one variable in which case LEN(variable) will work.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
 
Posts: 11762
Joined: Mon May 26, 2003 4:55 am
Location: Pittsburgh PA

Re: Help needed in visual basic 2008

Postposted on Wed Nov 12, 2008 9:28 pm

pete_roth wrote:He made it seem like he was taking every line and concatenating it into one variable in which case LEN(variable) will work.
Yeah, it would. I was just reading the (possibly incomplete) posted code, which didn't do that. Anyway, I was more interested in pointing out a couple of other classes and doc pages that might've been overlooked.
UberGerbil
Gerbil Khan
 
Posts: 9836
Joined: Thu Jun 19, 2003 2:11 pm

Re: Help needed in visual basic 2008

Postposted on Sat Nov 15, 2008 10:17 am

yea..the code i used before read only the last line in the file, but since i only had one line in the file, i thought it worked.. so now im using ReadToEnd instead and it seems to be working fine..and LEN function seems to work fine as well.. i have a little problem getting the file name using this function: http://msdn.microsoft.com/en-us/library ... ename.aspx .. i'll get the error: GetFileName is not a member of string.

and i also have another problem but it is quite hard to explain without u seeing the full code. atm the program works if file path/name is known.. but i would like to make it so user can enter file address/name himself. i have tried different methods but i still havent got it to work. if anyone here thinks he could take a look at it then pm me and i could send the whole project.
Knobot
Gerbil In Training
 
Posts: 5
Joined: Tue Nov 04, 2008 7:55 am

Re: Help needed in visual basic 2008

Postposted on Sat Nov 15, 2008 12:10 pm

Not sure what you're trying to do with the filename but if you wanted to use it as a string you need only append ".toString()" to the end of the getFileName call.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
 
Posts: 11762
Joined: Mon May 26, 2003 4:55 am
Location: Pittsburgh PA

Re: Help needed in visual basic 2008

Postposted on Wed Nov 19, 2008 10:35 am

i just wanted to thank everybody who replied and offered help. I finally got it working the way i wanted:) i couldnt have done it without your help.
thanks!
Knobot
Gerbil In Training
 
Posts: 5
Joined: Tue Nov 04, 2008 7:55 am


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 2 guests