|
-
Mar 17th, 2005, 10:30 AM
#1
Thread Starter
Frenzied Member
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
-
Mar 17th, 2005, 10:40 AM
#2
Fanatic Member
Re: VB6 and ini file
check out the getprivateprofilestring and writeprivateprofilestring API's
-
Mar 17th, 2005, 10:44 AM
#3
Fanatic Member
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.
-
Mar 17th, 2005, 10:46 AM
#4
Frenzied Member
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.
-
Mar 17th, 2005, 11:10 AM
#5
Thread Starter
Frenzied Member
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
-
Mar 17th, 2005, 11:15 AM
#6
Fanatic Member
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.
-
Mar 17th, 2005, 11:20 AM
#7
Fanatic Member
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:
If InStr(1,sBuilding,sCandidate)=0 then
Add to your count
Concatenate sCandidate onto end of sBuilding
End If
-
Mar 17th, 2005, 11:56 AM
#8
Thread Starter
Frenzied Member
Re: VB6 and ini file
 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:
If InStr(1,sBuilding,sCandidate)=0 then
Add to your count
Concatenate sCandidate onto end of sBuilding
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:
Open strEmailfile For Input As #intFreeFile
Do While Not EOF(intFreeFile)
Line Input #intFreeFile, strEmails
If InStr(1, strTotalEmails, strEmails) = 0 Then
'Add to your count
'Concatenate sCandidate onto end of sBuilding
intEmailCount = intEmailCount + 1
strTotalEmails = strTotalEmails + strEmails
End If
Loop
Close #intFreeFile
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
-
Mar 17th, 2005, 12:08 PM
#9
Fanatic Member
Re: VB6 and ini file
VB Code:
Option Explicit
Private Sub cmdEmail_Click()
'************* open emails from file***********
Dim strEmailfile As String
Dim intFreeFile As Integer
Dim strEmails As String ' Read in
Dim strTotalEmails As String
Dim strDuplicates As String
Dim intEmailCount As Integer
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
If InStr(1, strTotalEmails, strEmails) = 0 Then
'Add to your count
'Concatenate sCandidate onto end of sBuilding
intEmailCount = intEmailCount + 1
strTotalEmails = strTotalEmails & strEmails
Else
strDuplicates = strDuplicates & vbCrLf & strEmails
End If
Loop
Close #intFreeFile
MsgBox ("Email Count = " & intEmailCount)
If Len(strDuplicates) > 0 Then
MsgBox strDuplicates, , " THESE WERE DUPLICATED"
End If
FinishCheck:
End Sub
Hope that does the job.
I'm off to bed now (it's 4:08 AM)
-
Mar 18th, 2005, 05:05 AM
#10
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|