By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

How to Print The Values of Multiple Checkboxes in VB6

P: 29
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),mpf(column3),slide(col umn4),pdc(column5),tgas(column6),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:
Expand|Select|Wrap|Line Numbers
  1. Public Sub PrintColumns()
  2. With frmHeader
  3.     'all columns
  4.     If .colFPH.Value = 1 And .colMPF.Value = 1 And .colTGas.Value = 1 _
  5.         And .colMeth.Value = 1 And .colEth.Value = 1 And .colPro.Value = 1 And .colIBut.Value = 1 _
  6.         And .colNBut.Value = 1 And .colMWtIn.Value = 1 And .colMWtOut.Value = 1 And .colMTmpIn.Value = 1 _
  7.         And .colMTmpOut.Value = 1 And .colAnhy.Value = 1 And .colChalk.Value = 1 And .colLime.Value = 1 _
  8.         And .colDolo.Value = 1 And .colShale.Value = 1 And .colSand.Value = 1 And .colSilt.Value = 1 _
  9.         And .colCoal.Value = 1 And .colChert.Value = 1 And .colNoSamp.Value = 1 Then
  10.             Print #1, depth & vbTab & fph & vbTab & mpf & vbTab & slide & vbTab & _
  11.                 pdc & vbTab & tgas & vbTab & c1 & vbTab & c2 & vbTab & c3 & vbTab & _
  12.                 c4i & vbTab & c4n & vbTab & shale & vbTab & silt & vbTab & _
  13.                 sand & vbTab & chalk & vbTab & lime & vbTab & dolo & vbTab & _
  14.                 anhy & vbTab & coal & vbTab & chert & vbTab & nosamp & vbTab & _
  15.                 mwin & vbTab & mwout & vbTab & mtmpin & vbTab & mtmpout
  16.     End If
  17.  
  18.     If .colFPH.Value = 1 Then
  19.         Print #1, depth & vbTab & fph
  20.     End If
  21.     If .colMPF.Value = 1 Then
  22.         Print #1, depth & vbTab & mpf
  23.     End If
  24.     If .colSlide.Value = 1 Then
  25.         Print #1, depth & vbTab & slide
  26.     End If
  27.     If .colPDC.Value = 1 Then
  28.         Print #1, depth & vbTab & pdc
  29.     End If
  30.     If .colTGas.Value = 1 Then
  31.         Print #1, depth & vbTab & tgas
  32.     End If
  33.     If .colMeth.Value = 1 Then
  34.         Print #1, depth & vbTab & c1
  35.     End If
  36.     If .colEth.Value = 1 Then
  37.         Print #1, depth & vbTab & c2
  38.     End If
  39.     If .colPro.Value = 1 Then
  40.         Print #1, depth & vbTab & c3
  41.     End If
  42.     If .colIBut.Value = 1 Then
  43.         Print #1, depth & vbTab & c4i
  44.     End If
  45.     If .colNBut.Value = 1 Then
  46.         Print #1, depth & vbTab & c4n
  47.     End If
  48.     If .colMWtIn.Value = 1 Then
  49.         Print #1, depth & vbTab & mwin
  50.     End If
  51.     If .colMWtOut.Value = 1 Then
  52.         Print #1, depth & vbTab & mwout
  53.     End If
  54.     If .colMTmpIn.Value = 1 Then
  55.         Print #1, depth & vbTab & mtmpin
  56.     End If
  57.     If .colMTmpOut.Value = 1 Then
  58.         Print #1, depth & vbTab & mtmpout
  59.     End If
  60.     If .colAnhy.Value = 1 Then
  61.         Print #1, depth & vbTab & anhy
  62.     End If
  63.  
  64.  
  65.     'fph & mpf
  66.     If .colFPH.Value = 1 And .colMPF.Value = 1 Then
  67.         Print #1, depth & vbTab & fph & vbTab & mpf
  68.     End If
  69.     'fph,mpf,& tgas
  70.     If .colFPH.Value = 1 And .colMPF.Value = 1 And .colTGas.Value = 1 Then
  71.         Print #1, depth & vbTab & fph & vbTab & mpf & vbTab & tgas
  72.     End If
  73.  
  74. End With
  75.  
  76. End Sub
  77.  
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?
Feb 8 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.