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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:32:57+00:00 2026-06-17T16:32:57+00:00

I am new to VB.NET and WPF. I am building a Questionnaire app. Users

  • 0

I am new to VB.NET and WPF.

I am building a “Questionnaire” app. Users will be presented sequentially with different questions/tasks (windows). After they respond on each question/task and press a “submit” button a new window will open with a new question/task, and previous window will close. After each question, when the button is pressed, I need to store data to some global object. After all questions are answered the data of this object should be written out to the output file.

I figured out that Dictionary will be the best to store the results after each window.

I am not sure how, where to create this global Dictionary and how to access it. Should I use View Model? If yes, can you give an example? Or, should it be just a simple class with shared property? (something like this)

EDIT 2: I tried many different ways recommended online

GlobalModule:

Module GlobalModule
   Public Foo As String
End Module

GlobalVariables:

Public Class GlobalVariables
   Public Shared UserName As String = "Tim Johnson"
   Public Shared UserAge As Integer = 39
End Class

Global properties:

Public Class Globals

Public Shared Property One As String
    Get
        Return TryCast(Application.Current.Properties("One"), String)
    End Get
    Set(ByVal value As String)
        Application.Current.Properties("One") = value
    End Set
End Property

Public Shared Property Two As Integer
    Get
        Return Convert.ToInt32(Application.Current.Properties("Two"))
    End Get
    Set(ByVal value As Integer)
        Application.Current.Properties("Two") = value
    End Set
End Property

End Class

Here is where I save the data to global variables/properties in the first window. I need to store data in this subroutine before closing an old window and opening a new window. I use MessageBox just for testing.

Private Sub btnEnter_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnEnter.Click

    Dim instructionWindow As InstructionsWindow

    instructionWindow = New InstructionsWindow()

    Application.Current.Properties("number") = textBoxValue.Text

    Globals.One = "2"
    Globals.Two = 3

    MessageBox.Show("GlobalVariables: UserName=" & GlobalVariables.UserName & " UserAge=" & GlobalVariables.UserAge)

    GlobalVariables.UserName = "Viktor"
    GlobalVariables.UserAge = 34

    GlobalModule.Foo = "Test Foo"


    'testing if it saved tha value
    'MessageBox.Show(Application.Current.Properties("number"))

    Application.Current.MainWindow.Close()

    instructionWindow.ShowDialog()

End Sub

Next subroutine is where I am trying to retrieve the value from global Properties/variables in the second window, but message boxes come out empty. There might also the case that I am assigning values in a wrong way, or not reading them in a right way (casting?) :

Private Sub FlowDocReader_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles FlowDocReader.Initialized

    ' Get a reference to the Application base class instance.
    Dim currentApplication As Application = Application.Current

    MessageBox.Show(currentApplication.Properties("number"))

    MessageBox.Show("One = " & Globals.One & " Two = " & Globals.Two)

    MessageBox.Show("GlobalVariables: UserName=" & GlobalVariables.UserName & " UserAge=" & GlobalVariables.UserAge)

    MessageBox.Show("GlobalModule.Foo = " & GlobalModule.Foo)

    Dim filename As String = My.Computer.FileSystem.CurrentDirectory & "\instructions.txt"

    Dim paragraph As Paragraph = New Paragraph()
    paragraph.Inlines.Add(System.IO.File.ReadAllText(filename))
    Dim document As FlowDocument = New FlowDocument(paragraph)
    FlowDocReader.Document = document

End Sub

Thanks.

  • 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-17T16:32:58+00:00Added an answer on June 17, 2026 at 4:32 pm

    You can make public Dictionary property for form and put your dictionry to this property or make constructor with Dictionary argument.

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

Sidebar

Related Questions

I have 2 Windows in my sample App (learning .Net 4 WPF) In the
We are having a windows aplication(WPF .net 3.5) that client will be installing using
I am new to ASP.NET, experienced with WinForms and WPF. Go easy on me.
I am relatively new to .NET/C#/WPF/XAML. I have noticed sometimes controls seem to be
I'm relatively new to .Net 4 and I am creating my FIRST WPF application
I'm very new to .Net and WPF and have a problem. The code is
I'm relatively new to VB.NET and WPF and I have a basic threading question.
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
I am building a multiuser WPF application (requirement is a desktop app), database SQL
In my WPF app, I am creating a FlowDocument by building its XAML markup

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.