I need to optimize my code.

Get help on programming - C++, Java, Delphi, etc.
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

I need to optimize my code.

Post by SBSP »

Hey people.

We have these Biometric finger scanners here at
work, and it is also used as a time and attendance system.

mainly to check for the occasional late comers.

I wrote a query to query this systems, database (Simple access database)
the database resides on a shared drive and my excel sheet template connect to this database
then queries and gets the first login for the day per user.
first col has the user second the date third col the time

Every thing works fine, But it only shows the users in the log , so if a user did not log in
it means that his or her log wont show late or on time.

So I wrote the below to match the logged users and map it to a textfile that has all the users
per line in a normal .txt file that also resides on a network drive next to the database.

it opens it opens the file and loops thought the logged in users and finds users that is not in the list.
skips to the last line of the excel sheet and adds 3 lines for some space and readability then
list the users that has not logged in for the day per line.

The below code works fine, but is slow as.
It basically scans all lines per user there a many users so, the code is slow.
I would like to optimize it abit, by stepping the "For loop" to read not only one at a time.

I could probably make it read lets say 2 at a time but then if the number of users that
logged in are an "Sorry don't know the word" "One ewige getal" then it will cause to loop to
go crazy.

I'm no programmer I only code when I need it for my self to make life easier.
So please excuse the bad naming and coding practice

Once all this is done it gets mailed to management.

BTW i also use this code for something else as well, with more than 40 000
sometimes i have to find a few mappings not in the list like maybe 5000 or so.
so edit file search wont cut.


Here is the code.

Code: Select all

Dim LineCount As Long
Dim LastLine As Long
Dim NameCount As Long
Dim Username As String

Dim UserInList As Boolean

Dim UserNewLineCount As Long



Sub Main()
 
LineCount = 0
Do: DoEvents
LineCount = LineCount + 1
If Sheet1.Cells(LineCount, 7) = "1" Then Exit Do
LastLine = LineCount
Loop
UserNewLineCount = LastLine + 5

Sheet1.Cells(LastLine + 4, 1) = "Users that has not loged in for the day"

NameCount = 0

Open "H:\TimeAttend\Users.txt" For Input As #1

Do: DoEvents
NameCount = NameCount + 1

Line Input #1, Username


If EOF(1) Then Exit Do

    LineCount = 0
    UserInList = False
    Do: DoEvents
    LineCount = LineCount + 1
    If Sheet1.Cells(LineCount, 7) = "1" Then Exit Do
    
    
   
        
        If Username = Sheet1.Cells(LineCount, 1) Then
        UserInList = True
        
        Exit Do
        Else
        UserInList = False
        End If
    Loop
   If UserInList = False Then
   
   UserNewLineCount = UserNewLineCount + 1
   If Len(Username) smaller than 3 Then
   UserNewLineCount = UserNewLineCount - 1
   Else
   Sheet1.Cells(UserNewLineCount, 1) = Username
   End If
   End If


Loop
MsgBox "Done"
Close #1

 Columns("A:A").Select
    With Selection.Font
        .Name = "Tahoma"
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = 1
    End With
    Selection.Font.Bold = False
    Selection.Font.Bold = True
    Range("C17").Select

End Sub




Where it sais [If Sheet1.Cells(LineCount, 7) = "1" Then Exit Do]
its the only way i could think of sopping the loop.

in Sheet1.Cells(LineCount, 7) col there is a 1, and it checks each line at col 7
if it finds 1 the loop ends.

When my querry reads the database it gets all data , once done it ads 1 to the next line.


Please help , ask if something is not clear.

Thanks



OMG do you know how much trouble i had to post the above code the little smaller than 3 sign prevented me from posting something about HTML tag not allowed

*Sigh*
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

Can any one remember how you calculate the left over amount.
when dividing.

Its commonly used when you write code to copy files so lets say
the file is 21 Bytes and block size is 2 [ 21 /2 ] = 10 reads + 1 which is the left over byte ?

There is a code command to calculate that in VB but for the life of it i cant remember.
If i have that i might solve the above
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

Can any one remember how you calculate the left over amount.
when dividing.
Use modulus. 21 mod 2 = 1
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

Hex_Rated wrote:
Can any one remember how you calculate the left over amount.
when dividing.
Use modulus. 21 mod 2 = 1

Dude!!! thats it!!!



now i dont have to go something like 21 /10 = 2 then 2 * 10 = 20 and 21 - 20 = 1
Anthro
Moderator Emeritus
Posts: 5547
Joined: 21 Dec 2002, 02:00
Processor: i7 3770k
Motherboard: ASUS P8P67-Pro
Graphics card: 2xNvidia GTX670
Memory: 16 GB Gskill Sniper
Location: In SQL Space inserting 'null' on purpose
Contact:

