excel - VBA timer gives 0s for everything -


i have timer calculates differences in execution times between data types performing same calculation.

here macro:

public declare function gettickcount lib "kernel32.dll" () long sub function1_var_randnumcounter()  dim var_randnum_x variant, var_randnum_y variant, count variant  count = 1 count = 1000000000     var_randnum_x = rnd(now) ' rnd vals based on now, built-in vba property     var_randnum_y = rnd(now) next count  select case isnull("a2")     case true         cells.clear         set target_sheet = activesheet         target_sheet.range("a2").value = -t     case false         set target_sheet = activesheet         target_sheet.range("a2").value = -t end select  'msgbox gettickcount - t, , "milliseconds" call function1_dec_randnumcounter  end sub sub function1_dec_randnumcounter()  dim count, var_randnum_x, dec_randnum_x, var_randnum_y, dec_randnum_y  dec_randnum_x = cdec(var_randnum_x) dec_randnum_y = cdec(var_randnum_y) ' convert these vals decimals  count = 1 count = 1000000000     dec_randnum_x = rnd(now) ' rnd vals based on now, built-in vba property     dec_randnum_y = rnd(now) next count  select case isnull("b2")     case true         cells.clear         set target_sheet = activesheet         target_sheet.range("b2").value = -t     case false         set target_sheet = activesheet         target_sheet.range("b2").value = -t     end select  'msgbox gettickcount - t, , "milliseconds" call function1_int_randnumcounter  end sub sub function1_int_randnumcounter()  dim count, int_randnum_x, int_randnum_y  count = 1 count = 1000000000     int_randnum_x = rnd(now)     int_randnum_y = rnd(now) next count  select case isnull("c2")     case true         cells.clear         set target_sheet = activesheet         target_sheet.range("c2").value = -t     case false         set target_sheet = activesheet         target_sheet.range("c2").value = -t end select  'msgbox gettickcount - t, , "milliseconds"  call function1_double_randnumcounter  end sub sub function1_double_randnumcounter()  dim count, dbl_randnum_x, dbl_randnum_y  count = 1 count = 1000000000     dbl_randnum_x = rnd(now)     int_randnum_y = rnd(now) next count  select case isnull("d2")     case true         cells.clear         set target_sheet = activesheet         target_sheet.range("d2").value = -t     case false         set target_sheet = activesheet         target_sheet.range("d2").value = -t end select  'msgbox gettickcount - t, , "milliseconds"  end sub sub function2_bargraph() 'put of these vals in 2d bar graph end sub 

when run given 0s values everything. when increase decimal place count time 0.00000s. should this?

two things:

  1. variables in vb not typed (are variant) unless declare them specific type clause.

    dim count long, int_randnum_x integer, int_randnum_y integer 

as must used each variable, statement below declare int_randnum_y integer, leaing int_randnum_x variant:

    dim count long, int_randnum_x, int_randnum_y integer 
  1. you never assign value 't'. declared in msgbox call. should declare

    dim t double  

early in routine, , assign current time

   t = timer 

then later can elapsed time in seconds

   t = timer - t 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -