Results 1 to 10 of 10

Thread: VB6 and ini file (RESOLVED)

  1. #1

    Thread Starter
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Resolved VB6 and ini file (RESOLVED)

    heres what i have

    in ini file

    [email protected];
    [email protected];
    [email protected];

    my program opens and counts the number of entrys ive got

    <VBCODE>Private Sub cmdEmail_Click()
    '************* open emails from file***********
    Dim strEmailfile As String
    Dim intFreeFile As Integer
    Dim strEmails As String ' Read in

    strEmailfile = App.Path & "\emails.ini"
    'S:\Disaster Recovery\VB Program Backup\SBO Comm V1.7
    'MsgBox (strEmailfile)
    intFreeFile = FreeFile

    On Error GoTo FinishCheck
    Open strEmailfile For Input As #intFreeFile
    Do While Not EOF(intFreeFile)
    Line Input #intFreeFile, strEmails
    intEmailCount = intEmailCount + 1
    Loop
    Close #intFreeFile

    MsgBox ("Email Count = " & intEmailCount)

    FinishCheck:
    End Sub</VBCODE>

    i want to modify this so it checks the entrys and only allows one, (so no dupicates), unsure of the best way to do this, but please keep this simple, dont want to be adding components and references, or any databases

    ok thanks for your help in advance
    Last edited by Robbo; Mar 18th, 2005 at 05:34 AM.
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: VB6 and ini file

    check out the getprivateprofilestring and writeprivateprofilestring API's

  3. #3
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: VB6 and ini file

    I agree with the thought 'keep it simple'
    But you should also have the thought 'keep it clean'
    Don't handle messes, avoid them.
    I don't think you posted the code that writes to the file ?
    That is where we should prevent duplicates being written.
    Rob C

  4. #4
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: VB6 and ini file

    I reckon you should only be writing (and reading) INI files if you absolutely ABSOLUTELY have to.

    The registry is probably a better bet and my preference is to use XML.

  5. #5

    Thread Starter
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB6 and ini file

    the program at present only reads the file

    dont want to use API or XML, just need to simply read the address and count, just dont want duplicates like im getting at the min, any ideas?

    or code i could test even if it just says what line the double is at or, misses counting them, not sure what is best
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: VB6 and ini file

    Just make a reference to the microsoft scripting runtime and use that instead of the DOS based openfile etc that you are using at present. The scripting runtime is much more feature rich.

  7. #7
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: VB6 and ini file

    This won't be fast.
    As you read in each line, add it to a string.
    But before adding each line, do a test to see if already in the string.
    VB Code:
    1. If InStr(1,sBuilding,sCandidate)=0 then
    2.   Add to your count
    3.   Concatenate sCandidate onto end of sBuilding
    4. End If
    Rob C

  8. #8

    Thread Starter
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB6 and ini file

    Quote Originally Posted by RobCrombie
    This won't be fast.
    As you read in each line, add it to a string.
    But before adding each line, do a test to see if already in the string.
    VB Code:
    1. If InStr(1,sBuilding,sCandidate)=0 then
    2.   Add to your count
    3.   Concatenate sCandidate onto end of sBuilding
    4. End If
    cool that seem to work, on neex thing i need to do then is just flag up which ones are doubles, can i put a message box in there?

    have this

    VB Code:
    1. Open strEmailfile For Input As #intFreeFile
    2.   Do While Not EOF(intFreeFile)
    3.     Line Input #intFreeFile, strEmails
    4.    
    5.     If InStr(1, strTotalEmails, strEmails) = 0 Then
    6.     'Add to your count
    7.     'Concatenate sCandidate onto end of sBuilding
    8.         intEmailCount = intEmailCount + 1
    9.         strTotalEmails = strTotalEmails + strEmails
    10.     End If
    11.  
    12.   Loop
    13. Close #intFreeFile
    14.  
    15. MsgBox ("Email Count = " & intEmailCount)
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  9. #9
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: VB6 and ini file

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdEmail_Click()
    4. '************* open emails from file***********
    5.  Dim strEmailfile As String
    6.  Dim intFreeFile As Integer
    7.  Dim strEmails As String ' Read in
    8.  Dim strTotalEmails As String
    9.  Dim strDuplicates As String
    10.  Dim intEmailCount As Integer
    11.  
    12.   strEmailfile = App.Path & "\emails.ini"
    13.   'S:\Disaster Recovery\VB Program Backup\SBO Comm V1.7
    14.   'MsgBox (strEmailfile)
    15.   intFreeFile = FreeFile
    16.  
    17.   On Error GoTo FinishCheck
    18.   Open strEmailfile For Input As #intFreeFile
    19.   Do While Not EOF(intFreeFile)
    20.     Line Input #intFreeFile, strEmails
    21.    
    22.     If InStr(1, strTotalEmails, strEmails) = 0 Then
    23.     'Add to your count
    24.     'Concatenate sCandidate onto end of sBuilding
    25.         intEmailCount = intEmailCount + 1
    26.         strTotalEmails = strTotalEmails & strEmails
    27.     Else
    28.       strDuplicates = strDuplicates & vbCrLf & strEmails
    29.     End If
    30.  
    31.   Loop
    32.   Close #intFreeFile
    33.  
    34.   MsgBox ("Email Count = " & intEmailCount)
    35.   If Len(strDuplicates) > 0 Then
    36.     MsgBox strDuplicates, , " THESE WERE DUPLICATED"
    37.   End If
    38. FinishCheck:
    39. End Sub
    Hope that does the job.
    I'm off to bed now (it's 4:08 AM)
    Rob C

  10. #10

    Thread Starter
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Resolved Re: VB6 and ini file

    ok thats works ok with a bit of jiging thats just what i want cheers
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

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