Results 1 to 6 of 6

Thread: Reading text problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    222

    Reading text problem

    Hi all;

    I have text which contain data like below

    Hello
    value1=2
    value2=3
    value3=4

    i want to read these data and put them different variables.
    For example my variables wil be
    variable1=2
    variable2=3
    variable3=4

    Thanks

  2. #2
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Reading text problem

    Not quite sure what you mean here, but here goes:

    vb Code:
    1. MyVariable1 = Value1
    2. MyVariable2 = Value2

    you might want to look into using arrays for the text values and the variables.

    vb Code:
    1. 'used as a counter to loop through the array elements
    2. Dim Ctr as Long  
    3. Dim MyVar(5) As Variable
    4. Dim MyValue(5) As Long
    5.  
    6. 'this array has 6 elements to it (arrays are zero based)
    7. For Ctr = 0 To MyVar(5)    
    8.   MyVar(Ctr) = MyValue(Ctr)  'assuming the number of values to save is 6
    9. Next
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    222

    Re: Reading text problem

    My problem about split command
    I couldn't using split to value while reading from text

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Reading text problem

    Split splits strings. If the values are other types you'll have to convert.
    Code:
       Dim s() As String, i As Integer
            Open "C:\File.txt" For Input As #1
            s = Split(Input(LOF(1), 1), vbCrLf)
            Close #1
    
            IntegerVariable1 = CInt(s(0))
            LongVariable2 = CLng(s(1))
            DateVariable3 = CDate(s(2))
            'etc.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Reading text problem

    Since VAL() is available in VB6, the easiest way would be to obtain VAL(Right(Text,1)) where Text changes from "Hello" to "Value1=1" to "Value2=2" to "Value3=3".

    The returned values in each case are 0, 1, 2, and 3.
    Doctor Ed

  6. #6
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: Reading text problem

    what about replace(allcodeold, "value", "variable") ?

    seems easiest to me, but i might be misunderstanding your question.

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