|
I've got some code to read from a text file (contents will be pasted at the bottom of this message. I've got it reading the file fine, but some of the spacing between say like name and id isn't the same, and I'm lost finding a solution to read all fields. Any tips or suggestions? I know where the code fails is at ar = str.split(cchar(" ")), but every other file I've had to read was separated by a "|" or just had one single space between everything. A program doesn't care if the file looks good or not . Is there a way you could read a "column" per say?
Thanks
Here's the code:
Public Sub LoadStudents(ByVal strFile As String)
Dim fs As New FileStream(strFile, FileMode.Open)
Dim sr As StreamReader
Try
sr = New StreamReader(fs)
Dim str As String
Dim ar As String()
Do While sr.Peek <> -1
str = sr.ReadLine
If str.Trim.Length <> 0 Then
ar = str.Split(CChar(" "))
stud = New Student
With stud
.Number = CType(ar(0), Integer)
.Last = CType(ar(1), String).Substring(0, .Last.Length - 1)
.First = CType(ar(2), String)
.MidI = CType(ar(3), String)
.ID = CType(ar(4), String)
.College = CType(ar(5), String)
.Classification = CType(ar(6), String)
.Email = CType(ar(7), String)
.Major = CType(ar(8), String)
.Paid = CType(ar(9), String)
.Enrolled = CType(ar(10), String)
End With
End If
Loop
Catch ex As Exception
Exception(ex)
Finally
fs.Close()
sr.Close()
End Try
End Sub
Here's the text file:
1 ANSARI, EHSAN B 111-11-111 BT SR CSCI P Enrolled
2 CRAWFORD, BRIAN KEITH 111-11-111 BT SR CSCI P Enrolled
3 ELLIS, RICHARD M 111-11-111 BT SR CSCI P Enrolled
4 GARDNER, JAMES ROBY 111-11-111 BT SR CSCI P Enrolled
5 GNAU, DANIEL C 111-11-111 BT SR CSCI A Enrolled
7 GOULDER, JEFFREY SCOTT 111-11-111 BT SR CSCI P Enrolled
8 LAWSON, BRANDI NICOLE 111-11-111 BT SR CSCI P Enrolled
9 MONROE, JENNIFER M 111-11-111 BT SR CSCI P Enrolled
10 MOORE, MELISSA ANN 111-11-111 BT SR CSCI P Enrolled
11 OVERHOLT, JAMES PATRIC 111-11-111 BT SR CSCI P Enrolled
12 PARKER, BRIAN DOUGLAS 111-11-111 BT SR CSCI P Enrolled
|
|
|
|
|
I realized this line doesn't work, it is fixed:
.Last = CType(ar(1), String).Substring(0, .Last.Length - 1)
I used a variable to hold the array value and did substring from there.
|
|
|
|
|
|
Hello all,
I was very happy that my last problem was solved quickly. I have yet another problem though.
I'm working with quite a bit of For statements, and to be honest, I love them. Now, I need a feature to get VB.NET to ignore the rest of the code in the For/Next statement and do it all again (well, until the conditions are met).
For example, it reads the lines of a rich text box. If the length of the string is a certain length, then it does one thing and goes on to the next line. If it's another length it does something else and then goes to the next line.
Seems like I could do this with just an if statement, right? Well, there are too many things that it's checking for, so it would get really messy really fast.
I also could do this with a variable. Create a new variable at the beginning of the script, just say, called "Doneyet" (boolean). If the conditions are right and doneyet = false, then it does the action and sets doneyet to true. Then, any remaining code will see that doneyet = true and won't execute, and thus VB.NET will loop to the next "line" or whatnot.
Is there a better, cleaner way to do that?
|
|
|
|
|
|
i have a problem geting the hives, in the treeview and the keys the listbox.
i want to a replica of regedit in other words...(100% same fuctionalities). can any one help with a code sample in vb.net only not vb6 others because i started with .net only. :P
i want to work hard...in this field!
serious in programming!
|
|
|
|
|
Hi guys I have lost my source code and only have the exe. file is there some way to recover the source code (vb.net) from the .exe file????
|
|
|
|
|
You can recover a variant of the source. The variable names will not be the same. Look into Reflector[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
nobody can do convert exe to source file.
AMR-CIS
|
|
|
|
|
How would I write a program and get a random number
|
|
|
|
|
Just Google "Random Numbers" and "VB.NET", you'll get tons of hits.
No random number is truly "random", and random number generation algorithms can vary from extremely simple to extremely complex, depending on how "random" you really need your numbers to be. I'm sure you'll find something that suits your needs.
|
|
|
|
|
Buy this book with Samples: "Numerical Recipes in C"
Its a coding bible.
Its available on line.
Scooter
|
|
|
|
|
Dim myRNG As New Random()
Dim newNumber As Integer = myRNG.Next(lowerBound, upperBound)
But I vaguely remember telling you this already.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Tooltip on a treenode is overlaying Treeview enties behind tooltip. The tooltip leaves behind a white shadow that overlays only the Treeview data behind it. It looks like the tooltip erases the pixels behind were it came up but only in the treeview. I searched MSDN and still am at a loss. Any help is appreciated. I use the refresh function to fix the treeview but I was curious what what causing it.
Andrew
Princeton, NJ
-- modified at 14:53 Friday 14th October, 2005
|
|
|
|
|
Is that any function can tokenize a string just like what C++ can do.
Thanks,
David
|
|
|
|
|
There is the String.Split() function that will split a string into an array based upon a separator character.
|
|
|
|
|
You have to remember that VB.NET and C# both use the .NET Framework - it is the .NET framework that provides this sort of functionality. Therefore, when it comes to the classes and methods that are available if C# can do something then so can VB.NET.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Does anyone have a script that can prompt you for a user name and password to join a computer name to a domain? Thanks
|
|
|
|
|
Did you lookup the documentation on the JoinDomainOrWorkgroup[^] method? It can take optional parameters for username and password.
The sample I pointed you at already demonstrated this. Or are you asking how you would prompt for the username and password?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 10:32 Friday 14th October, 2005
|
|
|
|
|
Yes,
That script was good, but I wanted to allow for any IT member with the appropriate permissions to add a computer name to the domain. So a username and password prompt would be great!
|
|
|
|
|
Either code your script to parse command line arguments[^] or use an InputBox[^]. Be warned(!) Anything you type for a command line argument or into an InputBox appears as clear text! There is no PasswordInputBox for VBScript without using a 3rd party component that must be installed.
Another method would be to have the script create it's own web page and accept input using HTML controls, which DOES have a password input box.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Where can I find the control where I can input an IP address like the ones that can be found when you are configuring network connection in windows? I really need to know, thanx
|
|
|
|
|
|
It doesn't have to be in .NET because I'm using VB6 only.
Based on the link that you replied to me, I got the idea how the creator create the IP Address control box. Thanx
|
|
|
|
|
hi guys !!
need help from u guys..
my company have a big Local area network..
i m developing an application which ping all the IP's and cahck that they are working or not .
i also want to retrive the MAC address of those IP's. is there ant way to retrive the MAC address programatically by specifying the IP address
abhinav
|
|
|
|