How do I define FileOpen(C1 the Connection Name Globally

Discussion in 'Questions (Windows Mobile)' started by apstrojny2, May 4, 2009.

  1. apstrojny2

    apstrojny2 Member Licensed User

    How do I define variable C1 the 'Connection Name' Globally... This way I can test for existence in one Sub, open it in another Sub, use it in another Sub and close it in a Fourth...

    I know something needs to go in Sub Globals but I sure don't know what...

    If FileExist ("Data.txt") = true Then
    FileOpen (c1,"Data.txt",cRead ,, cASCII)
    r = FileRead (c1)
    Do Until r = EOF
    sum = sum + r
    r = FileRead (c1)
    Loop
    Msgbox (sum)
    FileClose (c1)
    End if


    Thanks Andy
     
  2. specci48

    specci48 Well-Known Member Licensed User

    Hello apstrojny2,

    just put dim c1 into the globals definition:
    Code:
    Dim c1
    So this code works:
    Code:
    Sub Globals
       
    Dim c1
    End Sub

    Sub App_Start
       Form1.Show
       TestSub1
    End Sub

    Sub TestSub1
       
    If FileExist ("Data.txt") = True Then
          FileOpen (c1,
    "Data.txt",cRead ,, cASCII)
          Test2      
          FileClose (c1)
       
    End If
    End Sub

    Sub TestSub2
       r = FileRead (c1)
       
    Do Until r = EOF
          sum = sum + r
          r = FileRead (c1)
       
    Loop
       
    Msgbox (sum)
    End Sub

    specci48
     
  3. derez

    derez Expert Licensed User

    The connection is global "by definition",you don't need to declare it in globals. You can use it in several subs and it always refer to the same connection.
    I checked it with this example:

    Code:
    Sub Globals
       
    'Declare the global variables here.
    count = 0
    End Sub

    Sub App_Start
       Form1.Show
       FileOpen(c1,
    "testfile.txt",cWrite)
       FileWrite(c1,
    "Start")
    End Sub

    Sub Button1_Click
    count = count + 
    1
    FileWrite(c1,count)
    End Sub

    Sub Button2_Click
    FileClose(c1)
    End Sub
     
  4. specci48

    specci48 Well-Known Member Licensed User

    Surprising information since this is not mentioned in the help file!

    Anyway I find it useful treating connections as all other "normal" variables and define a global dim statement for this. :)


    specci48
     
  5. agraham

    agraham Expert Licensed User

    Actually you are not defining the connection at all, you are just defining a normal global variable that has the same name as a connection.

    Connections are treated differently to and indepenently of variables and can have the same name as a variable without problem. Try it - you can assign to and use a variable with the same name as an open connection and nothing bad happens.
     
  6. specci48

    specci48 Well-Known Member Licensed User

    Thanks for clearifying this.
    Even it is possible it really would confuse me using the same name for different purposes at the same time... :eek:


    specci48
     
  7. agraham

    agraham Expert Licensed User

    Me too, some of us are human - although my better half does wonder at times! :rolleyes:
     
  8. Cableguy

    Cableguy Expert Licensed User

    By the way, how did the memory upgrade go?!?! :sign0188::sign0142:
     
  9. apstrojny2

    apstrojny2 Member Licensed User

    Thanks specci48, derez, and agraham....

    The example was excellent and helped a lot, you folks really know this stuff... I got that part of my program working...

    I do have another interesting network stream question... I'll start a new thread...

    Best regards,

    Andy
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice