Results 1 to 11 of 11

Thread: Working with Text Files!

  1. #1

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Unhappy

    I've been trying to get this all night!!!
    Here's what I'm trying to do, but it's kinda complicated to explain to try to stay with me!
    On a form, I have 2 labels and a text box. I want to use a text file and in it, it a list of about 100 things with 2 things - A street name and a number. Someone told me I can put the street name in "" and then the number after it with a space. Well I want to make it so it displays the street "in the" in the 1st label, and the user has to type in the number for the street in the text box. If they match, then the 2nd label says yes, else, it tells the user the right number. Now my problem is that I don't know how to load the text file and tell VB to load the name in the "" into the label. Then to see if the number and name matches...
    Does anyone know a way of doing this?

    I'll take ANY suggestions!
    Thanks a lot!
    -Emo
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

  2. #2
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Talking Split function

    You can also use the SPLIT function.
    set your street adress in the file then a specific sign (eg like an asterics) and then the number. Like this:

    Streetname*16

    When you load your line in your prog then use the split function. Like this:

    Code:
    Dim arrTemp() As String
    
    Open "c:\file" For Input As #1
    Line Input #1, strInput
    Close#1
    
    arrTemp() = Split(strInput, "*") 'Split your string in two diferent pieces, stored in arrTemp
    lblStreetName.Caption = arrTemp(0)
    lblStreetNumber.Caption = arrTemp(1)
    
    VBBrowser v2.1.6
    This 'll work

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  3. #3
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up

    Hmmm. Interesting solution. I would have done it different, but i think that'll work too.
    ~Peter


  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Here's a version...attached..
    Attached Files Attached Files
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Question

    Thanks for the reply you guys!

    WP, I did that, but I had to get rid of the this line Text1.Text = arrTemp(1) because I don't want to user to see the number, and I want him to input it! So I got stuck on the way of trying see if the number in the file and the number the user inputed match....

    I got this...
    If Text1.Text = arrTemp(1) Then

    but then what? How do I check if the 2 numbers are the same? Also, I guess I'll need some type of loop so it goes to the next line and does the same thing...

    P.S. HeSaidJoe, thanks a lot for the file, it helped a lot, but when I try to run the project, it gives me a Run-time error '6', Overflow. The line that the debugger highlights is iCount = iCount + 1

    -Emo
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    It runs fine for me...
    How many lines are you rrunning..it it's a lot try changing the Dimension of iCount from integer to Long

    Dim iCount as Long
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Unhappy ahhhhh

    I got the iCount like you said, but now when i run it, VB gives my some Run-time error '62' "Input past end of File"... and it highlights Input #iNum, sStreet, sNumber what is that supposed to mean? I tried putting it before and after the loop, but VB freezes!

    Anything?
    -Emo
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

  8. #8

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Angry

    This is starting to piss me off!!!

    I still can't get, but I found this and I'm pretty sure it will work but it gives me a Run-time error '6' "syntax error" And it highlights the exit...

    Code:
    open "path+file" for input as #1
    do until eof(1)
    input #1,name$
    label.caption = name$
    if name$ =textbox.text then v$="yes" exit do
    loop
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

  9. #9
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Wink ughhhhhhhhhh

    I see, you 're a little beginner.

    The problem was that there was no : between "yes" and "exit do".
    A ":" is used to seperated two commands on one line

    This has to work (not tested):

    Code:
    Dim MayContinue As Boolean
    
    Private Sub cmdStart_Click()
      Open "path+file" For Input As #1
      Do Until EOF(1)
        Input #1,name$, number%
        lblName.caption = name$
        MayContinue = False
        Do While Not MayContinue
          DoEvents
        Loop
        If  txtNumber.text = number% Then
          lblResult.Caption = "Very Good"
        Else
          lblResult.Caption = "Wrong"
        End If
      Loop
    End Sub
    
    Private Sub cmdCheck_click()
      MayContinue = True
    End Sub
    
    VBBrowser v2.1.6
    Does it?

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    EMO

    Send me a copy of your file and I will see if I can't get you going...the problem is in the file.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  11. #11

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Arrow

    HeSaidJoe, I sent you the file to your Yahoo E-mail.

    -Emo
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

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