Okay... So I've actually made it to the final project in my Intermediate Visual Basic class. Yet, I'm still feeling stupid - like I've never attempted any project at all. I think my main confusion in this project is that we're using two seperate sequential files. I CAN and HAVE written programs involving OOP, and sequential files, but it seems the harder I am trying to incorporate the two, the more confused I get. Everyone should be relieved that I've already scheduled a two-term break from programming classes to get a better handle on this, however.... I have to pass this class in order to stay with my program. (Please don't think that I have given up on this pursuit - I just need to get a full understanding arrays, etc. before I feel I can proceed further. I have coded the following sub procedure....

Sub DisplaySavings()
        Dim data() As Transaction
        Dim sr As StreamReader = File.OpenText("SAVINGS.TXT")

        data = sr.ReadLine.Split(","c)

        Dim fmtStr As String = "{0, -18} {1, -16} {2, -12} {3, -12}"

        transDate = data(0)
        transType = data(1)
        depAmt = data(2)
        wdAmt = data(3)

        Do While sr.Peek <> -1
            lstTransactions.Items.Add(String.Format(fmtStr, data(0), data(1), data(2), data(3)))
        Loop
    End Sub

... and although this is only a portion of the code I'm struggling with, it's the point I'm stuck at.

I'm getting an error at

data = sr.ReadLine.Split(","c)

I don't know if anyone can help me without complete rubric and assignment instructions, but I AM trying to complete this with minimal help.... Any suggestions? Or do I need to provide full assignment requirements?

* I'm at a complete loss here. The more I try to code this, the more confused I'm getting. * I have attempted this project using three different methods - none of which have gotten me anywhere near understanding it. I have various coding methods halfway completed... Can anyone help? =(

Recommended Answers

All 5 Replies

there pops 3 questions up in my head...
what is "transaction" (struct?, your own class? or what?)
secod question is ... what is the exact error you get?
and last question is ... you only want to read the first line of the text file? (just to be sure)

Dim data() As String
        Dim sr As StreamReader = File.OpenText("SAVINGS.TXT")

        data = sr.ReadLine.Split(","c)

would work since i assume there are only strings in the txt file :p

What a day for DaniWeb to go read-only... Right in the middle of working on my project. LOL

Anyway... actually, I did do this wrong - but because, yes, I need to read more than one line. I have mailed my instructor repeatedly for help on other parts of this project, too, but his directions never seem to help me much. =P

The requirements on this assignment are to use two Classes; Account and Transactions. We are to create a banking program which will allow the user to record and display transactions, as well as keep a running balance. The transactions are to be stored in two seperate sequential files - CHECKING.TXT and SAVINGS.TXT.

I can't get very far debugging right now with what I have, because I'm still struggling with how to draw the sequential files into arrays correctly. Arrays are definitely the area where my confusion begins. I DO understand how they work, but coding them is another story.

I am just going to attach what I have so far here. If anyone has time to look at it and has ANY suggestions on ANY portion of my coding that will help me get it going, it would be greatly appreciated.

You do realize that your name is included in that file name and it is very likely you could be found googling your name? I hope this isn't against your class' policy.

Anyway don't worry about appending a file and seeking it etc etc, that is too much of a headache with no real benefit. Load the transactions and accounts in to memory and write them all out when you want to save.

Here is a modified version of your program that uses XML serialization:

Public Class Account

    Private m_name As String
	Private m_balance As Decimal
	Private m_txn As New List(Of Transaction)

    Dim transArray() As String


    Public Property AccountName() As String
        Get
            Return m_name
        End Get
        Set(ByVal value As String)
            m_name = value
        End Set
    End Property

    Public Property Balance() As Double
		Get
			Return m_balance
		End Get
        Set(ByVal value As Double)
            m_balance = value
        End Set
    End Property


	Public Property Transactions() As List(Of Transaction)
		Get
			Return m_txn
		End Get
		Set(ByVal value As List(Of Transaction))
			If (value Is Nothing) Then
				m_txn = value
			End If
		End Set
	End Property

	Public Sub SaveToFile(ByVal fileName As String)
		If (System.IO.File.Exists(fileName)) Then
			System.IO.File.Delete(fileName)
		End If
		Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(Account))
		Dim fs As New System.IO.FileStream(fileName, IO.FileMode.CreateNew)
		ser.Serialize(fs, Me)
		fs.Flush()
		fs.Close()
		fs.Dispose()
	End Sub

	Public Shared Function LoadFromFile(ByVal fileName As String) As Account
		Dim acct As Account

		Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(Account))
		Dim fs As New System.IO.FileStream(fileName, IO.FileMode.Open)
		acct = CType(ser.Deserialize(fs), Account)
		fs.Close()
		fs.Dispose()
		Return acct
	End Function

End Class

Public Class Checking
    Inherits Account
End Class

Public Class Savings
    Inherits Account
End Class

Calling it:

Public Class frmTest

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim acct As New Account()
		acct.Balance = 50
		acct.AccountName = "abc123"
		Dim txn As New Transaction()
		txn.Amt = 50
		txn.Name = "50"
		acct.Transactions.Add(txn)
		acct.SaveToFile("C:\file.xml")
	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Dim acct As Account = Account.LoadFromFile("C:\file.xml")
		System.Diagnostics.Debugger.Break()
	End Sub
End Class

I do realize that, but no, I don't think it's against my class policy, as I'm not looking for someone to write my code, just comments to help me understand and code it myself. =)

Your example confuses me a little, in that we haven't studied xml serialization yet.

I originally (I've attempted to code this 4 times now from scratch) tried to use "New List(of Transaction)" but I guess I don't quite understand this well enough. I believe I have that statement in the wrong place, though, now that I've seen this example. I've never successfully used it in my programs before, so this helps immensely. =P

Thank you for your input, though. I'm going to do some more research on this, and see what I can fix using the List function. =)

Sounds good :)

Please mark this thread as solved if you have received an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.