Results 1 to 6 of 6

Thread: how to share string in all form(s), via module?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    how to share string in all form(s), via module?

    I have problem:

    why not work ?

    please!

    Code:
    'Form1
    Private Sub Command1_Click()
    MsgBox a
    MsgBox b
    End Sub
    
    
    'Module1
    Public a As String
    Public b as string
    a = CStr(Form1.Text1.Text)
    b = App.Path
    Last edited by rpool; Apr 24th, 2010 at 02:49 AM.

  2. #2
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    Re: simple string in module

    Quote Originally Posted by rpool View Post
    I have problem:

    why not work ?

    please!

    Code:
    'Form1
    Private Sub Command1_Click()
    MsgBox a
    MsgBox b
    End Sub
    
    
    'Module1
    Public a As String
    Public b as string
    a = CStr(Form1.Text1.Text)
    b = App.Path
    Try to put this code on Form Load

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    Re: simple string in module

    yes, put to Form_Load is work.

    But how to share that "a" "b" string in all form(s).

  4. #4
    Addicted Member BSA01's Avatar
    Join Date
    Apr 2009
    Location
    Bosnia and Herzegovina
    Posts
    146

    Re: simple string in module

    Quote Originally Posted by rpool View Post
    yes, put to Form_Load is work.

    But how to share that "a" "b" string in all form(s).
    You can do this :

    Module 1

    Code:
    Public a As String
    Public B As String
    
    Public Sub Outside()
    a = CStr(Form1.Text1.Text)
    B = App.Path
    End Sub
    On Button CLick, set :
    Code:
    Outside
    Msgbox a
    Msgbox b

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    Re: how to share string in all form(s), via module?

    how about this styles: ? same

    Code:
    'form1
    Private Sub Command1_Click()
    MsgBox astr
    
    End Sub
    
    
    'module1
    Public Function astr() As String
    astr = "module1 string"
    End Function

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: how to share string in all form(s), via module?

    You can use sub main() also.

    Code in a module:
    Code:
    '~~~ You have to set the Startup object (Project menu --> Project Properties --> Startup Object) to "Sub Main"
    Option Explicit
    
    Public a As String
    Public b As String
    
    Sub main()  '~~~ Execution of the program starts here
      '~~~ Initialize values
      a = "Hello"
      b = App.Path
      
      Form1.Show    '~~~ Display Form1
    End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width