Sunday, November 8, 2015

Vb6 for Excel Cheat Sheet

Ngoài các hàm mặc định của VB6, còn có các hàm dành riêng cho Excel. Tham khảo 1 số ví dụ.

Các kiểu dữ liệu dành riêng cho Excel:
 - Workbook
 - Workbooks
 - WorkSheet
 - WorkSheets
 - Range: 1 cell cũng là 1 Range

1. Set giá trị cho Cell A1 trong worksheet "Sheet1"
  Range("'Sheet1'!A1").Value = "giá trị"
2. Set FontSize:   Range("'Sheet1'!A1").Font.Size = 30
3. Gạch giữa chữ: Range("'Sheet1'!A1").Font.StrikeThrought = True

Macro in Excel

1. Enable Developer Toolbar (if not yet): Home -> Right click ribbon toolbar -> Customize Ribbon -> Check Developer checkbox.
2. Developer toolbar -> Macro -> Test this code:
 
Sub test()
    Dim r As Range, c As Range
    Dim x As String, j As Integer, k As Integer
    Dim cfind As Range, r1 As Range
    
    With Workbooks("excel A.xls").Worksheets("sheet1")
        Set r = Range(.Range("A2"), .Range("A2").End(xlDown))
        For Each c In r
            x = c.Value
            With Workbooks("excel B.xls")
                j = .Worksheets.Count
                For k = 1 To j
                    With .Worksheets(k)
                        Set cfind = .Cells.Find(what:=x, lookat:=xlWhole)
                        If Not cfind Is Nothing Then
                            Set r1 = Range(cfind.Offset(0, 1), cfind.End(xlToRight))
                            r1.Copy
                            GoTo pasting
                        End If
                    End With 'worksheets(k)
                    Next k
                    Exit Sub
            End With 'second book
        
pasting:
        c.Offset(0, 3).PasteSpecial
        Next c
    End With 'first book
End Sub

Thursday, October 29, 2015

Một số lưu ý khi sử dụng Json.NET

1. Create Json Model Object: sử dụng JsonProperty để định nghĩa tên của 1 field.


2. Khi parse json string. Nên parse thành JToken, vì nó tổng quan nhất, sau đó dựa vào cái type của nó để xác định xem nên parse thành gì (nếu không có thể sẽ bị exception). Điều này quan trọng để parse string thành 1 type nào đó, đôi lúc string không hợp lệ cho type đó.

Tuesday, October 20, 2015

How to detect error base on RestSharp returned response fields?



Never check ErrorMessage for detecting error, just check StatusCode.


Note. This picture is In case of using Asp Web Api 2, doesn't has ErrorMessage but has System.Net.HttpStatusCode.NotFound status. (See all http status codes)

Một số lưu ý khi sử dụng SQLite

Links hay:
  http://blogs.msdn.com/b/matt/archive/2008/05/22/into-to-linq-to-sql-optimistic-concurrency.aspx

1. Khi tạo các model, sử dụng namespace using System.Data.Linq.Mapping;
Example:
[Table(Name = "McmUser")]
    public class McmUser
    {
        [Column(Name = "Username", IsPrimaryKey = true)]
        public string Username { get; set; }

        [Column(Name = "IsActive")]
        public bool IsActive { get; set; }
    }

2. Không sử dụng 1 số hàm sau trên IQueryable (của System.Linq):

  1. First
  2. FirstOrDefault
  3. ElementAt
3. Sử dụng Lock trên 1 DataContext See

Thursday, August 6, 2015

Monday, August 3, 2015

Ninect OnePerRequestModule

http://stackoverflow.com/questions/536007/ninject-oneperrequestbehaviour-doesnt-seem-to-work-correctly


IIS7:
<system.webServer> 
  <modules>
    <add name="OnePerRequestModule" type="Ninject.Core.Behavior.OnePerRequestModule, Ninject.Core"/>
  </modules>
</system.webServer>
IIS6:
<system.web>
  <httpModules>
    <add name="OnePerRequestModule" type="Ninject.Core.Behavior.OnePerRequestModule, Ninject.Core"/>
  </httpModules>
</system.web>

Monday, May 18, 2015

How to download GIF from 9gag.com

9gag.com/gag/aAr5XAd
=>>
http://img-9gag-ftw.9cache.com/photo/aAr5XAd_460sa.gif