Files
Lesson 1.6 homework part C solution
Code
'Homework 1.6c
'Imagine that your company has the part numbers for its product lines listed in text files, with _
each part number separated by a comma. The prefix for each part number should be "FKS", with _
no spaces in between the prefix and the number. Use the Split, Replace, and IsNumeric _
functions to: _
-create an array containing all part numbers _
-remove any extra spaces _
-include the prefix if it is not already present _
-display the result in a single message box _
Assume that this is the string that was pulled from the text file: _
"2900,FKS2910, 2920, 2930 ,FKS2940,2950, 2960"
Const strList As String = "2900,FKS2910, 2920, 2930,FKS2940,2950,2960"
Dim strPartNums() As String
Dim i As Integer
Dim strCompletedList As String
Sub main()
strCompletedList = ""
strPartNums = Split(strList, ",")
For i = 0 To UBound(strPartNums)
If InStr(1, strPartNums(i), " ") <> 0 Then strPartNums(i) = Replace(strPartNums(i), " ", "")
If IsNumeric(strPartNums(i)) = True Then strPartNums(i) = "FKS" & strPartNums(i)
strCompletedList = strCompletedList & vbCrLf & strPartNums(i)
Next i
MsgBox strCompletedList
End Sub