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 8012757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:25:37+00:00 2026-06-04T19:25:37+00:00

I am working on a GUI for a simulation program. The simulation program is

  • 0

I am working on a GUI for a simulation program. The simulation program is a single .exe which is driven by an input file (File.inp placed in the same directory).
The Original.inp file functions as a template from which the form reads all the values into an array. Then it changes these values reflecting the changes done by the user in the form. After that it writes all the new values to File.inp.
By pushing the “Run” button the Simulation.exe file is executed.
The folder structure looks like this:

root  
|  
|---input   
|   |  
|   |--Original.inp
|
|---GUI.exe
|---Simulation.exe
|---File.inp

Ideally I would supply only the GUI, the user would select the working directory and then the GUI.exe would create an input folder and extract the Original.inp and Simulation.exe in the appropriate locations. So far I have only managed to include Original.inp and Simulation.exe as “EmbeddedResources” in my VB project and I have let my code create an input folder in the working directory chosen by the user.

Can someone please explain to me how I can extract the .inp and .exe file into the correct directories? I’ve searched on google, tried File.WriteAllBytes and Filestream.WriteByte but did not get the desired results.

The problem with File.WriteAllBytes was that I could not point to the embedded resource (“Simulation.exe is not a member of Resources” and with Filestream.WriteByte I got a 0 kb file.

  • 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-06-04T19:25:41+00:00Added an answer on June 4, 2026 at 7:25 pm

    The question commenters are correct, this is probably a task best left for a setup program. However, that having been stated, in the interest of answering the question as asked I offer the following approach.

    Contrary to your supposition in your question comment, you do need to “read” the embedded resource from the GUI’s executable file, since it’s an embedded resource and not an external resource. It won’t magically extract itselt from the executable file. You need to do the manual read from the assembly and write to your specified locations. To do this, you need to read the resource using .Net Reflection, via the currently executing assembly’s GetManifestResourceStream method.

    The Simulation.exe file is a binary file so it must be handled as such. I assumed that the Orginal.inp file was a text file since it afforded the opportunity to demonstrate different types of file reads and writes. Any error handling (and there should be plenty) is omitted for brevity.

    The code could look something like this:

    Imports System.IO
    Imports System.Reflection
    
    Module Module1
    
    Sub Main()
        'Determine where the GUI executable is located and save for later use
        Dim thisAssembly As Assembly = Assembly.GetExecutingAssembly()
        Dim appFolder As String = Path.GetDirectoryName(thisAssembly.Location)
    
        Dim fileContents As String = String.Empty
    
        'Read the contents of the template file. It was assumed this is in text format so a 
        'StreamReader, adept at reading text files, was used to read the entire file into a string
        'N.B. The namespace that prefixes the file name in the next line is CRITICAL. An embedded resource
        'is placed in the executable with the namespace noted in the project file, so it must be 
        'dereferenced in the same manner.
        Using fileStream As Stream = thisAssembly.GetManifestResourceStream("SOQuestion10613051.Original.inp")
            If fileStream IsNot Nothing Then
                Using textStreamReader As New StreamReader(fileStream)
                    fileContents = textStreamReader.ReadToEnd()
                    textStreamReader.Close()
                End Using
                fileStream.Close()
            End If
        End Using
    
        'Create the "input" subfolder if it doesn't already exist
        Dim inputFolder As String = Path.Combine(appFolder, "input")
        If Not Directory.Exists(inputFolder) Then
            Directory.CreateDirectory(inputFolder)
        End If
    
        'Write the contents of the resource read above to the input sub-folder
        Using writer As New StreamWriter(Path.Combine(inputFolder, "Original.inp"))
            writer.Write(fileContents)
            writer.Close()
        End Using
    
        'Now read the simulation executable. The same namespace issues noted above still apply.
        'Since this is a binary file we use a file stream to read into a byte buffer
        Dim buffer() As Byte = Nothing
        Using fileStream As Stream = thisAssembly.GetManifestResourceStream("SOQuestion10613051.Simulation.exe")
            If fileStream IsNot Nothing Then
                ReDim buffer(fileStream.Length)
                fileStream.Read(buffer, 0, fileStream.Length)
                fileStream.Close()
            End If
        End Using
    
        'Now write the byte buffer with the contents of the executable file to the root folder
        If buffer IsNot Nothing Then
            Using exeStream As New FileStream(Path.Combine(appFolder, "Simulation.exe"), FileMode.Create, FileAccess.Write, FileShare.None)
                exeStream.Write(buffer, 0, buffer.Length)
                exeStream.Close()
            End Using
        End If
    
    End Sub
    
    End Module
    

    You will also have to add logic to determine if the files have been extracted so it doesn’t happen every time the GUI is invoked. That’s a big reason why an installation program might be the correct answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a GUI program in which I already bind a start button
I am working on a small basic GUI program that gets the files from
I am working on a GUI for motor control, for which i will be
I'm working with matplotlib to build a very basic GUI around a statistical model/simulation.
Background: I'm working on a GUI from Hell program. Problem: I need to change
I am working on the GUI of an older program (in Delphi). Some of
I have a problem with my program. I'm working on the gui, and I
I have been working on a Gui-based program using Tkinter. It needs data to
I'm working on a GUI framework, where I want all the elements to be
I'm working on a GUI for a card game and am using the ACM's

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.