Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:57:44+00:00 2026-05-27T07:57:44+00:00

Is this possible? Public Class Foo public var as string public sub Load(byval filename

  • 0

Is this possible?

Public Class Foo
    public var as string

    public sub Load(byval filename as string)
        'This is done
        [...]
        oItem = [...] 'Code to deserialize

        me = oItem 'THIS LINE
    end sub
end class

So that you can load foo from the serialized file like so:

Public Sub Main
    Dim f as Foo = new Foo()
    f.load("myFile")
end sub

Up until now i’ve had a function that that returns Foo as Object (I’m trying to make the serialize / deserialize process general so I can just copy and paste and avoid explicitly setting each variable)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:57:45+00:00Added an answer on May 27, 2026 at 7:57 am

    No, what you want to do in your case is have Load be a Shared Function that returns the newly created item.

    More like:

    Public Class Foo
        public var as string
    
        public Shared Function Load(byval filename as string) As Foo
            'This is done
            [...]
            oItem = [...] 'Code to deserialize
    
            Return oItem
        end sub
    end class
    
    Public Sub Main
        Dim f as Foo
        f = Foo.load("myFile")
    end sub
    

    Also, rather than embedding the deserialization directly into each class, you can have a general purpose method, such as:

    ''' <summary>
    ''' This method is used to deserialize an object from a file that was serialized using the SoapFormatter
    ''' </summary>
    ''' <param name="sFileName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Deserialize(Of T)(ByVal sFileName As String) As T
        ' Exceptions are handled by the caller
    
        Using oStream As Stream = File.Open(sFileName, FileMode.Open, IO.FileAccess.Read)
            If oStream IsNot Nothing Then
                Return DirectCast((New SoapFormatter).Deserialize(oStream), T)
            End If
        End Using
    
        Return Nothing
    End Function
    

    which you can then call as:

    Public Sub Main
        Dim f as Foo
        f = Deserialize(Of Foo)("myFile")
    end sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

imagine this: public class Foo { private IList<string> WasSet; public string Prop1 {get;set;} public
Consider the following code (C# 4.0): public class Foo : LambdaExpression { } This
I have this code: #include <iostream> class foo { public: foo(int yy){y = yy;}
This is probably not possible, but I have this class: public class Metadata<DataType> where
Is it possible to convert this java code snippet to php? public void testBalanceReturnsToZeroOnVending()
let's say I have 2 classes like this: public class Foo { [Required] public
Is it possible to write the following code via Reflection? var fake = A.Fake<Foo>(
Why doesn't this change the initial object: public class Foo { Bar item =
Say I have this: template<typename T, int X> class foo { public: void set(const
My class is like: class Foo { public String duration; public String height; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.