Post by Anthro »

You have a typo:
"Users that has not loged<<<logged>>> in for the day"

And that is as much as i understand about the code you just entered
Last edited by Anthro on 10 Jan 2007, 13:11, edited 1 time in total.
Temporary Absence
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

Anthropoid wrote:You have a typo:
"Users that has not loged<<<logged>>> in for the day"

And that is as much as i understad about the code you just entered
Thanks Dude!
Anthro
Moderator Emeritus
Posts: 5547
Joined: 21 Dec 2002, 02:00
Processor: i7 3770k
Motherboard: ASUS P8P67-Pro
Graphics card: 2xNvidia GTX670
Memory: 16 GB Gskill Sniper
Location: In SQL Space inserting 'null' on purpose
Contact:

Post by Anthro »

:bigups:
Temporary Absence
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

i try and i try, but the first and most important step is "do this in anything other than VB.".. :P

your problem hints at poor normalisation....
Most people would sooner die than think; in fact, they do so - Bertrand Russel
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

rustypup wrote:i try and i try, but the first and most important step is "do this in anything other than VB.".. :P

your problem hints at poor normalisation....
Correctamundo bleep
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

like i said i'm not a programmer.

I cant code in any other language but VB,

I can go

#include <iostream.h>

void Main()
cout >> "Hello World" ,ENDL;

Return 0;

or something like that

and thats about it.
Anthro
Moderator Emeritus
Posts: 5547
Joined: 21 Dec 2002, 02:00
Processor: i7 3770k
Motherboard: ASUS P8P67-Pro
Graphics card: 2xNvidia GTX670
Memory: 16 GB Gskill Sniper
Location: In SQL Space inserting 'null' on purpose
Contact:

Post by Anthro »

My head now hurts. . . .
Please stop now please ?
Temporary Absence
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

SBSP wrote:like i said i'm not a programmer.

I cant code in any other language but VB,

I can go

#include <iostream.h>

void Main()
cout >> "Hello World" ,ENDL;

Return 0;

or something like that

and thats about it.


Wont compile

Code: Select all


#include <iostream.h>

void main() {
    cout << "Hello World", ENDL;    
}
Last edited by RuadRauFlessa on 10 Jan 2007, 13:44, edited 1 time in total.
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

RuadRauFlessa wrote:
SBSP wrote:like i said i'm not a programmer.

I cant code in any other language but VB,

I can go

#include <iostream.h>

void Main()
cout >> "Hello World" ,ENDL;

Return 0;

or something like that

and thats about it.
Wont compile
Ok What ever
#include <iostream>

int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

:lol: that be a tad better though void also works depending on the compiler you are using but then you cannor "return 0"
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

I stick with VB cuz i dont want to go through the ***** rig and learn again.

Programming is not in my line.
:lol:
JavaMan
Registered User
Posts: 4
Joined: 02 Aug 2005, 02:00

Post by JavaMan »

Could you post the table and column names of all the tables in your database?

You can probably do the entire job by simply using one query. I would need to see the table and column names though. 8)
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

JavaMan Welcome to the forums.
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

SBSP wrote:I stick with VB cuz i dont want to go through the ***** rig and learn again.

Programming is not in my line.
:lol:


Haahahahahahahahaa!!!!!!!!!!!!

I was typing the whole rig made a type mistake instead i typed Wh0re
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

JavaMan wrote:Could you post the table and column names of all the tables in your database?

You can probably do the entire job by simply using one query. I would need to see the table and column names though. 8)
Thanks your first post is an offer to help me.

I'm impressed!
JavaMan
Registered User
Posts: 4
Joined: 02 Aug 2005, 02:00

Post by JavaMan »

Huh :?:
rudy
Registered User
Posts: 1
Joined: 10 Jan 2007, 02:00

floorplan 3d password

Post by rudy »

please help with password for floorplan 3d in mag
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

JavaMan wrote:Huh :?:
Your post count as in Posts the amount of posts youve posted on this forum.

of "Messages sent" normally people do the whole "Hi i'm so and so" thing

you dont understand? u sure you can help java man
i'm now in doupt
:lol:
JavaMan
Registered User
Posts: 4
Joined: 02 Aug 2005, 02:00

Post by JavaMan »

Hi, I'm JavaMan. I'm a web developer by profession, i also specialize in data access logic (e.g. writing database queries).

Any thing else? 8O
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Post by RuadRauFlessa »

Well I figured as much as that since I can call myself all that as well
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: floorplan 3d password

Post by SBSP »

rudy wrote:please help with password for floorplan 3d in mag

Serial Key

in ascii 70 85 67 75 79 70 70 33
Locked