none
Visual basic equivalences

    Question

  • I am in the process of converting my VB 6.0 programs to VS 2010 (vb.net). I have been reading and reading  how to books and I'm getting so frustrated in this process that I'm thinking that vb.net is not what I want to be using.  Nevertheless, I'm still trying and I think if I could just get a few equivalent solutions completed, I will understand what is going on.  Many of my programs read sequential files and use the information in data bases for reference.  I use Access tables frequently in my 6.0 code and have become fairly competent using the tables.  I have been using the book, MS Visual Basic 2010, Step by Step by Michael Halvorson as my guide and I have read it from cover to cover.  But I'm still confused   For example, in my 6.0 code I use Public Functions and Subs to do much of my work, but in VS 2010 I keep getting that my statement is not valid in a Namespace.

    Another example, VS 2010 removed the use of the TYPE statement and DIM SS as string * 3.  that is okay.  But if I want to read/write a fixed length record with using a single variable as defined by the TYPE variable, how can it be done.  Here is an example of what I did in 6.0:

    Type AllFiles
        FileNo As Integer           ' 001 Number of file or Number of files in this file
        FileDesc As String * 42     ' 003 full folder name
        filename As String * 15     ' 045 name of file (prefix)
        FileExt As String * 3       ' 060 name extension (suffix) 
        FileFree As String * 2      ' 063 Free space
    End Type                        ' 065

    Public FilesRec As AllFiles

    open filename for random as #1 len=len(AllFiles)

      get #1, rec, FilesRec

       or

      put #1, rec, FilesRec

    close #1

    This used to be so easy, but now it appears to be so complicated that I get lost.  I would love to see a VS 2010 equivalence code for the above code.

    Then there is the accessing of data in the access tables.  In my reference book, there are examples of how to store a complete table onto a grid.  My problems are primarily using the data as opposed to listing it in a grid.   in VB6 I could open the table and then reference the fields of the table by their variable names like !Record or !FileNo. I didn't see any references to this process at all and it appears that a person needs to know a million different properties before he can do a simple read and write of an Access table.  This is obviously an exaggeration and I admit I'm still learning how to code in VS, but VB 6.0 code was at least logical in its operations and you didn't have to know hidden secrets.

    I want to learn this and maybe even convert all my 6.0 programs to VS, but I can't understand why it has been made so difficult.  I guess I was hoping that when there wasn't a straight conversion from 6.0 to VS there would be a function or subroutine you can call to make it compatible.  If that process exists, that would be great, but I have not found one as yet.

    I guess I sound like a ship without a rudder, but I'm hoping other people have gone through this process and can offer some assistance.

    Thanks,

    BigTeePhil

      

    <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{9024F5C1-E130-4819-A3CD-ECE8324E4FB7}" /></object>
    Friday, August 02, 2013 10:56 PM

Answers

  • Hello,

    Sorry to hear this. Here is my take on complicated, if you have a .NET developer with only a VB6 background they are use to simple (I used simple thru out in the realm of how VB6 made things simple) for common task of developing solutions and rightfully so as this was one of the reasons VB6 was extremely successful but on the other hand simple meant that to venture out for task outside of simple meant complex code to get around simple. Now if a developer starting with .NET came from say Delphi or C they expect to not have simple. What is (and this is my opinion) great about not being constrained by simple is you are very free to flex your wings and do almost whatever you need. As you become proficient with the language you should see patterns and with these patterns and understanding of the Framework will be able to write re-usable code in the form of classes and language extensions that can be placed into utility projects which compile to a DLL that can be used in other projects or these projects can simply be included "as is" and used.

    Any ways until you get comfortable with .NET many task will appear complicated but once over the initial learning curve I expect you will welcome complex but not see it as complex but freedom.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, August 13, 2013 7:50 PM

