?
Solved

Preload Data Into VB App

Posted on 2006-05-08
13
Medium Priority
?
283 Views
Last Modified: 2012-06-21
Is it possible to preload data into a vb.net app?  I don't want to send a db with it either.  I want it to be completely transparent ot the client, so that they only see the executable and that is it.  This app can't be installed on the client's harddrive - it must run from a disk.
0
Comment
Question by:bengelhart
  • 6
  • 5
12 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 16634975
You could put data into an assembly (i.e., a separate file from the code) that gets built into the executable. You'd probably want to make it a class module for easy reference. Do you have a lot of data to load? Is having it all in text format in the class module file OK, or do you have pictures and other data for which text doesn't work well? Is this data that will be different for each client, or the same for everyone whom you send the program to?
0
 

Author Comment

by:bengelhart
ID: 16634988
It will all be text values, and yes it will be different for each client.  The record count will be anywhere from 500 to 8000.
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 16635103
Presumably the records are actually coming from a database that you have. There may be a way to store the db inside your executable, and then load the data when the program starts, but that requires a level of expertise above mine. 8-) Another option would be to create a loading program (that's used only on your computer) that reads your database and creates a text file containing the data structured as a class module. The output file would then be built into your executable.

So the output would look something like:

Public Class StandardData

   Public strCountries(50) as String
   strCountries(0) = "United States"
   ...

End Class

You'd then have a reference in your program to myapp.StandardData.strCountries(0) for "United States" (where "myapp" is the name of the root namespace for your application). You can put "Imports myapp.StandardData" at the beginning of your regular program file to avoid having to reference "myapp" each time.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:bengelhart
ID: 16635143
Cool I will try that.  Thanks.  That should definitely do the trick.  I am going to try it out tomorrow.  I will respond to this question and accept the answer if it works.  IF anyone knows how to attach a db lick ElrondCT is saying please feel free to jump in!
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 16637980
Correction: I should have verified my suggestion before making it. It needs to be rewritten as follows:

Public Class StandardData

   Public Shared strCountry() = { _
      "United States", _
      "Canada", _
      ...
      "Zimbabwe" }

End Class

then in your application, you can use myapp.StandardData.strCountry(1) (or if you specify "Imports myapp.StandardData" at the beginning of your form code, you can just use strCountry(1) ).

You can, of course, have as many items on a line as you want, but since you'll be generating this from a database, it'll probably be easiest to have each on its own line, with the _ continuation character to tie everything together. One annoyance is that VB doesn't allow comments in the middle of a logical statement, so there's no way to notate in the code what subscript each element has.

My apologies for not checking this out more carefully originally, but the above is tested and I think will do what you want.
0
 

Author Comment

by:bengelhart
ID: 16639055
Excellent thanks.  I have about 8 columns per record, so I will just create a class for each column so that the index for each column is equal.  How would I create a loading function for something like this?  Does VB.NET support creating classes through functions?
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 16639800
What I have in mind is a second application, used only to create the class module. It would use a StreamWriter to output the data you want in the class. All of the columns could be in a single class. So it would look something like this:

        Dim swriOut As New System.IO.StreamWriter("StructuredData.vb")
        Dim strOutCountry(5) As String
        Dim strOutCity(6) As String
        Dim i As Integer

        swriOut.WriteLine("Public Class StrcturedData")
        swriOut.WriteLine("")
        swriOut.WriteLine("Public Shared strCountry() as String = { _")
        For i = 0 To strOutCountry.GetUpperBound(0) - 1
            swriOut.WriteLine("""" & strOutCountry(i) & """, _ ")
        Next
        swriOut.WriteLine("""" & strOutCountry(strOutCountry.GetUpperBound(0)) & """}")

        swriOut.WriteLine("Public Shared strCity() as String = { _")
        For i = 0 To strOutCity.GetUpperBound(0) - 1
            swriOut.WriteLine("""" & strOutCity(i) & """, _ ")
        Next
        swriOut.WriteLine("""" & strOutCity(strOutCity.GetUpperBound(0)) & """}")

        swriOut.WriteLine("End Class")
        swriOut.Close()

Once you've run this application, you add StructuredData.vb to your real application (right-click on the project in the Solution Explorer, choose Add, then Add Existing Item). It's now ready for the program to use. When you want to recompile the application for a different client, you run the StreamWriter application again and pop the new file into the primary application. Does that make sense?
0
 

Author Comment

by:bengelhart
ID: 16639969
Yeah I think that will work.  I will test it tomorrow to see how it goes.  I will get back to you.  Thanks!!!!
0
 

Author Comment

by:bengelhart
ID: 16755997
Actually I would like to use an XML file as an embedded resource to do this.  I just can't figure out how to read it.  here is my code so far:

        Dim ExecAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
        Dim stName As String = ExecAssembly.GetName.ToString
        Dim Str As IO.Stream = ExecAssembly.GetManifestResourceStream(stName & ".ASQ.xml")
        ds.ReadXml(Str)

        'dgList is a datagrid
        dgList.DataSource = ds
        dgList.Refresh()
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 16756125
You're in an area of the language that I have no experience with, so I can't offer any help. Sorry. You might want to post a new question specifically asking how to read an XML file that's an embedded resource.

Another thread that I found that might be useful for you is http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21259587.html.  It shows how to save variables to an XML file and read them back. It presupposes an XML file that is external to the application, but it may be possible to use the basic ideas and tweak it to work with an embedded file.
0
 

Author Comment

by:bengelhart
ID: 16763548
Got it figured out now.  My namespace had spaces in the name so those spaces needed to be underscores.  
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16968260
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question