dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Advanced Text Loading

  1. #1
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125

    Advanced Text Loading

    Hello,

    What I want to do is this. The user types a number in a textbox or so. Then there is a textfile where every line starts with a number. Like:
    Code:
    001 User 1
    002 User 2
    666 Satan
    946 Me
    So when the typed number is a number that is in the textfile. The line should be loaded in a textbox. I know there is someway to search textfiles, but cant find the code anymore.

    Thanks Very Much
    Bert Willekens,

  2. #2
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181
    Code:
    'add Microsoft Scripting Runtime
    
    
    dim fFile as New FileSystemObject
    dim myFile
    dim blnGot as Boolean
    dim strLine as String
    
    set my fFile=fFile.OpentextFile("C:\List.txt")
    blnGot=False
    do while blnGot=False
       strLine = myFile.ReadLine
       if mid(strLine,1,3)=Text1.Text Then
           Text1.Text=strLine
           blnGot=True
       End If
    loop
    Last edited by Cimperiali; June 23rd, 2003 at 02:04 PM.

  3. #3
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    Hey, thanks the code works great.

    But heres another:
    How can I check p.e. 50 text boxes for a duplicate one. So there is a msgbox when 2 or more same values are found. I could do this with if's but then i gotta do allot of if's
    Bert Willekens,

  4. #4
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181
    create a control array of text boxes
    and place this code

    Dim intI As Integer, intJ As Integer
    For intI = 0 To 19
    For intJ = intI + 1 To 20
    If Text1(intI).Text = Text1(intJ).Text Then
    MsgBox intI & " & " & intJ & " contains same Text" & vbNewLine & "The Text is " & Text1(intJ).Text
    End If
    Label1.Caption = intI & " " & intJ
    DoEvents
    Next
    Next

  5. #5
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    hey, I transformed the code to this:
    Code:
    For intI = 1 To 6
    For intJ = intI + 1 To 7
    Form1.Caption = intI & " " & intJ
    If div1_intI.Text = div1_intJ.Text Then
    MsgBox intI & " & " & intJ & " contains same Text" & vbNewLine & "The Text is " & div1_intJ.Text
    End If
    MsgBox intI & " " & intJ, vbOKCancel
    DoEvents
    Next
    Next
    My textboxes are named like this: div1_1, div1_2, div1_3, etc.. .
    I get the error: Object required
    I thinkt that the intI isnt doing wat it should do.

    Help needed

    Thanks
    Bert Willekens,

  6. #6
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    Ok, Leave it, i made it with the arrays, allot of renaming but its working now

    Thx
    Bert Willekens,

  7. #7
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    Hello,

    another question

    How can I start reading a text, in a textbox, or string after a | or another sign to say, start reading now. understand ?
    like this
    text1 = "donotread|readthis"
    and the output is
    "readthis"

    Thanks
    Bert Willekens,

  8. #8
    Join Date
    Dec 2001
    Posts
    6,332
    You can just get the position of the "|", then read after it.

    NewString = Mid(OldString, InStr(OldString, "|") + 1)

    By the way, you do not need the FileSystemObject to read a file. Just use the Open statement, and read in the lines with Input, or Line Input.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #9
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    hello,

    Hers another one.
    I have a template like:
    <font color="red" size="2"> country(0).text </font>
    if i save this into a html file with Print #1, "<font color="red" size="2">" & country(0).text & "</font>"
    then the country will be replaced with the text in the textbox. But now i have a large file where allmost every line contains lines like this. So i thought i load the file into a rtf box and then just save it, but then the program isn't replacing the country(0).text . Is there a way how I should do this ? or just do
    Print #1, "<font color="red" size="2">" & country(0).text & "</font>"
    Print #1, "<font color="red" size="2">" & name(0).text & "</font>"
    ....
    and the rest off the file.

    Thanks
    Bert Willekens,

  10. #10
    Join Date
    Dec 2001
    Posts
    6,332
    Depending on your requirements, you may be able to use a loop to iterate through the fields. I would also define the FONT tags as two strings, so then you only have to define them once.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  11. #11
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    Yow, finally i made a code that converts:
    This:

    002 Diamond Bel |Private
    003 Andr&#233; Ned |Himself
    004 Ronny Fra |BRF Racing
    005 Jefkeuh Spa |Jef Racing

    Into This:
    Hmm, To lazy, see the screenshot

    With this code:
    Code:
    Private Sub number_Change(Index As Integer)
    'Please Do NOT steal, Edit, Screw-Up this piece of code! WORKED LONG ON IT!
    On Error GoTo err:
    Set myFile = fFile.OpenTextFile(App.Path & "\list.txt")
    blnGot = False
    Do While blnGot = False
    strLine = myFile.ReadLine
    If Mid(strLine, 1, 3) = number(Index) Then
    Label9 = strLine
    nam(Index) = Mid(Label9, 4, (InStr(strLine, "|") - 9))
    Country(Index) = Mid(strLine, (InStr(strLine, "|") - 4), 3)
    leng = Len(Label9.Caption) - (Len(nam(Index).Text) - "9")
    team(Index) = Mid(strLine, (InStr(strLine, "|") + 1), leng)
    blnGot = True
    End If
    Loop
    Exit Sub
    err:
    str = "Invalid Number"
    nam(Index) = str
    Country(Index) = ""
    team(Index) = ""
    If number(Index).Text = "" Then
    nam(Index).Text = ""
    team(Index).Text = ""
    End If
    End Sub
    Also converting into HTML.

    Thanks for the pieces of code
    Attached Images Attached Images  
    Last edited by Bert Willekens; May 31st, 2010 at 06:24 AM.
    Bert Willekens,

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)