วันอาทิตย์ที่ 4 พฤษภาคม พ.ศ. 2557

C# class example

โปรแกรมจะรับค่า properties ของ air จำนวน 10 ชุด
โดยจะมี class AirCondition เพื่อเป็นต้นแบบของวัตถุ
เมื่อรับค่าเสร็จก็จะแสดงค่า BTU ของ air แต่ละตัวผ่าน method getBTU()
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 namespace ConsoleApplication2  
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       List<AirCondition> air = new List<AirCondition>();  
       int n = 1, width, high, length, var;  
       while (n <= 10)  
       {  
         Console.WriteLine("Enter properties of air{0}/10 :", n);  
         Console.WriteLine("Enter width : ");  
         string s_width = Console.ReadLine();  
         Console.WriteLine("Enter high : ");  
         string s_high = Console.ReadLine();  
         Console.WriteLine("Enter length : ");  
         string s_length = Console.ReadLine();  
         Console.WriteLine("Enter var : ");  
         string s_var = Console.ReadLine();  
         if (int.TryParse(s_width, out width) && int.TryParse(s_high, out high) && int.TryParse(s_length, out length) && int.TryParse(s_var, out var))  
         {  
           AirCondition temp = new AirCondition(width, high, length, var);  
           air.Add(temp);  
           n++;  
         }  
         else  
         {  
           Console.WriteLine("Please enter again!!");  
         }  
       }  
       n = 1;  
       foreach (AirCondition ob in air)  
       {   
         Console.WriteLine("BTU of air{0}/10 : {1}", n, ob.getBTU());  
         n++;  
       }  
       Console.WriteLine("Press any key to stop...");  
       Console.ReadKey();  
       /*AirCondition air = new AirCondition(5,3,5,400);  
       double value = air.getBTU();  
       Console.WriteLine("BTU : {0}", value);  
       Console.WriteLine("Press any key to stop...");  
       Console.ReadKey();  
       */  
     }  
   }  
   class AirCondition  
   {  
     public int width;  
     public int high;  
     public int length;  
     public int var;  
     public AirCondition()  
     {  
       width = 0;  
       high = 0;  
       length = 0;  
       var = 0;  
     }  
     public AirCondition(int width,int high, int length, int var)  
     {  
       this.width = width;  
       this.high = high;  
       this.length = length;  
       this.var = var;  
     }  
     public double getBTU()  
     {  
       return (width * high * length * var) / 3;  
     }  
   }  
 }  

--------------------------------------------------

C# get input number from keyboard and find max min


โปรแกรมจะรับ input จาก keyboard จำนวน 10 ตัวเลข
จะมีการเช็ค input ว่าเป็นตัวเลขหรือไม่ ถ้าไม่ใช่ก็จะให้กลับไปใส่อีกรอบ
เมื่อใส่ตัวเลขเรียบร้อยแล้วก็จะแสดงผลค่ามากที่สุดและน้อยที่สุด
ผ่านหน้าจอโปรแกรม
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 namespace ConsoleApplication1  
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       int[] numbers;  
       numbers = new int[10];  
       int n = 1, value, max, min;  
       while (n <= 10)  
       {  
         Console.WriteLine("Enter number {0}/10 :", n);  
         string line = Console.ReadLine();  
         if (int.TryParse(line, out value))  
         {  
           numbers[n - 1] = value;  
           n++;  
         }  
         else  
         {  
           Console.WriteLine("Please enter again!!");  
         }  
       }  
       max = min = numbers[0];  
       foreach (int i in numbers)   
       {  
         if (i > max)   
         {  
           max = i;  
         }  
         if (i < min)   
         {  
           min = i;  
         }  
       }  
       Console.WriteLine("\n\nmax number : {0} \nmin number : {1}",max,min);  
       Console.WriteLine("Press any key to stop...");  
       Console.ReadKey();  
     }  
   }  
 }  


วันอาทิตย์ที่ 6 เมษายน พ.ศ. 2557

การใช้งานฟังก์ชั่น COUNTIF ใน Excel

พอดีได้มีโอกาสใช้ Excel ในการสร้างตารางการใช้ชีวิตในแต่ละวันเพราะรู้สึกว่าจะใช้ชีวิตไร้จุดหมายไปหน่อย เลยทำการสร้างตารางมาโดยจะทำการนับการอ่านหนังสือในแต่ละวันนั้นให้มีจำนวน 1.5 ชม./วัน

แบบก็ประมาณนี้


แต่ก็อยากจะใช้ เครื่องหมาย "/" มันดูเหมือนเป็นการเช็คดี :P
ที่จริงจะใช้ เป็นตัวเลข 1 แล้วใช้ฟังก์ชั่น SUM ก็ได้แต่มันดูไม่เท่อ่ะ
ปัญหาเกิดทีนี้!@~& ลองใช้ SUM ก็ไม่ได้(หรือใช้ได้แต่ใช้ไม่เป็น !!)
ก็เลยมาเจอกับ COUNTIF การใช้ก็ง่ายๆ
รูปแบบ COUNTIF(range, criteria) 
จากนั้นก็นำมาใช้ให้ตรงกับงานของเราก็จะเป็น =COUNTIF(C3:AF3,"/")

ผลลัพธ์

ส่วนการใช้งานแบบอื่นถ้าอยากรู้ดูได้จาก
http://office.microsoft.com/th-th/excel-help/HP010069840.aspx
ตามนี้เลย
*************