• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

VB.NET Help. For the fourth time.

Status
Not open for further replies.

Soul4ger

Member
I have a more difficult project this time. We're supposed to read input from a data file, then check to see if each line is a palindrome. We have to use a loop to read each line, and do various things to each line of data, print each revision, then read the next line, etc.

Where I'm running into a problem:

First, I don't know how to do a loop that detects the end of the file. We open a file by means of:

FileOpen(1, "File Name", OpenMode.Input)

Not the io.streamreader way.

Do when I do Do While (restriction), I can't just put in (Not EOF()), can I? It gives me an error when I do that.

Any help would be most appreciated. I'm sure I'll have more questions as I go, too.
 

Soul4ger

Member
Okay, I figured that out, actually. I have two really quick questions. If someone would help, I would really appreciate it.

How do you read a string from the right? Like I said, the program is checking to see if a line in a file is a palindrome. So I'm going to read it from the right, then see if it's equal to the one on the left, and if it is it'll display that it's a palindrome. My professor told us to say:

strName.Microsoft.VisualBasic.Right(number)

But that's not working for me.

Last question, anyone know how to just skip a line in a listbox?
 
Rather than test for EOF, test to see if the line you just read is Null/Nothing. If you can't use StreamReader, use FileInfo_OpenRead and get the bytestream. If the file is ASCII or UTF8, each byte will be a character, although you should use a character encoding class to make sure.

Here's a sample in C# (fuck VB.NET, should be an easy conversion)

FileInfo fInfo = new FileInfo(path);
using (FileStream fs = fInfo_OpenRead())
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);

while (fs.ReadByte) != -1) // -1 is end of stream
{
// do yer processing here
}
}

Within the FileStream, you can use the Seek method to move the file cursor around. http://msdn.microsoft.com/library/d...tml/frlrfsystemiofilestreamclassseektopic.asp

Enjoy!
 

Soul4ger

Member
OKAY, I posted on that forum. No one helped. My question is simple. HOW DO YOU READ A STRING FROM THE RIGHT? I'm running short on time here, so any help is appreciated.
 

Azih

Member
Dude I personally woud just set up an inner loop for the sentence that compares the first character to the last character, the second character to the second-last character and so on.

Possible implementation: keep track of the characters you're comparing (call it leftCharPos, rightCharPos or whatever), keep comparing characters and increment leftCharPos one and decrement rightCharPos one until either the characters don't match (not palindrome) or leftCharPos becomes greater than rightCharPos (is palindrome). This loop condition takes care of one length, odd length, and even length sentences. Need special case to hande an empty line though.
 

beerbelly

Banned
reading the string from the right?

example for "Ryerson", you want to read it as "nosreyR" ?

You can use the Strreverse function which reverses your strings and then read it that way :D.

But Ecrofirt's way can also be used.
 

Soul4ger

Member
Digging up a corpse.

How do you send an array to a sub? I have a call that looks like this:

CalcGross(dblGrossNet(MAX_EMPLOYEES, 2))
' MAX_EMPLOYEES is a constant

Then a sub line that says

Sub CalcGross(ByVal dblGrossNet())

And it's giving me shit.
 

Ecrofirt

Member
if you're sending it the array, you wouldn't send the specific element of the array. That's what it looks like you're doing.

CalcGross(dblGrossNet(MAX_EMPLOYEES, 2))

You're sending CalcGross the value of dblGrossNet the specific spot.

if you want to send the whole array, try this:

Code:
CalcGross(dblGrossNet())

and if CalcGross only needs the specific element of the array, send just the specific value. Something like this

Code:
theValue=dblGrossNet(MAX_EMPLOYEES,2)
CalcGross(theValue)
 

Soul4ger

Member
Argh. I want to kill myself. When I don't type anything in:

CalcGross(dblGrossNet())

I get the error:

"Number of indices is less than the number of dimensions of the indexed array."

Nyargh.
 

Ecrofirt

Member
if I didn't have so much to do for school tonight, I'd gladly try and offer more help.

For now, try asking at that extemevbtalk site. I'll bump your thread if you link to it.
 

Ecrofirt

Member
I thought you did when using VB.

Of course, that was VB6, and a year and a half ago, so my memory is a bit sketchy
 

CaptainABAB

Member
1. If your prof is recommending FileOpen() over the io.streamreader method, then he is too used to the old way VB did things and needs to learn .NET.

The old FileOpen approach is put in there for compatability purposes only and is so much slower then the io classes.


2. To read a string from the right, you have several options besides the easy approach you took. I would still use your method (don't reinvent the wheel), but just in case you have to use a language w/o such a feature, try these ...

- load the string into a byte array and access it backwards.... (mystring.length - 1) to 0

- use Right(Left(myString, 1), n) where n is increasing from 1 to myString.length

- use myString.substring(n, 1) where n is decreasing from myString.length
 

CaptainABAB

Member
Ecrofirt said:
I thought you did when using VB.

Of course, that was VB6, and a year and a half ago, so my memory is a bit sketchy

You need to append the () at the end of the array when declaring it (local or as a parameter) OR when you need to access the individual elements. You don't need to use it when you are referring to the array object itself.

So when you want the size of the array, you do

myArray.length() not myArray().length()

same thing when passing it into a funciton or setting the object to another variable.

myArray2 = myArray1

to ONLY set individual elements, you would do

myArray2(5) = myArray1(9)
 
Status
Not open for further replies.
Top Bottom