All replies

  • The following does a TextFile, requires a DataGridView to see the results. Alternate still using a class like below there is the BinaryFormatter class.

    Public Class Form1
        Private Items As New List(Of MyStructure)
        Private FileName As String = IO.Path.Combine(Application.StartupPath, "MyFile.txt")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Items.AddRange(
                New MyStructure() _
                {
                    New MyStructure With
                    {
                        .Number = 1,
                        .Name = "Name1",
                        .Description = "Desc 1",
                        .Extension = "Ext1"
                    },
                    New MyStructure With
                    {
                        .Number = 2,
                        .Name = "Name2",
                        .Description = "Desc 2",
                        .Extension = "Ext2"
                    },
                    New MyStructure With
                    {
                        .Number = 3,
                        .Name = "Name3",
                        .Description = "Desc 3",
                        .Extension = "Ext3"
                    }
                }
            )
            Dim sb As New System.Text.StringBuilder
            For Each item In Items
                sb.AppendLine(item.ToString)
            Next
            IO.File.WriteAllText(FileName, sb.ToString)
        End Sub
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Items.Clear()
            Using Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(FileName)
                Reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
                Reader.Delimiters = New String() {","}
                Dim Row As String()
                While Not Reader.EndOfData
                    Try
                        Row = Reader.ReadFields()
                        Items.Add(
                            New MyStructure With
                            {
                                .Number = CInt(Row(0)),
                                .Description = Row(1),
                                .Name = Row(2),
                                .Extension = Row(3)
                            }
                        )
                    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                        MessageBox.Show("Line " & ex.Message & " is invalid.  Skipping")
                    End Try
                End While
            End Using
            DataGridView1.DataSource = Items
        End Sub
    End Class

    Class for above

    Public Class MyStructure
        Public Property Number As Int32
        Public Property Description As String
        Public Property Name As String
        Public Property Extension As String
        Public Sub New()
        End Sub
        Public ReadOnly Property ItemArray As Object()
            Get
                Return New Object() {Me.Number, Me.Description, Me.Name, Me.Extension}
            End Get
        End Property
        Public Overrides Function ToString() As String
            Return String.Join(",", Me.ItemArray)
        End Function
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by BigTee Phil Tuesday, August 06, 2013 8:11 PM
    • Unmarked as answer by BigTee Phil Tuesday, August 06, 2013 8:11 PM
    Saturday, August 03, 2013 12:22 AM
  • Yes it is challenging to upgrade. I had some C code that read a binary file of Canadian Weather Stations that posed the same problem you are experiencing with fixed length data in a struct (Type) but with the Help of Anthony Baraff's

    Fast Binary File Reading with C#

    available at

    http://www.codeproject.com/Articles/10750/Fast-Binary-File-Reading-with-C

    I was able to do a conversion to C#.

    The VB code below was converted from C# using Tangible Software Solutions Instant VB. I compiled it with Visual BASIC 2010 and it ran as expected.

    Hopefully it will help you get beyond this particular stumbling block.

    Robert Wishlaw

    Imports System
    Imports System.IO
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    
    <StructLayout(LayoutKind.Sequential, CharSet := CharSet.Ansi, Pack := 1)> _
    Friend Structure IndexFileHeader
    	<MarshalAs(UnmanagedType.ByValArray, SizeConst := 4)> _
    	Public CSN() As Char
    	<MarshalAs(UnmanagedType.ByValArray, SizeConst := 24)> _
    	Public StationName() As Char
    	<MarshalAs(UnmanagedType.ByValArray, SizeConst := 3)> _
    	Public Airport() As Char
    	Public Latitude As Int16
    	Public Longitude As Int16
    	Public Elevation As Int16
    	<MarshalAs(UnmanagedType.ByValArray, SizeConst := 7)> _
    	Public FirstYear() As Int16
    	<MarshalAs(UnmanagedType.ByValArray, SizeConst := 7)> _
    	Public LastYear() As Int16
    	Public StartingRecordNumber As Int16
    End Structure
    Friend Class MyStream
    	Private Const FileName As String = "STATIONS.ALL"
    	Public Shared Sub Main(ByVal args() As String)
    
    		' get file size
    		Dim oFileInfo As New FileInfo(FileName)
    		Dim FileSize As Long = oFileInfo.Length
    		Dim StructSize As Integer = Marshal.SizeOf(GetType(IndexFileHeader))
    		' number of records
    		Dim Records As Long = FileSize \ StructSize
    		Dim Record As Long = 0
    		Dim str1 As String = ""
    		Dim str2 As String = ""
    		Dim str3 As String = ""
    		' Create the reader for data.
    		Dim fs As New FileStream(FileName, FileMode.Open, FileAccess.Read)
    		Dim r As New BinaryReader(fs)
    
    		'Read byte array
    		Do
    			Dim buff() As Byte = r.ReadBytes(Marshal.SizeOf(GetType(IndexFileHeader)))
    			'Make sure that the Garbage Collector doesn't move our buffer 
    			Dim handle As GCHandle = GCHandle.Alloc(buff, GCHandleType.Pinned)
    			'Marshal the bytes
    			Dim s As IndexFileHeader = CType(Marshal.PtrToStructure(handle.AddrOfPinnedObject(), GetType(IndexFileHeader)), IndexFileHeader)
    			handle.Free() 'Give control of the buffer back to the GC
    
    			Console.Write(s.CSN)
    			Console.Write(",")
    			str2 = New String(s.StationName)
    			str3 = str2.Replace(",", "")
    			str1 = str3.Trim()
    			Console.Write(str1)
    			Console.Write(",")
    			str2 = New String(s.Airport)
    			str1 = str2.Trim()
    			Console.Write(str1)
    			Console.Write(",")
    			Console.Write(s.Latitude)
    			Console.Write(",")
    			Console.Write(s.Longitude)
    			Console.Write(",")
    			Console.Write(s.Elevation)
    			Console.Write(",")
    			Console.Write(s.FirstYear(0))
    			Console.Write(",")
    			Console.Write(s.FirstYear(1))
    			Console.Write(",")
    			Console.Write(s.FirstYear(2))
    			Console.Write(",")
    			Console.Write(s.FirstYear(3))
    			Console.Write(",")
    			Console.Write(s.FirstYear(4))
    			Console.Write(",")
    			Console.Write(s.FirstYear(5))
    			Console.Write(",")
    			Console.Write(s.FirstYear(6))
    			Console.Write(",")
    			Console.Write(s.LastYear(0))
    			Console.Write(",")
    			Console.Write(s.LastYear(1))
    			Console.Write(",")
    			Console.Write(s.LastYear(2))
    			Console.Write(",")
    			Console.Write(s.LastYear(3))
    			Console.Write(",")
    			Console.Write(s.LastYear(4))
    			Console.Write(",")
    			Console.Write(s.LastYear(5))
    			Console.Write(",")
    			Console.Write(s.LastYear(6))
    			Console.Write(",")
    			Console.WriteLine(s.StartingRecordNumber)
    			Record += 1
    		Loop While Record < Records
    		r.Close()
    		fs.Close()
        End Sub
    
    End Class

    Saturday, August 03, 2013 4:12 AM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{16FCFEC4-211C-42F5-827D-EA4D14365754}" /></object>Thank you Kevisinstructor.  I am learning new things all the time and I need to study your code more, but this does not create a fixed length sequential file.  It does a comma delimited sequential file.   I do have an application for this type of structure as well so it is not in vain.  BigTee Phil
    Tuesday, August 06, 2013 8:11 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{19337CD8-2ECE-4A86-98BF-10A3FEFA7B7D}" /></object>I'm having a problem with the line: Dim s as indexFileHeader =  It seems to be cut off so the program will not run.  Can you complete the line for me?  Thanks, BigTee Phil
    Tuesday, August 06, 2013 8:25 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{16FCFEC4-211C-42F5-827D-EA4D14365754}" /></object>Thank you Kevisinstructor.  I am learning new things all the time and I need to study your code more, but this does not create a fixed length sequential file.  It does a comma delimited sequential file.   I do have an application for this type of structure as well so it is not in vain.  BigTee Phil

    Hello BigTee Phil,

    Yes I understand it is not the type you were looking for but thought if open to alternates you might consider it or what I did not show, a binary version but neither are fixed lengths.

    Possible options no matter if writing to text or binary file we can control lengths. The following example is not what I call fully asserted so to show the basic concept.

    Public Class MyStructure
        Public Property Number As Int32
        Public Property Description As String
        Public Property Name As String
        Private mExtension As String = ""
        Public Property Extension As String
            Set(value As String)
                If value.Length > 3 Then
                    mExtension = value.Substring(0, 3)
                Else
                    mExtension = value
                End If
            End Set
            Get
                Return mExtension
            End Get
        End Property
        Public Sub New()
        End Sub
        Public ReadOnly Property ItemArray As Object()
            Get
                '
                ' Example does not consider string length might be less than what I index. So for real life
                ' we would have more code to ensure we do not index outside the length of a string.
                '
                Return New Object() {Me.Number, Me.Description.Substring(0, 42), Me.Name.Substring(0, 15), Me.Extension}
            End Get
        End Property
        Public Overrides Function ToString() As String
            Return String.Join(",", Me.ItemArray)
        End Function
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.



    Tuesday, August 06, 2013 9:11 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{7E8D1A34-01DB-4C48-AF7B-59DCB507AF23}" /></object>No, the point is the data must be fixed length to be able to access the data as records in a file.  I am aware of the many other ways to store data, but fixed length records (old school, maybe) were very easy to access in a random file environment.  So in my example if you needed to the know the information about file number 2000 you could read the 2000th record and find out from the data in the record.  This functionally appears to be gone completely from VS 2010/VB.net.  I'm sure it is somewhere else, but I have not found it yet.  Thanks for you help.  BigTee Phil
    Wednesday, August 07, 2013 1:15 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{7E8D1A34-01DB-4C48-AF7B-59DCB507AF23}" /></object>No, the point is the data must be fixed length to be able to access the data as records in a file.  I am aware of the many other ways to store data, but fixed length records (old school, maybe) were very easy to access in a random file environment.  So in my example if you needed to the know the information about file number 2000 you could read the 2000th record and find out from the data in the record.  This functionally appears to be gone completely from VS 2010/VB.net.  I'm sure it is somewhere else, but I have not found it yet.  Thanks for you help.  BigTee Phil

    If I have a free hour today I will write up an example that is binary, fix length and indexable, strongly typed as I have done this before including encryption on the fly.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Wednesday, August 07, 2013 3:11 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{613EAA9B-27A3-4927-9025-E61310740AE1}" /></object>

    That would be great if you have the time.  The other example received may show that, at least that is what they imply.  But the version I received  does not compile because of this incomplete line:

    Dim s As IndexFileHeader = CType(Marshal.PtrToStructure(handle.AddrOfPinnedObject

    If you know how to complete this line, it may save you the time of writing your example.

    Thanks,

    BigTee Phil

    Thursday, August 08, 2013 1:48 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{613EAA9B-27A3-4927-9025-E61310740AE1}" /></object>

    That would be great if you have the time.  The other example received may show that, at least that is what they imply.  But the version I received  does not compile because of this incomplete line:

    Dim s As IndexFileHeader = CType(Marshal.PtrToStructure(handle.AddrOfPinnedObject

    If you know how to complete this line, it may save you the time of writing your example.

    Thanks,

    BigTee Phil

    This is the complete line from Robert Wishlaw post

    'Marshal the bytes
    Dim s As IndexFileHeader = _
        CType( _
            Marshal.PtrToStructure(handle.AddrOfPinnedObject(), _
                                   GetType(IndexFileHeader)), IndexFileHeader)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Thursday, August 08, 2013 2:40 PM
  • Okay,

    I do not have VS2010 installed so rather than upload a project to SkyDrive for demoing here is the code which is VS2010 compatible.

    So the demo below shows the basics for read/write class data to and from disk.

    Form, three buttons, one DataGridView

    ''' <summary>
    ''' For this demo I delete the binary file on startup so we have clean data each time
    ''' which of course you would not do for a read app.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Form1
        Private FileName As String = IO.Path.Combine(Application.StartupPath, "KSG.Bin")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If IO.File.Exists(FileName) Then
                IO.File.Delete(FileName)
            End If
            DataGridView1.ReadOnly = True
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
            Dim List As New AllFiles(FileName)
            List.Add(
                New AllFile With
                {
                    .Identifier = List.NextIdentifier,
                    .FileName = "Test1.txt",
                    .FileDescription = "Test1 demo"
                }
            )
            ' Test length constraint on file name
            List.Add(
                New AllFile With
                {
                    .Identifier = List.NextIdentifier,
                    .FileName = "1234567890123456",
                    .FileDescription = "Test2 demo"
                }
            )
            List.Add(
                New AllFile With
                {
                    .Identifier = List.NextIdentifier,
                    .FileName = "Test3.txt",
                    .FileDescription = "Test3 demo"
                }
            )
            If List.SaveToDataFile Then
                MessageBox.Show("Saved")
            Else
                MessageBox.Show("Not saved")
            End If
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles cmdLoad.Click
            Dim List As New AllFiles(FileName)
            If List.LoadFromDataFile() Then
                DataGridView1.DataSource = List.DataTable
                For Each col As DataGridViewColumn In DataGridView1.Columns
                    col.HeaderText = List.DataTable.Columns(col.Name).Caption
                Next
            End If
        End Sub
        Private Sub cmdExport_Click(sender As Object, e As EventArgs) Handles cmdFind.Click
            If Not IO.File.Exists(FileName) Then
                MessageBox.Show("Please create file via the Save button")
            End If
            Dim List As New AllFiles(FileName)
            If List.LoadFromDataFile() Then
                Dim Item = List.GetItemByFileName("Test1.txt")
                If Item IsNot Nothing Then
                    MessageBox.Show(Item.ToString)
                End If
            End If
        End Sub
    End Class

    Class responsible for basics of read/write a binary file. It is not full feature but if you take the time to understand what I did you can complete it. For instance I show read/write, hard coded find, get next primary key value (thinking one user adds items at any one time). Did not do edits and deletes but you should have no problem if you study the code provided. Also an improvement would be to have changes trigger an event i.e. property change notification.

    Of course feel free to ask for assistance :-)

    Imports System.Runtime.Serialization.Formatters.Binary
    <Serializable()>
    Public Class AllFile
        ''' <summary>
        ''' Primary method to identify an item
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>
        ''' SEE ALSO NextIdentifier in AllFiles class
        ''' </remarks>
        Public Property Identifier As Int32
        Private mFileDescription As String
        Public Property FileDescription As String
            Set(value As String)
                If Not String.IsNullOrWhiteSpace(value) Then
                    If value.Trim.Length > 42 Then
                        mFileDescription = value.Trim.Substring(0, 42)
                    Else
                        mFileDescription = value
                    End If
                End If
            End Set
            Get
                Return mFileDescription
            End Get
        End Property
        Private mFileName As String
        Public Property FileName As String
            Set(value As String)
                If Not String.IsNullOrWhiteSpace(value) Then
                    If value.Trim.Length > 15 Then
                        mFileName = value.Trim.Substring(0, 15)
                    Else
                        mFileName = value
                    End If
                End If
            End Set
            Get
                Return mFileName
            End Get
        End Property
        Public Sub New()
        End Sub
        Public Overrides Function ToString() As String
            Return Me.Identifier.ToString & " " & Me.FileName & " " & Me.FileDescription
        End Function
    End Class
    Public Class AllFiles
        Inherits CollectionBase
        Private mErrors As System.Text.StringBuilder
        Public ReadOnly Property Errors As String
            Get
                Return mErrors.ToString
            End Get
        End Property
        Private mDataFile As String
        Public ReadOnly Property DataFile() As String
            Get
                Return mDataFile
            End Get
        End Property
        Private mDataTable As DataTable
        Public ReadOnly Property DataTable As DataTable
            Get
                mDataTable.Rows.Clear()
                If Me.Count > 0 Then
                    For Each oItem As AllFile In Me.InnerList
                        mDataTable.Rows.Add(New Object() {oItem.Identifier, oItem.FileName, oItem.FileDescription})
                    Next
                End If
                Return mDataTable
            End Get
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="FileName">Name of file to read and write too</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal FileName As String)
            MyBase.New()
            mDataFile = FileName
            mDataTable = New DataTable
            mDataTable.Columns.Add(New DataColumn With {.ColumnName = "Identifier", .DataType = GetType(Int32), .Caption = "ID"})
            mDataTable.Columns.Add(New DataColumn With {.ColumnName = "FileName", .DataType = GetType(String), .Caption = "Name"})
            mDataTable.Columns.Add(New DataColumn With {.ColumnName = "FileDescription", .DataType = GetType(String), .Caption = "Description"})
        End Sub
        Public Sub Load(ByVal oReader As IDataReader)
            While oReader.Read = True
                Dim oItem As New AllFile
                Me.Add(oItem)
            End While
        End Sub
        Public Function GetItemByFileName(ByVal FileName As String) As AllFile
            Return (From T In Me.List.Cast(Of AllFile)() Where T.FileName = FileName).FirstOrDefault
        End Function
        Public Function GetItemByIdentifier(ByVal Identifier As Int32) As AllFile
            Return (From T In Me.List.Cast(Of AllFile)() Where T.Identifier = Identifier).FirstOrDefault
        End Function
        Public Sub Insert(ByVal iIndex As Integer, ByVal oItem As AllFile)
            InnerList.Insert(iIndex, oItem)
        End Sub
        Public Sub Remove(ByVal oItem As AllFile)
            InnerList.Remove(oItem)
        End Sub
        Public Function Contains(ByVal oItem As AllFile) As Boolean
            Return InnerList.Contains(oItem)
        End Function
        Public Function IndexOf(ByVal oItem As AllFile) As Integer
            Return InnerList.IndexOf(oItem)
        End Function
        Public Function Row(ByVal oItem As AllFile) As Integer
            Return Me.IndexOf(oItem)
        End Function
        Public Function Add(ByVal oItem As AllFile) As Integer
            Return InnerList.Add(oItem)
        End Function
        Public ReadOnly Property NextIdentifier As Int32
            Get
                If Me.Count = 0 Then
                    Return 1
                Else
                    Return (From T In Me.InnerList.Cast(Of AllFile)() Select T.Identifier).Max + 1
                End If
            End Get
        End Property
        Public Function LoadFromDataFile() As Boolean
            Const TheCaller As String = "AllFiles.LoadFromDataFile"
            Dim BinF As New BinaryFormatter
            Dim obj As Object
            Dim oItem As AllFile
            If System.IO.File.Exists(DataFile) Then
                Try
                    Dim FS As New System.IO.FileStream(DataFile, IO.FileMode.OpenOrCreate)
                    Do
                        obj = BinF.Deserialize(FS)
                        If obj.GetType Is GetType(AllFile) Then
                            oItem = CType(obj, AllFile)
                            Console.WriteLine(oItem.ToString)
                            Me.Add(oItem)
                        End If
                    Loop While FS.Position < FS.Length - 1
                    FS.Close()
                    Return True
                Catch ioe As System.IO.IOException
                    Me.mErrors.AppendLine(TheCaller & Environment.NewLine & ioe.Message)
                    Return False
                Catch ex As Exception
                    Me.mErrors.AppendLine(TheCaller & Environment.NewLine & ex.Message)
                    Return False
                End Try
            Else
                Return False
            End If
        End Function
        Public Function SaveToDataFile() As Boolean
            If Me.Count = 0 Then
                Me.mErrors.AppendLine("No items to save")
                Return False
            End If
            Dim BinF As New BinaryFormatter
            Try
                Dim FS As New System.IO.FileStream(DataFile, IO.FileMode.Create)
                For Each oItem As AllFile In Me.InnerList
                    BinF.Serialize(FS, oItem)
                Next
                FS.Close()
                Return True
            Catch ioe As System.IO.IOException
                Return False
            Catch ex As Exception
                Return False
            End Try
        End Function
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Thursday, August 08, 2013 4:23 PM
  •   

    I have been studying your code and I still do not believe it does what my simple example did and wow I guess I have created a monster of a problems from a simple example.  I thought your code was going to show me the correct way, but I am still wondering why is it so complicated.  The part that I really liked in the old way was the ability to use an integer (or any other type of variable I wished to declare) simply by giving it a name in the TYPE declaration and then using the variable as it is declared.  The process above just doesn't do that.  I have added some code to your solution in a effort to allow for entry of data via text boxes to build a data base and search for records by index (the old index sequential file structure) but I'm not seeing your solution as a solution.  I was able to accomplish the compile of your code successfully and the program did run, but as far as I could tell.  The program didn't do much and did not give me the ability to retrieve say record with file number 100 as a request.

    Of course, I can put the data into an Access data base and work that way, but that doesn't seem to be simple either.  I will continue to pursue this path and eventually I will find the explanation.

    Thanks for your effort.

    BigTee Phil

    <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{1222BC5F-80CF-4BDC-AF4D-4881001914E0}" /></object>
    Tuesday, August 13, 2013 6:45 PM
  • Hello,

    Sorry to hear this. Here is my take on complicated, if you have a .NET developer with only a VB6 background they are use to simple (I used simple thru out in the realm of how VB6 made things simple) for common task of developing solutions and rightfully so as this was one of the reasons VB6 was extremely successful but on the other hand simple meant that to venture out for task outside of simple meant complex code to get around simple. Now if a developer starting with .NET came from say Delphi or C they expect to not have simple. What is (and this is my opinion) great about not being constrained by simple is you are very free to flex your wings and do almost whatever you need. As you become proficient with the language you should see patterns and with these patterns and understanding of the Framework will be able to write re-usable code in the form of classes and language extensions that can be placed into utility projects which compile to a DLL that can be used in other projects or these projects can simply be included "as is" and used.

    Any ways until you get comfortable with .NET many task will appear complicated but once over the initial learning curve I expect you will welcome complex but not see it as complex but freedom.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, August 13, 2013 7:50 PM
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{17DDF39C-F5E0-470F-BAEE-5948CCFD76B1}" /></object>I agree with you on complex gets easier (simple) with usage.  I hope you are correct.  I have always been a person looking for an easy way to accomplish a task, VB6 was such a tool.  I guess I just don't understand why useful tools  had to be removed from the language without an equivalent solution that can be called in a macro.  That seems to be going backwards.  Thanks for you assistance.  BigTee Phil 
    Wednesday, August 14, 2013 12:33 PM
  • Thanks for Kevininstructor’s kindly help.

    Hi BigTee,

    Could you get useful information from Kevininstructor’s replies? If it is helpful for you, you could make the reply as the answer.

    Actually this forum is to discuss the VS usage issue. If still no help, to help you resolve this issue as soon as possible, I suggest you post this issue to the specific VB language development forum, and there you would get better response from the VB experts.

    For VB issue, you could post it to Visual Basic like this case “Converting VB6 apps to VB2010”.

    For VB 6.0 issue, I think you would get useful information from here:

    Where to post your VB 6 questions

    If there's any concern, please feel free to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 15, 2013 2:49 AM
    Moderator
  • <object height="1" id="plugin0" style=";z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{9DD9F306-4661-455B-A1A1-71057234A787}" /></object>

    You know I thought that would be the case as well, but I don't seem to get any favorable responses from that forum.  I am not a expert, but have been coding for many years.  I do love VB6 and want to become proficient in VB 2010+.  It will probably take me many months to understand since I don't do this full time anymore.

    Thanks for your responses,

    BigTee Phil

    Tuesday, August 27, 2013 1:25 PM
  • Hi BigTee,

    As far as I know, there are many participators and community members in the language development forum, so if you get a development issue, please feel free to post the development issue to the specific language forum, and you would get better response.

    If you get any VS usage issue, welcome to our forum.J

    Have a nice day,


    Jack Zhai[MSFT]
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, August 28, 2013 1:40 AM
    Moderator