Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Link a text file? (VB6)

    Not quite sure where to start here but maybe someone can point me in the right direction.

    I have a very long string of numbers (1000+) in which I want to manipulate specific parts of it. At present the string is in a text file. As the string is so long is there a way of an application being "pointed" towards that file, extracting the specific part of the string I want and then manipulating it within the code?

    So basically, how do I link a .txt or other file to a VB application
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Link a text file? (VB6)

    I don't think you can link a text file in VB6, but you can open it and read data from it. One possibility is to use the old BASIC file manipulation instructions:

    Dim f As Integer
    Dim strLine As String
    f = FreeFile
    Open "F:VB6Test.txt" For Input As #f
    Line Input #f, strLine
    Close #f
    ' Code to extract specific part from strLine goes here

    Another possibility is to use the more "modern" FileSystemObject: set a reference to Microsoft Scripting Runtime in Project | References...

    Dim fso As New Scripting.FileSystemObject
    Dim ts As Scripting.TextStream
    Dim strLine As String
    Set ts = fso.OpenTextFile("F:VB6Test.txt")
    strLine = ts.ReadLine
    ts.Close
    Set ts = Nothing
    Set fso = Nothing
    ' Code to extract specific part from strLine goes here

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Link a text file? (VB6)

    Thanks Hans

    This is one of my little personal "projects". The application is at home so I will try it tonight and get back to you tomorrow if any problems <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Jerry

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link a text file? (VB6)

    I don't know how big your file is Jezza, but a string can hold up to about 2 billion characters. You might be able to read the whole thing into a single string, then use string manipulation functions together with type conversion functions, to perform your required tasks.

    Alan

  5. #5
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Link a text file? (VB6)

    Thanks Alan

    I was doing some background research after Hans replied to me, although I said 1000+, my dream was to have 1,000,000!!!!! So this is perfect as I would prefer to put it all in, in one go. I have a feeling I will have to get my old PC under my desk running so I can run it over night or more as the Jezzaettes will be want to play Sims 2 at some stage.... don't get me started on that subject <img src=/S/argue.gif border=0 alt=argue width=50 height=25>
    Jerry

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link a text file? (VB6)

    I think I crossed over into what Hans was suggesting in his second block of code - didn't <img src=/S/rtfm.gif border=0 alt=rtfm width=24 height=23> properly (where m="message from Hans" in this case). Just curious - what sort of processing do you intend doing on the block of numbers you extract?

    Alan

  7. #7
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Link a text file? (VB6)

    Well Alan you had to ask <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

    I am experimenting on a cryptograph. I have managed to get PI transcribed to 1,000,000 places. What I first thought of doing was to put those figures into an 2 dimensional array but that would then cause the array to be 1000 x 1000. I then went to think I could put the digits into a 3 dimensional array of 100 x 100 x 100 which would be more manageable. By selecting 3 specific or random ASCII characters I could manipulate the figure so that it became a value between 0 and 101 but not inclusive. By taking these values (x,y,z) I could then find a value within my 3D array and use it as a basis to "do something". That something is Phase 2 my projectette and is "being developed".

    edited by jezza to get rid of typo's
    Jerry

  8. #8
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Link a text file? (VB6)

    Hans

    I promised to get back to you about this.

    I did some work on this last night and I have to admit that I kicked myself over its simplicity, I hadn't realised strings could be so large and hence my concern about processing time. Anyway I tried the first piece of code and timed it to be between 1 and 2 seconds to perform whilst the second piece of code took a staggering 22 seconds. I have stuck with the first.

    As you can see from the other post to Alan for the reasons, that manipulation took approx 2 seconds.

    So I have a nice 100x100x100 array which takes about 4 seconds to perform, perfect. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Jerry

Posting Permissions

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