I
Incredulous Dreamer
OK, Here is my first attempt to solve the problem I posted a couple days
back. It is functional but I am sure it is not as elegant as it could be,
because I am just a code hacker. My thanks to Steve Rindsberg and David
Marcovitz for setting me down the path.
Some troubles I had and what I learned:
1) It was necessary to be able to allow the user to toggle the selection
boxes "on and off" repeatedly. So, the only thing I could think of to do
was update the box status for all the boxes and rewrite the entire text file
every time the user changed ANY selection box. If there is a more elegent
way to do this, please let me know.
2) Now I believe I know why David used the
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents .......
methods in his quiz code. That seems to be the only method I could use that
would overwrite the file each time. I couldn't find a way to do that with
the "open" method.
3) I don't "read" the value for the comboBox yet, I haven't figured out
that command yet but I hope to accomplish that without much additional
grief.
Next I need to bring the txt file created into specific cells in a
spreadsheet. In future versions some of the response may be numbers but I
assume I can deal with that as well.
The code follows below. Improvements are welcome.
Private Sub UserForm_Initialize()
ComboBox1.Clear
ComboBox1.ColumnCount = 2
ComboBox1.BoundColumn = 2
ComboBox1.TextColumn = 1
ComboBox1.AddItem "Low"
ComboBox1.AddItem "Medium"
ComboBox1.AddItem "High"
ListBox1.AddItem "Beam Blanker"
ListBox1.ColumnCount = 1
ListBox1.BoundColumn = 1
ListBox1.TextColumn = 4
End Sub
Public Sub ListBox1_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
ListBox2.AddItem "Electron Lithography"
ListBox2.ColumnCount = 1
ListBox2.BoundColumn = 1
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
Private Sub ListBox2_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
ListBox3.AddItem "ion Lithography"
ListBox3.ColumnCount = 1
ListBox3.BoundColumn = 1
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
Private Sub ListBox3_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
ListBox4.AddItem "TEM Sample Preparation"
ListBox4.ColumnCount = 1
ListBox4.BoundColumn = 1
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
Private Sub ListBox4_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
back. It is functional but I am sure it is not as elegant as it could be,
because I am just a code hacker. My thanks to Steve Rindsberg and David
Marcovitz for setting me down the path.
Some troubles I had and what I learned:
1) It was necessary to be able to allow the user to toggle the selection
boxes "on and off" repeatedly. So, the only thing I could think of to do
was update the box status for all the boxes and rewrite the entire text file
every time the user changed ANY selection box. If there is a more elegent
way to do this, please let me know.
2) Now I believe I know why David used the
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents .......
methods in his quiz code. That seems to be the only method I could use that
would overwrite the file each time. I couldn't find a way to do that with
the "open" method.
3) I don't "read" the value for the comboBox yet, I haven't figured out
that command yet but I hope to accomplish that without much additional
grief.
Next I need to bring the txt file created into specific cells in a
spreadsheet. In future versions some of the response may be numbers but I
assume I can deal with that as well.
The code follows below. Improvements are welcome.
Private Sub UserForm_Initialize()
ComboBox1.Clear
ComboBox1.ColumnCount = 2
ComboBox1.BoundColumn = 2
ComboBox1.TextColumn = 1
ComboBox1.AddItem "Low"
ComboBox1.AddItem "Medium"
ComboBox1.AddItem "High"
ListBox1.AddItem "Beam Blanker"
ListBox1.ColumnCount = 1
ListBox1.BoundColumn = 1
ListBox1.TextColumn = 4
End Sub
Public Sub ListBox1_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
ListBox2.AddItem "Electron Lithography"
ListBox2.ColumnCount = 1
ListBox2.BoundColumn = 1
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
Private Sub ListBox2_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
ListBox3.AddItem "ion Lithography"
ListBox3.ColumnCount = 1
ListBox3.BoundColumn = 1
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
Private Sub ListBox3_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
ListBox4.AddItem "TEM Sample Preparation"
ListBox4.ColumnCount = 1
ListBox4.BoundColumn = 1
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub
Private Sub ListBox4_Change()
Set fs = CreateObject("Scripting.FileSystemObject")
Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
answerFile.Close
Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
If ListBox1.Selected(0) = True Then
Write #1, "Beam Blanker"
Else
Write #1, "No Beam Blanker"
End If
If ListBox2.Selected(0) = True Then
Write #1, "Electron Lithography"
Else
Write #1, "No Electron Lithograpy"
End If
If ListBox3.Selected(0) = True Then
Write #1, "Ion Lithography"
Else
Write #1, "No Ion Lithography"
End If
If ListBox4.Selected(0) = True Then
Write #1, "TEM Sample Preparation"
Else
Write #1, "No TEM Sample Prep"
End If
Close #1
End Sub