1 / 20

סוגי מידע / משתנים

סוגי מידע / משתנים. ד"ר אבי רוזנפלד. דוגמה פשוטה. Module Module1 Sub Main() Dim x As Integer x = 10 Console.WriteLine ((x + 2) / 10) Console.ReadKey () End Sub End Module. מה זה יעשה?. Module Module1 Sub Main() Dim x As Integer x = 10

Download Presentation

סוגי מידע / משתנים

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. סוגי מידע / משתנים ד"ר אבי רוזנפלד

  2. דוגמה פשוטה Module Module1 Sub Main() Dim x As Integer x = 10 Console.WriteLine((x + 2) / 10) Console.ReadKey() End Sub End Module

  3. מה זה יעשה? Module Module1 Sub Main() Dim x As Integer x = 10 Console.WriteLine(x + 2 * 10 + 1) Console.ReadKey() End Sub End Module

  4. מה יהיה הפלט? Module Module1 Sub Main() Dim x, y, z As Integer x = 10 y = x / 3 z = x / 4 Console.WriteLine("x is " & x) Console.WriteLine("y is " & y) Console.WriteLine("z is " & z) Console.ReadKey() End Sub End Module

  5. num count הצבה (השמה) -assignment Dim num as integer Dim count as integer =1 6 5 num = 5 num = num + count 1 מבוא לתכנות למע"ס - מאיר קומר - סמסטר

  6. אופרטורים - + * / Mod \ מבוא לתכנות למע"ס - מאיר קומר - סמסטר

  7. יש גם קבועים Const piAs single = 3.1415 מבוא לתכנות למנע"ס - שבוע מספר 2 - מאיר קומר - סמסטר ב' - תשס"ו

  8. סוגים שונים של מידע (long) Module Module1 Sub Main() Dim x, y, z As Long x = 10 y = x / 3 z = x / 4 Console.WriteLine("x is " & x) Console.WriteLine("y is " & y) Console.WriteLine("z is " & z) Console.ReadKey() End Sub End Module

  9. סוגים שונים של מידע (short) Module Module1 Sub Main() Dim x, y, z As Short x = 10 y = x / 3 z = x / 4 Console.WriteLine("x is " & x) Console.WriteLine("y is " & y) Console.WriteLine("z is " & z) Console.ReadKey() End Sub End Module

  10. סוגים שונים של מידע (String) Module Module1 Sub Main() Dim x, y, z As String x = "Hello World" 'y = x / 3 This is in a comment 'z = x / 4 This is too Console.WriteLine("x is " & x) Console.WriteLine("y is " & y) Console.WriteLine("z is " & z) Console.ReadKey() End Sub End Module

  11. מה זה יעשה? Module Module1 Sub Main() Dim x, y, z As String x = "Hello World" y = x + " Aviland " z = x + " what???? " + y 'This actually works! Console.WriteLine("x is " & x) Console.WriteLine("y is " & y) Console.WriteLine("z is " & z) Console.ReadKey() End Sub End Module

  12. העולם של קלט • אתה חייב משתנה (זיכרון לאחסן את המידע) • אתה גם חייב משתנה מתאים של Console.ReadLine

  13. דוגמא Module Module1 Sub Main() Dim x, y As String x = "Hello World" Console.WriteLine(x) y = Console.ReadLine() 'It waits until "enter" Console.WriteLine("You typed " & y) Console.ReadKey() End Sub End Module

  14. זה לא יעבוד Module Module1 Sub Main() Dim x As Integer x = Console.Read() ' this reads as a word! 'It waits until "enter" Console.WriteLine("You typed " & x + 1) Console.ReadKey() End Sub End Module

  15. זה כן יעבוד Module Module1 Sub Main() Dim x As Integer x = Console.ReadLine() 'this works! 'It waits until "enter" Console.WriteLine("You typed " & x + 1) Console.ReadKey() End Sub End Module

  16. מה זה יעשה? Module Module1 Sub Main() Dim x As Integer Dim y As Decimal y = Console.ReadLine 'It waits until "enter" x = y Console.WriteLine("The whole portion was " & x) Console.WriteLine("The input was " & y) Console.WriteLine("The decimal was " & y - x) Console.ReadKey() End Sub End Module

  17. Type Casting (and fun!) Module Module1 Sub Main() Dim thousands, hundreds, tens, ones As Integer Dim whole, stam_unused_variable As Decimal Console.WriteLine("Please enter a number greater than 1000 ") whole = Console.ReadLine 'It waits until "enter" thousands = Int(whole / 1000) whole -= thousands * 1000 hundreds = Int(whole / 100) whole -= hundreds * 100 tens = Int(whole / 10) ones = whole Mod 10 'Just for show off mod Console.WriteLine("The thousands part is " & thousands & ", the hundreds part is " & hundreds) Console.WriteLine("The tens portion is " & tens & " and the ones portion is " & ones) Console.ReadKey() End Sub End Module

  18. פלט לקבצים Imports System.IO 'Notice the import! Module Module1 Sub Main() Dim writer As StreamWriter = _ New StreamWriter("z:\KBTest.txt") writer.WriteLine("File created using StreamWriter class2.") writer.Write("What???") writer.Close() End Sub End Module

  19. דוגמא לקלט Imports System.IO 'Notice the import! Module Module1 Sub Main() Dim fileReader As StreamReader fileReader = _ My.Computer.FileSystem.OpenTextFileReader("KBTest.txt") Dim x As String x = fileReader.ReadLine() Console.WriteLine("The file line of the file is " & x) Console.ReadKey() End Sub End Module

More Related