Help << operator VB. net

day (1-31)

Month (1-12)

Year(0-99)

Can you help me This code is wrong but is something like this i think.

Module Module1

Sub Main()

Dim MyDate As Integer

Console.WriteLine("enter day!")

MyDate = ((Console.ReadLine) << 3)

Console.WriteLine("enter month!")

MyDate = ((Console.ReadLine) << 6)

Console.WriteLine("enter year!")

MyDate = ((Console.ReadLine) << 0)

Console.WriteLine(MyDate)

End Sub

End Module




Answer this question

Help << operator VB. net

  • Sniper167

    I need to write date with left and right shift operators and I need to store direct day, month and year in MyDate.

  • FlyingSun

    try something like this:

    Sub Main()

    Dim day as integer, month as integer, year as integer

    Console.WriteLine("enter day!")

    day = cint(Console.ReadLine)

    Console.WriteLine("enter month!")

    month = cint(Console.ReadLine)

    Console.WriteLine("enter year!")

    year = cint(Console.ReadLine)

    Console.WriteLine("Date = " & day & "/" & month & "/" & year)

    End Sub

    why use a console program, who wants to type at the command-line create a GUI and the use the dateTimePicker control. much easier :)


  • Aaron Leiby

    Sub Main()
            dim myDate, temp as Integer 
            
            console.Write("unesite dan (1-31): ")
            myDate = console.ReadLine()    'vrijednost se pohranjuje
                            'direktno u varijablu
     
            myDate <<= 4
            console.Write("unesite mjesec (1-12): ")
            myDate = myDate Or console.ReadLine()
            
            myDate <<= 7
            console.Write("unesite godinu (0-99): ")
            myDate = myDate Or Console.ReadLine()
            
            console.WriteLine()
            
            console.WriteLine("dan je: {0}", myDate >> 11)
            
            temp = myDate >> 11
            temp <<= 11
            myDate = myDate and (not temp)
            console.WriteLine("mjesec je: {0}", myDate >> 7) 
            
            temp = myDate >> 7
            temp <<= 7
            myDate = myDate and (not temp)
            console.WriteLine("godina je: {0}",myDate)
            
            console.ReadLine()
        End Sub


  • morgan32

    The OP is trying to use the C++ iostream operators in Visual Basic. Sounds like a class assignment. Can't say much more but: "Hey Dude(tte), you're using the wrong language!"


  • R Suresh

     

    You aren't listening to people here. You use shift operators when THEY answer an application need.

    It does not seem as if you understand what they do and I'd recommend looking at the shift operator in help for a clearer understanding.

    You have not declated a datatype for mydate. Therefore, it's going to default to an integer with what you have written. The argument and the shift operators will tell the compiler to make it an integer. However an integer is a far, far less than optimal datatype to store date fields,

    You have to first understand what a shift operator does to decide to use it. I do not think you have found the application for them ...yet.

     

     



  • Akshay Saini

    I need to use >> and << for this program.

    Ok I now saw that I ask you a wrong question.

    The code is something like this...Can you now help me

    Test Date (07.03.2005)

    ***************************************************************************************

    Sub Main()

    Dim MyDate As Integer

    Console.WriteLine("Enter day!")

    MyDate = ((Console.ReadLine) << )

    Console.WriteLine("enter month!")

    MyDate = ((Console.ReadLine) << )

    Console.WriteLine("Enter year!")

    MyDate = ((Console.ReadLine) << )

    Console.WriteLine("The day is :{0}", MyDate >> )

    Console.WriteLine("The month is:{1}", MyDate >> )

    Console.WriteLine("The year is:{2}", MyDate >> )

    End Sub

    End Module



  • Amit Glazer

    It's very "wrong". << is for bit shifting.

    Why not explain what you are trying to accomplish instead of having us guess



  • kats

    You're going to have to tell us what you're trying to do. Otherwise we're just guessing. By the way, the name of the operators you're using is left shift and right shift operators - they change the internal bit representation of integer values by moving them to the left or right a certain number of times.

  • Help << operator VB. net