BlueIshDan
☠
- Local time
- Today, 05:26
- Joined
- May 15, 2014
- Messages
- 1,122
How does this look?
*NOTICE* ERR in table for question five is due to a duplicate answer letter. *NOTICE*
5. A query can do which of the following:
a. display less fields than the underlying table
b. make a table
c. update a table
*a. all of the above
*NOTICE*
Generated by this code:
Code:
Public Sub ImportQuestions(ByVal file As String)
Dim fs As New FileSystemObject
If Not fs.FileExists(file) Then: Exit Sub
Dim rs As Recordset: Set rs = CurrentDb.OpenRecordset("questions")
Dim str_line As Variant: Dim str_temp As String: Dim is_answer As Boolean
Dim last_option As String: Dim first_record As Boolean: first_record = True
For Each str_line In GetFileLines(file, True, False, False)
str_temp = Trim(Left(str_line, 3))
If InStr(1, str_temp, ".") + _
InStr(1, str_temp, ")") = 0 Then
rs(last_option) = rs(last_option) + " " + Trim(str_line)
Else
str_temp = Replace(str_temp, ".", vbNullString)
str_temp = Replace(str_temp, ")", vbNullString)
If IsNumeric(str_temp) Then
If Not first_record Then
rs.Update
Else: first_record = False
End If
rs.AddNew
rs!question = Mid(str_line, 4)
Else
If InStr(1, str_temp, "*") > 0 Then
str_temp = Replace(str_temp, "*", vbNullString)
rs!answer = str_temp
End If
last_option = Trim(Replace(str_temp, Chr(9), vbNullString))
rs(last_option) = Mid(str_line, 4)
End If
End If
Next
rs.Close
End Sub
Public Function GetFileLines(ByVal address As String, _
ByVal remove_blank_lines As Boolean, _
ByVal trim_lines As Boolean, _
ByVal keep_newline_char)
' keep_newline_char represents the Chr(byte) value of 10 and 13. These Bytes represent a NewLine.
' passing a true value to this parameter will cause returned lines to contain the new line value at the end of them.
' Use: True - Displaying data in a message
' False - Parsing the data line by line.
Dim fs As New FileSystemObject
Dim arr_bytes() As Byte
Dim file_node As Long
Dim var_byte As Variant
Dim lines() As String
Dim line_count As Long: line_count = 0
ReDim lines(line_count)
If fs.FileExists(address) Then
ReDim arr_bytes(FileLen(address))
file_node = FreeFile
Open address For Binary Access Read As file_node
Get 1, , arr_bytes
Close file_node
For Each var_byte In arr_bytes
If var_byte = 10 Or var_byte = 13 Then
If trim_lines Then: lines(line_count) = Trim(lines(line_count))
If remove_blank_lines And Trim(lines(line_count)) = "" Then
lines(line_count) = ""
Else
If keep_newline_char Then: lines(line_count) = lines(line_count) & Chr(var_byte)
line_count = line_count + 1
ReDim Preserve lines(line_count)
End If
Else: lines(line_count) = lines(line_count) & Chr(var_byte)
End If
var_byte = Empty
Next
End If
Set fs = Nothing
GetFileLines = lines
End Function
Attachments
Last edited: