I am adding to my software. I have placed about 30 checkboxes on a form. Based on which checkboxes are selected, I want to print the values to a tab delimited text file. For instance, the first checkbox is labeled "Depth" and corresponds to a named variable of 'depth'. If this checkbox is select, I want to print column A, or 'depth' to the file. This part is easy. I am looking for the simplest way to write to a tab delimited text file, if there are multiple checkboxes selected, say 20. But I am wanting the column to print in a certain order. My named variables are: depth(column1), fph(column2),mp f(column3),slid e(column4),pdc( column5),tgas(c olumn6),etc. Now if checkboxes "Depth", "MPF" , "Slide", & "TGas" were selected, I need the values of the columns to print in a certain order: depth, fph, mpf, slide, pdc, tgas, etc. The code I have so far is as follows:
If I keep writing it like I am, I will have around 2000 lines of code to write, just to get the logic correct. Does anyone have a simpler way of doing this? I have about 25 columns of data, and only want the ones that are referenced by the checkboxes to print to a tab delimited file, but in a specific order. Any ideas?
Code:
Public Sub PrintColumns()
With frmHeader
'all columns
If .colFPH.Value = 1 And .colMPF.Value = 1 And .colTGas.Value = 1 _
And .colMeth.Value = 1 And .colEth.Value = 1 And .colPro.Value = 1 And .colIBut.Value = 1 _
And .colNBut.Value = 1 And .colMWtIn.Value = 1 And .colMWtOut.Value = 1 And .colMTmpIn.Value = 1 _
And .colMTmpOut.Value = 1 And .colAnhy.Value = 1 And .colChalk.Value = 1 And .colLime.Value = 1 _
And .colDolo.Value = 1 And .colShale.Value = 1 And .colSand.Value = 1 And .colSilt.Value = 1 _
And .colCoal.Value = 1 And .colChert.Value = 1 And .colNoSamp.Value = 1 Then
Print #1, depth & vbTab & fph & vbTab & mpf & vbTab & slide & vbTab & _
pdc & vbTab & tgas & vbTab & c1 & vbTab & c2 & vbTab & c3 & vbTab & _
c4i & vbTab & c4n & vbTab & shale & vbTab & silt & vbTab & _
sand & vbTab & chalk & vbTab & lime & vbTab & dolo & vbTab & _
anhy & vbTab & coal & vbTab & chert & vbTab & nosamp & vbTab & _
mwin & vbTab & mwout & vbTab & mtmpin & vbTab & mtmpout
End If
If .colFPH.Value = 1 Then
Print #1, depth & vbTab & fph
End If
If .colMPF.Value = 1 Then
Print #1, depth & vbTab & mpf
End If
If .colSlide.Value = 1 Then
Print #1, depth & vbTab & slide
End If
If .colPDC.Value = 1 Then
Print #1, depth & vbTab & pdc
End If
If .colTGas.Value = 1 Then
Print #1, depth & vbTab & tgas
End If
If .colMeth.Value = 1 Then
Print #1, depth & vbTab & c1
End If
If .colEth.Value = 1 Then
Print #1, depth & vbTab & c2
End If
If .colPro.Value = 1 Then
Print #1, depth & vbTab & c3
End If
If .colIBut.Value = 1 Then
Print #1, depth & vbTab & c4i
End If
If .colNBut.Value = 1 Then
Print #1, depth & vbTab & c4n
End If
If .colMWtIn.Value = 1 Then
Print #1, depth & vbTab & mwin
End If
If .colMWtOut.Value = 1 Then
Print #1, depth & vbTab & mwout
End If
If .colMTmpIn.Value = 1 Then
Print #1, depth & vbTab & mtmpin
End If
If .colMTmpOut.Value = 1 Then
Print #1, depth & vbTab & mtmpout
End If
If .colAnhy.Value = 1 Then
Print #1, depth & vbTab & anhy
End If
'fph & mpf
If .colFPH.Value = 1 And .colMPF.Value = 1 Then
Print #1, depth & vbTab & fph & vbTab & mpf
End If
'fph,mpf,& tgas
If .colFPH.Value = 1 And .colMPF.Value = 1 And .colTGas.Value = 1 Then
Print #1, depth & vbTab & fph & vbTab & mpf & vbTab & tgas
End If
End With
End Sub