Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello
I'm having difficultly to create public strings that i can use in all forms

I'm trying with Module to do it:
Imports Nini.Config
Imports System.IO

Public Module Settings

    Public MyConfigFile As String = ".\Settings.ini"
    Public MyVNCFile As String = ".\Create.vnc"
    Public BackUPFolder As String = ".\BackUP"
    Public VNCFolder As String = ".\VNC"
    'Read Source File
    Public source As New IniConfigSource(MyConfigFile)
    'Read Strings From File
    Public fileName As String = source.Configs("Update").Get("Url")
    Public columns As String = source.Configs("Update").Get("Info")

End Module


and when i use in Form1 the strings i got debug mode but not display anything just show that it doesn't read the string correct:
Example:
Public Sub CheckFolders()
        'Dim Path As String = ".\BackUP"
        'Dim Path2 As String = ".\VNC"

        If Not Directory.Exists(Settings.BackUPFolder) Then
            Directory.CreateDirectory(Settings.BackUPFolder)
        End If
        If Not Directory.Exists(Settings.VNCFolder) Then
            Directory.CreateDirectory(Settings.VNCFolder)
        End If

    End Sub

But it crash, any ideas how to make this strings correct?

What I have tried:

Tried with Module to create it, example is on top, but it crash it looks like it doesn't has any value setted up in this string i do not know why, can someone tell me how to make it correct or where i make wrong.?
Posted
Updated 4-Dec-19 5:32am
Comments
Richard MacCutchan 4-Dec-19 11:39am    
I just tried that and it works fine. Are you sure the two modules are correctly linked together?
diablo22 4-Dec-19 11:51am    
if i build new project and use my code it works...normal
but on my main project it doesn't ...that's what i want to find out why..
diablo22 4-Dec-19 11:55am    
i'm idiot maybe...
Public Sub CreateMe()
Dim source As New IniConfigSource(MyConfigFile)
'Read Strings From File
Dim fileName As String = source.Configs("Update").Get("Url")
Dim columns As String = source.Configs("Update").Get("Info")
End Sub
This make strings read correct now...

1 solution

You could use the techniques discussed at Best practice for sharing variables across forms in VB.NET - Stack Overflow[^]

But personally I find OriginalGriff's Tip series more useful Transferring information between two forms, Part 1: Parent to Child[^] - they are in C# but the principles still stand
 
Share this answer
 
Comments
diablo22 4-Dec-19 11:42am    
i sow this topics, but it doesn't describe how can i make it by module to store all stuff inside.
in c++ is easy to pass strings but on vb.net i'm not familar how to do it with module.
For me my code should work, but it doesn't for somehow it stuck on this when debug "Settings.BackUPFolder" looks like cannot read the string text
CHill60 5-Dec-19 3:43am    
The first link contains the answer "Store your global variables in a Module1.vb file, they must be publicly declared to be accessible from all forms:"
Your code uses Settings.BackUPFolder - that is the type of notation you would use if Settings was a class. Try using just BackUPFolder and VNCFolder instead
Rajeev Panday 4-Dec-19 12:29pm    
Chill, please do not discourage OP by just adding links references which anyways he can also goggle and find it out. what is point of asking in this fouram if end answer is going to some link.. please give some respect to coder who is learning. he has given so much of code that means he has done the enough background work etc.
phil.o 4-Dec-19 12:38pm    
Why do you think giving links is trying to discourage OP?
Besides, I would say that downvoting people who genuinely try to help is somehow discouraging them from answering.
CHill60 5-Dec-19 3:43am    
Thank you for your support

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900