Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27569

VS 2013 Saving Structures Within Binary Files

$
0
0
Hey guys. I'm currently making a program as a self study guide for my coarses in college. Basically it allows me to add potential multiple choice test questions for any coarse I choose and save it to a file in binary format. And it allows me to test myself by randomly displaying the questions after loading it from file. Well....I'm stuck on figuring out how I can save it.

Basically how I have my structures is like this. I have a number of subjects, which are my coarses in college. Each subject has chapters, which is another structure. And each chapter has questions to that chapter, with possible random answers related to the right answer but will be the wrong answer:

vb.net Code:
  1. Private Structure Question_Type
  2.         <VBFixedString(256)> Dim Answer As String
  3.         <VBFixedString(256)> Dim Rnd_Answer() As String
  4.         Public Sub Initialize()
  5.             ReDim Rnd_Answer(2)
  6.         End Sub
  7.     End Structure
  8.  
  9.     Private Structure Chapter_Type
  10.         Dim Question() As Question_Type
  11.         Dim Number_of_Questions As Integer
  12.         Public Sub Initialize()
  13.             ReDim Question(Number_of_Questions)
  14.         End Sub
  15.     End Structure
  16.  
  17.     Private Structure Subject_Type
  18.         Dim Chapter() As Chapter_Type
  19.         Dim Number_Of_Chapters As Integer
  20.         Public Sub Initialize()
  21.             ReDim Chapter(Number_Of_Chapters)
  22.         End Sub
  23.     End Structure
  24.  
  25.     Private Subject(2) As Subject_Type

And if I were to save it as a binary file, I haven't the slightest clue on how I'm gonna do it :eek2:

vb.net Code:
  1. Try
  2.             Binary_Writer = New BinaryWriter(New FileStream(Application.StartupPath & "\Test.bin", FileMode.Create))
  3.         Catch err As IOException
  4.             MessageBox.Show(err.Message + "\n Cannot create file.", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
  5.         End Try
  6.  
  7.         'Subject > Chapter > Questions
  8.  
  9.         'Don't know how I am gonna save this
  10.         Binary_Writer.Write(???)

Without having to save multiple files cause I only wanna work with one file that holds everything, I need to be able to save the questions with the random wrong answers with the associated chapters and subjects, and be able to load it from whatever subject and chapter of my choosing, and get the random questions to test myself associated with that chapter and subject. I know its 2 in the morning but I'm stumpt. Maybe I need some sleep to think about it but if anyone has any bright ideas, I would appreciate it. Thanks in advance. :bigyello:

Viewing all articles
Browse latest Browse all 27569

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>