none
Equivalent code vb6 to vb.net 2010 ? RRS feed

  • Question

  • The following code is used to change the system time in vb6 .

    Date = "12/18/2013"
    Time = "13:39:11"

    Now, what is the equivalent command in vb.net 2010 ?

    Thank you .


    Wednesday, December 18, 2013 7:49 AM

Answers

  • Hello,

    In vb.net, we use kernel32.dll to change the system time like below:

    Imports System.Runtime.InteropServices
    
    
    Module Module1
    
    
        Sub Main()
    
            SetDeviceTime()
    
        End Sub
    
    
        <StructLayoutAttribute(LayoutKind.Sequential)> _
    
        Private Structure SYSTEMTIME
    
            Public year As Short
    
            Public month As Short
    
            Public dayOfWeek As Short
    
            Public day As Short
    
            Public hour As Short
    
            Public minute As Short
    
            Public second As Short
    
            Public milliseconds As Short
    
        End Structure
    
    
        <DllImport("kernel32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _
    
        Private Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
    
    
        End Function
    
        Public Sub SetDeviceTime()
    
            'Populate structure...
    
            'Substitute <your date="" object=""> with your date object returned via GPRS...
    
    
            Dim st As SYSTEMTIME
    
            st.year = 2014
    
            st.month = 1
    
            st.dayOfWeek = 1
    
            st.day = 1
    
            st.hour = 0
    
            st.minute = 0
    
            st.second = 0
    
            st.milliseconds = 0
    
    
            'Set the new time...
    
            Dim bool As Boolean = False
    
    
            bool = SetLocalTime(st)
    
    
            If bool = True Then
    
    
            End If
    
        End Sub
    
    
    End Module
    

    For details, please refer to link below:

    http://social.msdn.microsoft.com/Forums/en-US/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a/change-system-time-using-vbnet?forum=vblanguage

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 19, 2013 9:32 AM
    Moderator