Results 1 to 3 of 3

Thread: Using variables in different forms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Post

    Can anyone tell med how I can declare a variable, i.e. a string in the (General) in one form and use it in another form?
    I have tried Form2.txt (where txt is the name of a string declared in the (general) of Form2) but it doesn't work.
    Is there other ways to get information from one form to another?

    Also:
    How can I load the contents of a sequential file into a string? I have one method, loading it into a RichTextBox, but now I want it to get into the string without showing on the screen.
    To read it line by line takes to much memory (and time) with big files.

    Thanks in advance!


    ------------------
    Wilhelm Tunemyr,
    Sweden

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menchen"
    Heinrich Heine (1797-1856)

    Pravda zvítezi!

  2. #2
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    To declare a variable for all forms you have to declare it as Public.
    Just write Public instead of Dim.
    For Example:
    Public txt$
    Then you can access the txt variable form everywhere in the application.

    To load a text from a textfile:

    Open Textfilename for Input as #1
    Text1.text = Input(Lof(1), 1)
    Close #1

    This is really fast and puts all the content of the file into a textbox

    ------------------
    Razzle
    ICQ#: 31429438

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Public variables are usually placed in the Declarations section of a code module rather than a form. That way you can use a naming scheme such as g_strMyVar where the g_ means that it's global (that is, available everywhere), and the str indicates that it's a String. If the variable where in the Declaration section of a form, it would be named m_strMyVar, where m_ is for module level.

    As for your second question, read the fist line into a string variable, for example strMyVar, and then for all other reads say something like strMyVar = strMyVar & datafromnextread

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

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