<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Open Script Solution &#187; VB6</title>
	<atom:link href="http://www.openscriptsolution.com/category/vb6/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.openscriptsolution.com</link>
	<description>... where solutions for script programming are found ...</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:48:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Get Data from Excel Worksheet Using VB6</title>
		<link>http://www.openscriptsolution.com/2009/09/02/how-to-get-data-from-excel-worksheet-using-vb6/</link>
		<comments>http://www.openscriptsolution.com/2009/09/02/how-to-get-data-from-excel-worksheet-using-vb6/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 07:09:02 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Excel File]]></category>
		<category><![CDATA[ambil]]></category>
		<category><![CDATA[baca]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[retrieve]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=181</guid>
		<description><![CDATA[You can read and retrieve data from Microsoft Excel Worksheet easily by using your application that you made by Visual Basic 6 (VB6) programming. Simply just using its Microsoft Excel Object Library reference provided by VB6. The following code will show you how we can do that step by step. Started from how we can [...]]]></description>
			<content:encoded><![CDATA[<p>You can read and retrieve data from Microsoft Excel Worksheet easily by using your application that you made by Visual Basic 6 (VB6) programming. Simply just using its Microsoft Excel Object Library reference provided by VB6. The following code will show you how we can do that step by step. Started from how we can prepare the Excel object, get or create the Excel object, opening the Excel file, opening the Excel worksheet, accessing (read and displaying) the data from Excel file, closing the Excel worksheet, closing the Excel file, until cleaning-up the memory used by the Excel object. This is very very important for you, since almost our data stored in Microsoft Excel file, and not always in the database. <span id="more-181"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'Description: Read and get data from an Excel worksheet and 
</span><span style="color: #008000;">'             display it from the first row until the fifth row
</span><span style="color: #008000;">'             by using a MsgBox in Visual Basic 6.
</span><span style="color: #008000;">'             Including the technique how you should access Excel 
</span><span style="color: #008000;">'             step by step properly, from opening the Excel file until
</span><span style="color: #008000;">'             close and clear the memory that used by Excel object.
</span><span style="color: #008000;">'Author     : Masino Sinaga
</span><span style="color: #008000;">'Date       : Sunday, August 2, 2009
</span><span style="color: #008000;">'Preparation: 1. Create a new Standard exe project with 1 form
</span><span style="color: #008000;">'             2. Add 1 CommandButton control on the Form1
</span><span style="color: #008000;">'             3. Add an item &quot;Microsoft Excel X.X Object Library&quot;
</span><span style="color: #008000;">'                from menu Project -&gt; References... . X.X depends on
</span><span style="color: #008000;">'                version Excel or Microsoft Office you are using.
</span><span style="color: #008000;">'                When I tried this code, it had been installed 
</span><span style="color: #008000;">'                Microsoft Office 2000 and Microsoft Office 2007,
</span><span style="color: #008000;">'                thus, X.X above is equal with 12.0 which VB6
</span><span style="color: #008000;">'                displaying only the last version object library Excel. 
</span><span style="color: #008000;">'                In this case, Microsoft Excel 12.0 Object Library 
</span><span style="color: #008000;">'             4. Ensure your Dataku.xls file already exists in the same
</span><span style="color: #008000;">'                directory where your application located, and in
</span><span style="color: #008000;">'                column B started from the first row until the fifth row
</span><span style="color: #008000;">'                you already have value in it.
</span><span style="color: #008000;">'             5. Copy the following code to the Form1 editor.
</span><span style="color: #008000;">'------------------------------------------------------------------
</span>
<span style="color: #000080;">Dim</span> Excel <span style="color: #000080;">As</span> Excel.Application <span style="color: #008000;">'Excel Application
</span><span style="color: #000080;">Dim</span> ExcelWBk <span style="color: #000080;">As</span> Excel.Workbook <span style="color: #008000;">'Excel Workbook
</span><span style="color: #000080;">Dim</span> ExcelWS <span style="color: #000080;">As</span> Excel.Worksheet <span style="color: #008000;">'Excel Worksheet
</span>
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Command1_Click()
  <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">GoTo</span> Err
  <span style="color: #008000;">'Inisialitation Excel object
</span>  StartExcel
  <span style="color: #008000;">'Open Dataku.xls file that located in the same directory
</span>  <span style="color: #008000;">'where your application located.
</span>  <span style="color: #000080;">Set</span> ExcelWBk = Excel.Workbooks.<span style="color: #000080;">Open</span>(App.Path &amp; <span style="color: #800000;">&quot;\Dataku.xls&quot;</span>)
  <span style="color: #008000;">'Displaying its status on the form
</span>  <span style="color: #000080;">Print</span> <span style="color: #800000;">&quot;Successfully open file ...&quot;</span>
  <span style="color: #008000;">'Access the first Worksheet (1)
</span>  <span style="color: #008000;">'If you want to switch to the second Worksheet, then
</span>  <span style="color: #008000;">'simply replace (1) with (2), and so forth...
</span>  <span style="color: #000080;">Set</span> ExcelWS = ExcelWBk.Worksheets(1)
  <span style="color: #008000;">'Displaying its status on the form
</span>  <span style="color: #000080;">Print</span> <span style="color: #800000;">&quot;Successfully read Worksheet Sheet1 ...&quot;</span>
  <span style="color: #008000;">'Processing the ExcelWS variable
</span>  <span style="color: #000080;">With</span> ExcelWS
    <span style="color: #000080;">Dim</span> i <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
    <span style="color: #000080;">Dim</span> strData <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
    <span style="color: #008000;">'Read from the first row until the fifth row
</span>    <span style="color: #000080;">For</span> i = 1 <span style="color: #000080;">To</span> 5
      <span style="color: #008000;">'Assign to a variabel
</span>      strData = strData &amp; .Cells(i, 2) &amp; vbCrLf
    <span style="color: #000080;">Next</span> i
  <span style="color: #000080;">End</span> <span style="color: #000080;">With</span>
  <span style="color: #008000;">'Displaying the data to MsgBox
</span>  MsgBox strData
  <span style="color: #008000;">'After finished, don't forget to close the worksheet
</span>  CloseWorkSheet
  <span style="color: #008000;">'Displaying its status on the form
</span>  <span style="color: #000080;">Print</span> <span style="color: #800000;">&quot;Successfully close worksheet and Excel file ...&quot;</span>
  <span style="color: #008000;">'Don' forget neither, always clean-up the memory that
</span>  <span style="color: #008000;">'has just been used by Excel object
</span>  ClearExcelMemory
  <span style="color: #008000;">'Displaying its status on the form
</span>  <span style="color: #000080;">Print</span> <span style="color: #800000;">&quot;Successfully clean-up the memory used by Excel ...&quot;</span>
  <span style="color: #008000;">'Displaying the message
</span>  MsgBox <span style="color: #800000;">&quot;Finish, that's all folks ...!&quot;</span>, vbInformation, <span style="color: #800000;">&quot;Good&quot;</span>
  <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
Err:
  <span style="color: #008000;">'CloseWorkSheet
</span>  <span style="color: #008000;">'When error occured, don't forget to clean-up the memory
</span>  ClearExcelMemory
  MsgBox Err.Description, vbCritical, <span style="color: #800000;">&quot;Error Occured&quot;</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> StartExcel()
  <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">GoTo</span> Err:
  <span style="color: #008000;">'First of all, get the Excel object, and if error occured
</span>  <span style="color: #008000;">'jumpt to the Err label on the bottom of this Sub,
</span>  <span style="color: #008000;">'then create the Excel object. Typically, error occured here
</span>  <span style="color: #008000;">'if the Excel object has not been created, yet
</span>  <span style="color: #000080;">Set</span> Excel = GetObject(, <span style="color: #800000;">&quot;Excel.Application&quot;</span>)
  <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
Err:
  <span style="color: #008000;">'Create an Excel object if it does not exist.
</span>  <span style="color: #000080;">Set</span> Excel = CreateObject(<span style="color: #800000;">&quot;Excel.Application&quot;</span>)
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> CloseWorkSheet()
  <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
  <span style="color: #008000;">'Close the Excel workbook
</span>  ExcelWBk.<span style="color: #000080;">Close</span>
  <span style="color: #008000;">'Quit from Excel application
</span>  Excel.Quit
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> ClearExcelMemory()
  <span style="color: #008000;">'Clean-up the memory, check first, whether
</span>  <span style="color: #008000;">'the Excel object exists or not in the memory ...
</span>  <span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> ExcelWS <span style="color: #000080;">Is</span> <span style="color: #000080;">Nothing</span> <span style="color: #000080;">Then</span> <span style="color: #000080;">Set</span> ExcelWS = <span style="color: #000080;">Nothing</span>
  <span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> ExcelWBk <span style="color: #000080;">Is</span> <span style="color: #000080;">Nothing</span> <span style="color: #000080;">Then</span> <span style="color: #000080;">Set</span> ExcelWBk = <span style="color: #000080;">Nothing</span>
  <span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> Excel <span style="color: #000080;">Is</span> <span style="color: #000080;">Nothing</span> <span style="color: #000080;">Then</span> <span style="color: #000080;">Set</span> Excel = <span style="color: #000080;">Nothing</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p>Do not forget to always cleaning-up the memory used by your Excel object. If you do not handle this, then you can not open your Excel file, until you have to first clear the memory used by your Excel object by pressing <strong>End Task</strong> button in the <strong>Task Manager</strong> dialogue box.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.openscriptsolution.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.openscriptsolution.com/2009/09/02/how-to-get-data-from-excel-worksheet-using-vb6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Calculate Difference Between Two Dates Using VB6</title>
		<link>http://www.openscriptsolution.com/2009/09/01/how-to-calculate-difference-between-two-dates-using-vb6/</link>
		<comments>http://www.openscriptsolution.com/2009/09/01/how-to-calculate-difference-between-two-dates-using-vb6/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 13:38:35 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Date and Time]]></category>
		<category><![CDATA[between]]></category>
		<category><![CDATA[calculate]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[dates]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[hitung]]></category>
		<category><![CDATA[selisih]]></category>
		<category><![CDATA[tanggal]]></category>
		<category><![CDATA[two]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=175</guid>
		<description><![CDATA[This following code will show you how to calculate difference between two dates by using Visual Basic 6. The calculation result will give you an output that contains of the difference between those two dates in format: Days, Hours:Minutes:Seconds. The both dates must be in complete format. For example: the first date is March 1, [...]]]></description>
			<content:encoded><![CDATA[<p>This following code will show you how to calculate difference between two dates by using Visual Basic 6. The calculation result will give you an output that contains of the difference between those two dates in format: <strong>Days, Hours:Minutes:Seconds</strong>. The both dates must be in complete format. For example: the first date is March 1, 2002 17:18:00, and the second date is September 1, 2002 09:42:30. After being calculated, then the output will give you the result as follow: 183 day(s), 16:24:30. It means: The difference between those two dates is: 183 days, 16 hours, 24 minutes, and 30 seconds.<span id="more-175"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'Description: Calculate difference between 2 particular dates 
</span><span style="color: #008000;">'             and show the result in format: day(s), hr:min:sec
</span><span style="color: #008000;">'             For example: 
</span><span style="color: #008000;">'             The first date  = 01/03/2002 17:18:00 and 
</span><span style="color: #008000;">'             The second date = 01/09/2002 09:42:30, then
</span><span style="color: #008000;">'             the result will output --&gt; 183 day(s), 16:24:30 
</span><span style="color: #008000;">'             (183 days, 16 hours, 24 minutes, and 30 seconds).
</span><span style="color: #008000;">'             You can use the DateDiff function belongs to VB6
</span><span style="color: #008000;">'Author     : Masino Sinaga 
</span><span style="color: #008000;">'Created    : Sunday, September 1, 2002
</span><span style="color: #008000;">'Preparation: 1. Create a new standar exe project with 1 Form.
</span><span style="color: #008000;">'             2. Add controls: 2 TextBoxes, 1 Label, and 1 Timer.
</span><span style="color: #008000;">'             3. Copy this following code to the form editor form.
</span><span style="color: #008000;">'-------------------------------------------------------------------
</span>
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Function</span> CalcDiff2Dates(<span style="color: #000080;">ByVal</span> d1 <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span>, _
                        <span style="color: #000080;">ByVal</span> d2 <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
  <span style="color: #000080;">Dim</span> Second <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, Day <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, Hour <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
  <span style="color: #000080;">Dim</span> CompleteHour <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
&nbsp;
  <span style="color: #000080;">If</span> d1 &gt; d2 <span style="color: #000080;">Then</span>
     MsgBox <span style="color: #800000;">&quot;The first date must be lower than &quot;</span> &amp; _
            <span style="color: #800000;">&quot;the second date!&quot;</span>, _
            vbCritical, <span style="color: #800000;">&quot;Warning&quot;</span>
     <span style="color: #000080;">Exit</span> <span style="color: #000080;">Function</span>
  <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
  <span style="color: #008000;">'Count the difference in seconds
</span>  Second = DateDiff(<span style="color: #800000;">&quot;s&quot;</span>, d1, d2)
&nbsp;
  <span style="color: #008000;">'Calculate the hour by dividing with 3600
</span>  <span style="color: #008000;">'(backslash (&quot;\&quot;) in order to get the Integer
</span>  <span style="color: #008000;">'without decimal value)
</span>  Hour = Second \ 3600
&nbsp;
  <span style="color: #008000;">'If hour greater than 23
</span>  <span style="color: #008000;">'it means: more than 1 day
</span>  <span style="color: #000080;">If</span> Hour &gt; 23 <span style="color: #000080;">Then</span>
&nbsp;
     <span style="color: #008000;">'Calculate day by dividing with 24
</span>     <span style="color: #008000;">'(backslash (&quot;\&quot;) in order to get the Integer
</span>     <span style="color: #008000;">'value without decimal value)
</span>     Day = Hour \ 24
&nbsp;
     <span style="color: #008000;">'Calculate the hour duration in hh:mm:ss
</span>     CompleteHour = Format((d2 - d1), <span style="color: #800000;">&quot;hh:mm:ss&quot;</span>)
&nbsp;
  <span style="color: #000080;">Else</span> <span style="color: #008000;">'If the hour less than or equal with 23      
</span>
     Day = 0   <span style="color: #008000;">'assign the Day with zero value      
</span>
     <span style="color: #008000;">'Calculate hour duration in hh:mm:ss
</span>     CompleteHour = Format((d2 - d1), <span style="color: #800000;">&quot;hh:mm:ss&quot;</span>)
&nbsp;
  <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>  
&nbsp;
  <span style="color: #000080;">If</span> Day = 0 <span style="color: #000080;">Then</span>  <span style="color: #008000;">'If less than 1 day
</span>
     <span style="color: #008000;">'Get the final result
</span>     CalcDiff2Dates = CompleteHour
&nbsp;
  <span style="color: #000080;">Else</span>  <span style="color: #008000;">'If day greater than 0, show the day duration     
</span>
     <span style="color: #008000;">'Get the final result
</span>     CalcDiff2Dates = Day &amp; <span style="color: #800000;">&quot; day(s), &quot;</span> &amp; CompleteHour
&nbsp;
  <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
  <span style="color: #000080;">Exit</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Form_Load()
  Timer1.Interval = 500
  Timer1.Enabled = <span style="color: #000080;">True</span>
  Text1.Text = <span style="color: #800000;">&quot;01/03/2002 17:18:00&quot;</span>
  <span style="color: #008000;">'Text2.Text = &quot;01/09/2002 09:42:30&quot;
</span>  Text2.Text = Now
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Timer1_Timer()
  <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">GoTo</span> ErrHandler
  Text2.Text = Now
  Label1.Caption = CalcDiff2Dates(<span style="color: #000080;">CDate</span>(Text1.Text), _
                      <span style="color: #000080;">CDate</span>(Text2.Text))
  <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
ErrHandler:
  MsgBox <span style="color: #800000;">&quot;Invalid date or format!&quot;</span>, _
         vbCritical, <span style="color: #800000;">&quot;Error Date&quot;</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p>From the code above, the first parameter belongs to the <strong>CalcDiff2Dates</strong> function placed on Text1 control, whereas the second parameter placed on Text2 which its value being generated by Timer1 control using time interval one second. </p>
<p>The result being shown at Label1 control based the changes generated by Timer1 control. Of course, you may modify that code above by yourself. For example, by removing the Timer control and disable the Timer code, and then simply use the <strong>CalcDiff2Dates</strong> function only in Form_Load procedure.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.openscriptsolution.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.openscriptsolution.com/2009/09/01/how-to-calculate-difference-between-two-dates-using-vb6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Convert 10 Digits Numeral to The Date Value?</title>
		<link>http://www.openscriptsolution.com/2009/08/29/how-to-convert-10-digits-numeral-to-the-date-value/</link>
		<comments>http://www.openscriptsolution.com/2009/08/29/how-to-convert-10-digits-numeral-to-the-date-value/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 11:17:29 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Date and Time]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[digits]]></category>
		<category><![CDATA[numeral]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=137</guid>
		<description><![CDATA[I have hundreds of records that need to be imported from one table and database (let&#8217;s say that this is the first database) to another table in different database (and the last one is the second database). Unfortunately, one of the columns in the table in first database has the Date value in 10 digits [...]]]></description>
			<content:encoded><![CDATA[<p>I have hundreds of records that need to be imported from one table and database (let&#8217;s say that this is the first database) to another table in different database (and the last one is the second database). Unfortunately, one of the columns in the table in first database has the Date value in 10 digits numeral format. For example: <strong>1206980969</strong>. Actually, this value equals with <strong>March 31, 2008 16:29:29 on UTC</strong>. Then, how do I convert that 10 digits numeral to the Data value since the column in the second database is a Date field type? And how do I convert again that date according to my local time?  <span id="more-137"></span></p>
<p>Okay. Here is the solution that I made from Visual Basic 6. First of all, you should create a new function for this.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> GetTimeZoneInformation <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;KERNEL32.dll&quot;</span> (lpTimeZoneInformation <span style="color: #000080;">As</span> TIME_ZONE_INFORMATION) <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Type</span> SYSTEMTIME
   wYear                <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wMonth               <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wDayOfWeek           <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wDay                 <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wHour                <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wMinute              <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wSecond              <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
   wMilliseconds        <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Type</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Type</span> TIME_ZONE_INFORMATION
   Bias                 <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
   StandardName         <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> * 64
   StandardDate         <span style="color: #000080;">As</span> SYSTEMTIME
   StandardBias         <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
   DaylightName         <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> * 64
   DaylightDate         <span style="color: #000080;">As</span> SYSTEMTIME
   DaylightBias         <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Type</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Const</span> TIME_ZONE_ID_DAYLIGHT <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 2
<span style="color: #000080;">Private</span> <span style="color: #000080;">Const</span> Unix1970   <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 25569 <span style="color: #008000;">'CDbl(DateSerial(1970, 1, 1))
</span>
<span style="color: #000080;">Public</span> <span style="color: #000080;">Function</span> Unix2Date(vUnixDate <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByVal</span> bReturnUTC <span style="color: #000080;">As</span> <span style="color: #000080;">Boolean</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span>
   Unix2Date = DateAdd(<span style="color: #800000;">&quot;s&quot;</span>, vUnixDate, Unix1970) - IIf(bReturnUTC, 0, GetCurrentTZOffset)
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">Public</span> <span style="color: #000080;">Function</span> GetCurrentTZOffset() <span style="color: #000080;">As</span> <span style="color: #000080;">Double</span>
   <span style="color: #000080;">Dim</span> tz               <span style="color: #000080;">As</span> TIME_ZONE_INFORMATION
   <span style="color: #000080;">Dim</span> lRet             <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>
   <span style="color: #008000;">'Quickest way to see if we are in
</span>   <span style="color: #008000;">'Daylight savings is to check lRet
</span>   lRet = GetTimeZoneInformation(tz)
   <span style="color: #008000;">'Offset in minutes
</span>   GetCurrentTZOffset = tz.Bias + IIf(lRet = TIME_ZONE_ID_DAYLIGHT, tz.DaylightBias, tz.StandardBias)
   GetCurrentTZOffset = GetCurrentTZOffset / 1440
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Command1_Click()
   MsgBox <span style="color: #800000;">&quot;UTC   = &quot;</span> &amp; Unix2Date(1206980969, <span style="color: #000080;">True</span>) <span style="color: #008000;">'March 31, 2008 16:29:29 (UTC)
</span>   MsgBox <span style="color: #800000;">&quot;Local = &quot;</span> &amp; Unix2Date(1206980969, <span style="color: #000080;">False</span>) <span style="color: #008000;">'March 31, 2008 23:29:29 (UTC + 7)
</span><span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p>From the code above, the conclusion is: We can use the Unix2Date function which has two parameters in it. The first parameter is the 10 digits numeral value, and the second parameter is the flag whether you want to convert it to UTC or to your local time. If we want to convert it to UTC, then the second parameter value is <strong>True</strong>, whereas if we want to convert it to the local time (in this case I have UTC + 7), the second parameter value is <strong>False</strong>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.openscriptsolution.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.openscriptsolution.com/2009/08/29/how-to-convert-10-digits-numeral-to-the-date-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Convert 5 Digits Numeral to The Date Value?</title>
		<link>http://www.openscriptsolution.com/2009/08/28/how-to-convert-5-digits-numeral-to-the-date-value/</link>
		<comments>http://www.openscriptsolution.com/2009/08/28/how-to-convert-5-digits-numeral-to-the-date-value/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 02:48:01 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Date and Time]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[digits]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[Macro]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=125</guid>
		<description><![CDATA[A few days ago, a friend of mine asked me for help. He wanted to export his data from Excel file into Access database file. There were about sixteen thousand rows in Excel that have to be exported into Access. One of the columns in that Excel had a Date data. Unfortunately, most of those [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, a friend of mine asked me for help. He wanted to export his data from Excel file into Access database file. There were about sixteen thousand rows in Excel that have to be exported into Access. One of the columns in that Excel had a Date data. Unfortunately, most of those rows have the 5 digits numeral data, and not in the real Date Value data. For example, there was a row with value <strong>&#8216;38353</strong>. As we know, this is not a valid Date, right? Besides that, there is a &#8216; character before the value itself. In this case, that value become a String and not a numeral value anymore. <span id="more-125"></span></p>
<p>If the data does not contain of the &#8216; character at beginning, it is so easy to convert them become Date value, by using Format Cells feature in Excel. Obviously, it took too long time if I have to remove first the &#8216; character for those thousand records, and then do formatting the cell column. Since the date have the &#8216; character, then it will take a long time to remove that character one by one. Even if you want to make the special function to remove this.</p>
<p>So, before I export all about those sixteen thousand rows, I analyzed, which one the best way to do this. Well, finally, I think it is better to convert first those 5 digits numeral data directly to the real Date Value data without having to remove the &#8216; character. I also have to convert this data become the Date format and order: <strong>year-month-date</strong>, such as &#8220;yyyy-MM-dd&#8221;. This &#8220;38353&#8243; value should be like <strong>2005-01-01</strong>. </p>
<p>Actually, the solution that I made for this, is only by using <strong>CDate()</strong> function belongs to VBA (Visual Basic Application) that exists in Excel file. Unfortunately, you cannot use formula <strong>=CDATE()</strong> function directly in the Excel WorkSheet Cell. So, I created this function below from Visual Basic Editor in the Excel file and run it from Macro Excel:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> <span style="color: #000080;">Function</span> ConvertDateStringToDateValue()
  <span style="color: #000080;">With</span> Sheet1
    <span style="color: #000080;">For</span> i = 2 <span style="color: #000080;">To</span> 16000 <span style="color: #008000;">'first row is the header column, so we start from the 2nd row
</span>      <span style="color: #000080;">If</span> IsDate(.Cells(i, 7)) <span style="color: #000080;">Then</span> <span style="color: #008000;">'check whether the Date value in the 7th column
</span>        <span style="color: #008000;">'among those 16,000 rows, not all rows contain of the DateString
</span>        <span style="color: #008000;">'so, if the Cell value is a real Date, do nothing here...
</span>      <span style="color: #000080;">Else</span> <span style="color: #008000;">'Else, if the cell value not a Date type
</span>        <span style="color: #008000;">'let's convert the Cell here, and put the result in to the 11th column
</span>        .Cells(i, 11).Value = Format(<span style="color: #000080;">CDate</span>(.Cells(i, 7).Value), <span style="color: #800000;">&quot;yyyy-MM-dd&quot;</span>)
      <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">Next</span> i
  <span style="color: #000080;">End</span> <span style="color: #000080;">With</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></td></tr></table></div>

<p>From the code above, we can see that the 5 digits numeral value located on the seventh column or column <strong>G</strong>, meanwhile the real Date Value I put on the eleventh column or column <strong>K</strong> in Excel file.</p>
<p>The conclusion? Well, the solution I made is by using <strong>CDate()</strong> and <strong>Format()</strong> function in Visual Basic Application (VBA) from Visual Basic editor belongs to the Excel file. We cannot use the Excel formula directly on the Sheet.  It took only moreless about a few seconds to convert the 5 digits numeral to the Date Value. Meanwhile, the export process itself from the Excel file into the Access database file took only a few seconds, too.  I just used the <strong>Get External Data</strong> from the Access database file from menu: &#8220;File -&gt; Get External Data -&gt; Import&#8230;&#8221;.</p>
<p>Thanks to the <strong>CDate()</strong> and <strong>Format()</strong> functions that available in VBA Excel, and also to the <strong>Get External Data</strong> feature that available in Microsoft Access.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.openscriptsolution.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.openscriptsolution.com/2009/08/28/how-to-convert-5-digits-numeral-to-the-date-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
