Attribute VB_Name = "x04_Checks"
Option Explicit
Option Base 1   ' Set default array subscripts to 1.


Public Sub do_checks(txt)
  Printdok "do_checks"
  If m_icount < 1 Then MsgBox "Warning! Nr of individuals=" & CStr(m_icount)
  If m_hcount < 1 Then MsgBox "Warning! Nr of households=" & CStr(m_hcount)
  Call check_hhnr(txt)
  Call check_inr(txt)
  Call check_begsh_bvux(txt)
  'Call check_istatus(txt)
End Sub

' Check for inconsitency in hh-numbers
Public Sub check_hhnr(txt) Dim hindex As Long, iindex As Long, hhnr As Long ' Check hh-numbers in h-matrix For hindex = 1 To m_hcount hhnr = h_hhnr(hindex) If hhnr2index(hhnr) < 1 Then status "ERROR h-matrix" status "Err " & "hindex=" & hindex status "Err " & "hhnr=" & hhnr MsgBox txt & " Error in hh-nr (h-matrix)" Debug.Print HouseholdInfo(h_hhnr(hindex)) End If Next ' Check hh-numbers in i-matrix For iindex = 1 To m_icount hhnr = i_hhnr(iindex) If hhnr2index(hhnr) < 1 Then status "ERROR i-matrix" status "Err " & "iindex=" & iindex status "Err " & "hhnr=" & hhnr MsgBox txt & " Error in hh-nr (i-matrix)" Debug.Print HouseholdInfo(hhnr) End If Next End Sub
' Check for inconsitency in i-numbers
Public Sub check_inr(txt) Dim hindex As Long, iindex As Long, hhnr As Long, indnr As Long ' Check i-numbers in i-matrix For iindex = 1 To m_icount indnr = i_indnr(iindex) If indnr2index(indnr) < 1 Then status "ERROR i-matrix" status "Err " & "iindex=" & iindex status "Err " & "indnr=" & indnr MsgBox txt & " Error in ind-nr (i-matrix)" Debug.Print HouseholdInfo(i_hhnr(iindex)) End If Next ' Check i-numbers in h-matrix For hindex = 1 To m_hcount indnr = h_first_indnr(hindex) If indnr2index(indnr) < 1 Then status "ERROR h-matrix" status "Err " & "hindex=" & hindex status "Err " & "first indnr=" & indnr MsgBox txt & " Error in first ind-nr (h-matrix)" Debug.Print HouseholdInfo(h_hhnr(hindex)) End If Next End Sub
'*** Sub check_begsh_bvux(txt) checks some important household variables '*** for consistency. The context of the call to the sub is tranferred '*** by txt.
Sub check_begsh_bvux(txt) Dim h As Long, indnr As Long Dim nvux As Integer, nchild As Integer '*** Loop across all households For h = 1 To m_hcount nvux = 0 nchild = 0 indnr = h_first_indnr(h) If h_n_adults(h) < 1 Then MsgBox "Error(" & txt & "): begsh=" & h_n_adults(h) & " hhnr=" & h_hhnr(h) Debug.Print HouseholdInfo(h_hhnr(h)) End If '*** Loop across all household members and count adults and children Do Until indnr = 0 If i_bvux(indnr2index(indnr)) = 1 Then nvux = nvux + 1 Else nchild = nchild + 1 End If indnr = i_next_indnr(indnr2index(indnr)) Loop If h_n_adults(h) <> nvux Then MsgBox "Error(" & txt & "): h_n_adults <> nvux, hhnr=" & h Debug.Print HouseholdInfo(h_hhnr(h)) End If If h_n_child(h) <> nchild Then MsgBox "Error(" & txt & "): h_n_child <> nchild, hhnr=" & h Debug.Print HouseholdInfo(h_hhnr(h)) End If If h_size(h) <> nchild + nvux Then MsgBox "Error(" & txt & "): h_size <> nvux + nchild, hhnr=" & h Debug.Print HouseholdInfo(h_hhnr(h)) End If Next End Sub
Sub check_istatus(txt) Dim i As Long For i = 1 To m_icount If i_status(i) < 1 Or i_status(i) > 9 Then _ MsgBox "Error(" & txt & "): i_status=" & i_status(i) Next End Sub
Sub trace_indnr(indnr As Long) Dim iindex As Long For iindex = 1 To m_icount If i_indnr(iindex) = indnr Then status "TTTTTTT" status "Trace indnr=" & indnr status "iindex=" & iindex status "i_hhnr=" & i_hhnr(iindex) status "i_age=" & i_age(iindex) status "TTTTTTT" End If Next End Sub
Sub dbg_hhnr() Dim inr As Long, hnr As Long Dim filenr As Byte filenr = FreeFile Open sesimpath & "\tempdata\debug_hhnr.txt" For Output As #filenr For inr = 1 To m_icount If i_hhnr(inr) <> h_hhnr(hhnr2index(i_hhnr(inr))) Then Write _ #filenr, i_hhnr(inr), h_hhnr(hhnr2index(i_hhnr(inr))) Next Close #filenr End Sub