How to use Streamreader to read different lines of text from .txt file into different ListBoxes? - listbox

Forgive me if this has already been asked. I've been able to find tons of info on writing to a ListBox from a .txt file, and that's supereasy. What I can't seem to find much info on is reading that text back into to multiple ListBoxes, 10 to be exact. I've been working on this for the last 12 hours and I give up. Nothing I do works. either all the listbox lines get put into the 1st testListBox, or when I try using an if...then statement, not show up. I've tried too many things to list here. My program has 10 listboxes all together, but I've only been trying to work on the 1st two. if I can get those going correctly, then the rest should be easy. That's why there are 10 listboxes being written and only 2 being read. Here is my write code and my read code:
' handles saveButton Click
Public Sub saveButton_Click(sender As Object, e As EventArgs) Handles saveButton.Click
SaveFileDialog1.InitialDirectory = "c:\users\jeremy\desktop"
SaveFileDialog1.FileName = (nameOfCourseTextBox.Text)
SaveFileDialog1.Filter = "Text File ONLY (*.txt)|*.txt"
SaveFileDialog1.ShowDialog()
Dim SW As New StreamWriter(SaveFileDialog1.FileName)
Dim i As Integer
SW.WriteLine(nameOfCourseTextBox.Text)
SW.WriteLine(creditsTextBox.Text)
SW.WriteLine(testTypeLabel.Text)
SW.WriteLine(testWeightLabel.Text)
SW.WriteLine(attendanceTypeLabel.Text)
SW.WriteLine(attendanceWeightLabel.Text)
SW.WriteLine(assignmentTypeLabel.Text)
SW.WriteLine(assignmentWeightLabel.Text)
SW.WriteLine(otherTypeLabel.Text)
SW.WriteLine(otherWeightLabel.Text)
SW.WriteLine(projectTypeLabel.Text)
SW.WriteLine(projectWeightLabel.Text)
SW.WriteLine(aTextBox.Text)
SW.WriteLine(bTextBox.Text)
SW.WriteLine(cTextBox.Text)
SW.WriteLine(dTextBox.Text)
SW.WriteLine(fTextBox.Text)
For i = 0 To testListBox.Items.Count - 1
SW.Write(testListBox.Items.Item(i) & ",")
Next
For i = 0 To gradeTestListBox.Items.Count - 1
SW.Write(gradeTestListBox.Items.Item(i) & ",")
Next
For i = 0 To assignmentListBox.Items.Count - 1
SW.WriteLine(assignmentListBox.Items.Item(i))
Next
For i = 0 To gradeAssignmentListBox.Items.Count - 1
SW.WriteLine(gradeAssignmentListBox.Items.Item(i))
Next
For i = 0 To attendanceListBox.Items.Count - 1
SW.WriteLine(attendanceListBox.Items.Item(i))
Next
For i = 0 To gradeAttendanceListBox.Items.Count - 1
SW.WriteLine(gradeAttendanceListBox.Items.Item(i))
Next
For i = 0 To projectListBox.Items.Count - 1
SW.WriteLine(projectListBox.Items.Item(i))
Next
For i = 0 To gradeProjectListBox.Items.Count - 1
SW.WriteLine(gradeProjectListBox.Items.Item(i))
Next
For i = 0 To otherListBox.Items.Count - 1
SW.WriteLine(otherListBox.Items.Item(i))
Next
For i = 0 To gradeOtherListBox.Items.Count - 1
SW.WriteLine(gradeOtherListBox.Items.Item(i))
Next
SW.Close()
End Sub ' saveButton_Click
Public Sub openFileButton_Click(sender As Object, e As EventArgs) Handles openFileButton.Click
OpenFileDialog1.InitialDirectory = "c:\users\jeremy\desktop"
OpenFileDialog1.Filter = "Text File ONLY (*txt)|*txt"
OpenFileDialog1.ShowDialog()
Dim SR As New StreamReader(OpenFileDialog1.FileName)
nameOfCourseTextBox.Text = SR.ReadLine
creditsTextBox.Text = SR.ReadLine
testTypeLabel.Text = SR.ReadLine
testWeightLabel.Text = SR.ReadLine
attendanceTypeLabel.Text = SR.ReadLine
attendanceWeightLabel.Text = SR.ReadLine
assignmentTypeLabel.Text = SR.ReadLine
assignmentWeightLabel.Text = SR.ReadLine
otherTypeLabel.Text = SR.ReadLine
otherWeightLabel.Text = SR.ReadLine
projectTypeLabel.Text = SR.ReadLine
projectWeightLabel.Text = SR.ReadLine
aTextBox.Text = SR.ReadLine
bTextBox.Text = SR.ReadLine
cTextBox.Text = SR.ReadLine
dTextBox.Text = SR.ReadLine
fTextBox.Text = SR.ReadLine
Do While (SR.Peek() > -1)
testListBox.Items.Add(SR.ReadLine)
Loop
Do While (SR.Peek() > -1)
gradeTestListBox.Items.Add(SR.ReadLine)
Loop
I'm just learning Visual Basic, this is my first semester of this programming class. I'm using Visual Basic 2013. I realize I have a lot to learn. I know that I still need to add comments and what not, but I really just want to get past this particular problem before I continue on to other aspects of the program.
I've tried to add a prefix to the "testListBox.items", for example, and that works, but when I try to use any sort of an if...then statement on the StreamReader part to specify where that line should go, nothing shows up in the listbox. Aside from that, I have no idea how to get a certain line to be written in a certain ListBox. Can anyone help me out here, please? I've read a lot of stuff about using a listview instead of listbox, but I've spend so much time setting all this up, I really don't want to have to do so much of it over again, if there's any other way to make this work. Than
Edit: So, I got rid of the commas, the only thing now is that it's putting the testListBox.items in all the listboxes. Is that because I don't have the loop going anymore, or because of the lack of string.join that you mentioned? If I add the loop back into the mix, the program gets stuck. How is it to account for the what's supposed to be in what listbox? Or should I have gotten rid of the For i =... Then statement from the write section?
' handles saveButton Click
Public Sub saveButton_Click(sender As Object, e As EventArgs) Handles saveButton.Click
SaveFileDialog1.InitialDirectory = "c:\users\jeremy\desktop"
SaveFileDialog1.FileName = (nameOfCourseTextBox.Text)
SaveFileDialog1.Filter = "Text File ONLY (*.txt)|*.txt"
SaveFileDialog1.ShowDialog()
Dim SW As New StreamWriter(SaveFileDialog1.FileName)
Dim i As Integer
SW.WriteLine(nameOfCourseTextBox.Text)
SW.WriteLine(creditsTextBox.Text)
SW.WriteLine(testTypeLabel.Text)
SW.WriteLine(testWeightLabel.Text)
SW.WriteLine(attendanceTypeLabel.Text)
SW.WriteLine(attendanceWeightLabel.Text)
SW.WriteLine(assignmentTypeLabel.Text)
SW.WriteLine(assignmentWeightLabel.Text)
SW.WriteLine(otherTypeLabel.Text)
SW.WriteLine(otherWeightLabel.Text)
SW.WriteLine(projectTypeLabel.Text)
SW.WriteLine(projectWeightLabel.Text)
SW.WriteLine(aTextBox.Text)
SW.WriteLine(bTextBox.Text)
SW.WriteLine(cTextBox.Text)
SW.WriteLine(dTextBox.Text)
SW.WriteLine(fTextBox.Text)
For i = 0 To testListBox.Items.Count - 1
SW.Write(testListBox.Items.Item(i) & ",")
Next i
SW.WriteLine() ' creats new line
For i = 0 To gradeTestListBox.Items.Count - 1
SW.Write(gradeTestListBox.Items.Item(i) & ",")
Next i
SW.WriteLine() ' creats new line
For i = 0 To assignmentListBox.Items.Count - 1
SW.Write(assignmentListBox.Items.Item(i))
Next i
SW.WriteLine() ' creats new line
For i = 0 To gradeAssignmentListBox.Items.Count - 1
SW.Write(gradeAssignmentListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
For i = 0 To attendanceListBox.Items.Count - 1
SW.Write(attendanceListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
For i = 0 To gradeAttendanceListBox.Items.Count - 1
SW.Write(gradeAttendanceListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
For i = 0 To projectListBox.Items.Count - 1
SW.Write(projectListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
For i = 0 To gradeProjectListBox.Items.Count - 1
SW.Write(gradeProjectListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
For i = 0 To otherListBox.Items.Count - 1
SW.Write(otherListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
For i = 0 To gradeOtherListBox.Items.Count - 1
SW.Write(gradeOtherListBox.Items.Item(i))
Next
SW.WriteLine() ' creats new line
SW.Close()
End Sub ' saveButton_Click
Public Sub openFileButton_Click(sender As Object, e As EventArgs) Handles openFileButton.Click
OpenFileDialog1.InitialDirectory = "c:\users\jeremy\desktop"
OpenFileDialog1.Filter = "Text File ONLY (*txt)|*txt"
OpenFileDialog1.ShowDialog()
Dim SR As New StreamReader(OpenFileDialog1.FileName)
nameOfCourseTextBox.Text = SR.ReadLine
creditsTextBox.Text = SR.ReadLine
testTypeLabel.Text = SR.ReadLine
testWeightLabel.Text = SR.ReadLine
attendanceTypeLabel.Text = SR.ReadLine
attendanceWeightLabel.Text = SR.ReadLine
assignmentTypeLabel.Text = SR.ReadLine
assignmentWeightLabel.Text = SR.ReadLine
otherTypeLabel.Text = SR.ReadLine
otherWeightLabel.Text = SR.ReadLine
projectTypeLabel.Text = SR.ReadLine
projectWeightLabel.Text = SR.ReadLine
aTextBox.Text = SR.ReadLine
bTextBox.Text = SR.ReadLine
cTextBox.Text = SR.ReadLine
dTextBox.Text = SR.ReadLine
fTextBox.Text = SR.ReadLine
Dim S As String() = SR.ReadLine.Split(New Char() {","c})
testListBox.Items.AddRange(S)
gradeTestListBox.Items.AddRange(S)
assignmentListBox.Items.AddRange(S)
gradeAssignmentListBox.Items.AddRange(S)
SR.Close()
End Sub

Although I would choose to write this code significantly differently, you're really close to the solution you're looking for. When you write out the listboxes with this code...
For i = 0 To testListBox.Items.Count - 1
SW.Write(testListBox.Items.Item(i) & ",")
Next
SW.WriteLine(); // <<-- Create a new line...
For i = 0 To gradeTestListBox.Items.Count - 1
SW.Write(gradeTestListBox.Items.Item(i) & ",")
Next
...be sure to write a line between them. That way, you've got multiple comma-delimited lines instead of just one long one.
When you read these back in, just do a SR.ReadLine for each comma-delimited line and split it with String.Split. String.Split returns an array of strings and you pass it a comma because that's what you used when joining the strings. (You could also replace your loops that write these lines with String.Join calls to make your code cleaner.)
Dim s As String() = SW.ReadLine().Split(New Char() {","c})
testListBox.Items.AddRange(s)
See this page for examples of VB.NET and Split.
http://www.dotnetperls.com/split-vbnet
EDIT
The only thing left to do is add readline calls for each of your listboxes, like this:
Dim S As String() = SR.ReadLine.Split(New Char() {","c})
testListBox.Items.AddRange(S)
S = SR.ReadLine().Split(New Char() {","c})
gradeTestListBox.Items.AddRange(S)
S = SR.ReadLine().Split(New Char() {","c})
assignmentListBox.Items.AddRange(S)
S = SR.ReadLine().Split(New Char() {","c})
gradeAssignmentListBox.Items.AddRange(S)

Related

how to modify code to allow transpose copied data?

I have a code to insert all data from different excel files located in one folder as a loop ,
but the inserted data comes as a table (Vertically) , here is my question
what is the required modification to the existing code to make the inserted data transpose horizontally??????? thanks in advance
here is the pic of loaded data, i need these table to be shown horizontally
enter image description here
here is my code
Sub Basic_Example_1()
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long, Fnum As Long
Dim mybook As Workbook, BaseWks As Worksheet
Dim sourceRange As Range, destrange As Range
Dim rnum As Long, CalcMode As Long
'Fill in the path\folder where the files are
MyPath = "C:\Users\mjamal\Desktop\Downloads\Sensor1"
'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If
'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xl*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 1
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
Set BaseWks = Worksheets("Sheet1")
rnum = 5
'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
On Error GoTo 0
If Not mybook Is Nothing Then
On Error Resume Next
With mybook.Worksheets(1)
Set sourceRange = .Range("B1:BB7")
End With
If Err.Number > 0 Then
Err.Clear
Set sourceRange = Nothing
Else
'if SourceRange use all columns then skip this file
If sourceRange.Columns.Count >= BaseWks.Columns.Count Then
Set sourceRange = Nothing
End If
End If
On Error GoTo 0
If Not sourceRange Is Nothing Then
SourceRcount = sourceRange.Rows.Count
If rnum + SourceRcount >= BaseWks.Rows.Count Then
MsgBox "Sorry there are not enough rows in the sheet"
BaseWks.Columns.AutoFit
mybook.Close savechanges:=False
GoTo ExitTheSub
Else
'Copy the file name in column A
With sourceRange
BaseWks.Cells(rnum, "C"). _
Resize(.Rows.Count).Value = MyFiles(Fnum)
End With
'Set the destrange
Set destrange = BaseWks.Range("G" & rnum)
'we copy the values from the sourceRange to the destrange
With sourceRange
Set destrange = destrange. _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
rnum = rnum + SourceRcount + 5
End If
End If
mybook.Close savechanges:=False
End If
Next Fnum
BaseWks.Columns.AutoFit
End If
ExitTheSub:
'Restore ScreenUpdating, Calculation and EnableEvents
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub

Can you see anything in this foreach loop that would make it execute twice?

This is "psuedo code" from a workflow that I hope will be more readable than xaml or the design view. The top foreach loop "foreach (DataRow row in dataSetTables[0] as Enumerable())" seems to be executing twice. At least the 2 Rest Calls and the DB insert operation contained inside it are happening twice. I've no idea why a foreach would execute twice.
drpQryStr = "very long query string"
dataSet = new DataSet()
dataSet = ExecuteQuery
if dataSet.Tables[0].Rows.Count > 0
foreach (DataRow row in dataSetTables[0] as Enumerable())
iter = 0
dict = new Dictionary<string, string>()
lst = new List<char>()
newDict = new Dictionary<string, string>()
sb = new StringBuilder()
Do
dict.Add(row.Table.Columns[iter].ColumnName, row[row.Table.Columns[iter].ColumnName].ToString())
iter ++
While(iter < row.Table.Columns.Count)
foreach (KeyValuePair kv in dict)
if(kv.Key == "DOB" || kv.Key == "LOB")
newDict.Add(kv.Key, kv.Value)
else
strKey = kv.Key
strCaseCorrected = strKey.ToLower()
aChars = strCaseCorrected.ToCharArray()
lst.Clear()
sb.Clear()
lst.AddRange(aChars)
itr2 = 0
Do
if(itr2 == 0)
lst[itr2] = Char.ToUpper(lst[itr2])
else
if(lst[itr2] == '_')
itr2 ++
lst[itr2] = Char.ToUpper(lst[itr2])
else
if(lst.Count - itr2 == 1)
if(lst[itr2] == 'd')
if(lst[itr2 - 1] == 'I')
lst[itr2] = 'D'
itr2 ++
While(itr2 < lst.Count)
foreach(Char c in lst)
sb.Append(c.ToStrng()
newDict.Add(sb.ToString(), kv.Value)
dict = newDict
dict[Communiction_Date] = dict["Communication_Date"].Insert(4, "-").Insert(7, "-")
strJson = JsonConvert.SerializeObject(dict, Formatting.None)
today = DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss")
Invoke a Rest Service that posts this json to a sqlless DB
eventStr = "a large string that likely doesn't cause the problem"
ctdbObj = JObject.Parse(eventStr)
Invoke aRest Service that Posts an event to a sqlless DB
cts_id = dict["External_Source_ID"]
strInsert = "sql insert statement"
Execute Insert statement
SendResponse
Yeah neither could I, I thnk the sql query may be running too long and the workflow is being invoked again before it finishes executing. Consider this closed.

Migration Zephyr test-cases steps from Jira server to Jira cloud

Now we are on the process of migration from Jira server to the Jira cloud.
We are using Zephyr for Test Cases.
For now we have 1843 and they must be migrated as other tickets to Jira cloud.
We do not need to migrate all Test Cycles and all history of test execution, we need only Test Cases to use it in future Test Cycles.
This article contains answer on the same question
https://support.getzephyr.com/hc/en-us/community/posts/205799785-How-to-migrate-from-JIRA-Server-to-JIRA-Cloud
but utility doesn't work properly for me, after pressing Start Import button nothing happens.
How to migrate Test Cases from server Jira to cloud with Test Steps in Zephyr?
Finally I found the solution how to import all 1843 Test Cases automatically via tool from the article mention in the question.
Our test-cases were migrated to the cloud Jira as usual tickets. They have no Test Steps but have all other information like Description, Labels and other which relate to Jira fields. Further I will show how to migrate all steps to the migrated Test Cases without steps.
Go to your Jira and Export Test Cases that you need to Excel file. It can be done from this screen
https://zephyrdocs.atlassian.net/wiki/spaces/ZTD/pages/12386325/Search+Test+Executions
Download .jar file from the
https://bitbucket.org/zfjdeveloper/zfj-importer/downloads/
In cmd run this jar file via command java -jar zfj-importer-utility-0.40.jar
I tried to run jar file by double click, application opens but after configuration and press button Start Import nothing happens.
Only after opening from cmd everything works.
Plus in cmd you can see progress and error details which will help you in debug.
Configure utility as in documentation https://bitbucket.org/zfjdeveloper/zfj-importer/wiki/Home
At this point I though that after pressing Start Import everything will be perfect, but no.
In console I found a lot of error, their reason was a lot of line breaks inside test steps.
Lets say you have one step with one row in Step field, one row In Test Data field but in Execution result field you have text with line breaks, lets say 4 rows. For this case in excel Execution result field will be 4 different columns, Step field and Test Data as one merged column.
And based on utility rules there impossible to have result without step. (such issue can be if you have line break in Step field and Test Data).
Below I will show how I handle it.
I decided to write Excel function which will get rows from not merged rows for one step, concatenate them and provide to import.
Excuse me for my VBA, I have never use it before. Everything that I wrote can be rewritten in better way and in one script, but it works for me and I do not want to spend time more on this issue, so let go.
Below you can find 4 excel function. 3 of them are quite similar and difference is only in one letter. Last scrip is for deleting empty rows which were concatenated, without it steps with value "null" will be created.
Public Const lastTableRow = 3872
Function ConvertSteps()
Dim callerRow As Long
Dim isValueInStepId As Boolean
Dim isNoValueInNextStepId As Boolean
Dim result As String
Dim baseColumnLetter As String
Dim stepIdColumnLetter As String
callerRow = Application.Caller.row
baseColumnLetter = "S"
stepIdColumnLetter = "Q"
Debug.Print "processed row is: " & callerRow
isValueInStepId = (Range(stepIdColumnLetter & callerRow).Value <> "")
isNoValueInNextStepId = (Range(stepIdColumnLetter & (callerRow + 1)).Value = "")
If isValueInStepId And isNoValueInNextStepId Then
Dim i As Integer
i = 1
result = Range(baseColumnLetter & callerRow).Value
Do While Range(stepIdColumnLetter & (callerRow + i)).Value = "" And (callerRow + i) <= lastTableRow
result = result & " " & Range(baseColumnLetter & (callerRow + i)).Value
i = i + 1
Loop
ConvertSteps = result
Else
If Range(baseColumnLetter & (callerRow)).Value = "" Then
ConvertSteps = ""
Else
ConvertSteps = Range(baseColumnLetter & (callerRow)).Value
End If
End If
End Function
Function ConvertTestData()
Dim callerRow As Long
Dim isValueInStepId As Boolean
Dim isNoValueInNextStepId As Boolean
Dim result As String
Dim baseColumnLetter As String
Dim stepIdColumnLetter As String
callerRow = Application.Caller.row
baseColumnLetter = "T"
stepIdColumnLetter = "Q"
Debug.Print "processed row is: " & callerRow
isValueInStepId = (Range(stepIdColumnLetter & callerRow).Value <> "")
isNoValueInNextStepId = (Range(stepIdColumnLetter & (callerRow + 1)).Value = "")
If isValueInStepId And isNoValueInNextStepId Then
Dim i As Integer
i = 1
result = Range(baseColumnLetter & callerRow).Value
Do While Range(stepIdColumnLetter & (callerRow + i)).Value = "" And (callerRow + i) <= lastTableRow
result = result & " " & Range(baseColumnLetter & (callerRow + i)).Value
i = i + 1
Loop
ConvertTestData = result
Else
If Range(baseColumnLetter & (callerRow)).Value = "" Then
ConvertTestData = ""
Else
ConvertTestData = Range(baseColumnLetter & (callerRow)).Value
End If
End If
End Function
Function ConvertResult()
Dim callerRow As Long
Dim isValueInStepId As Boolean
Dim isNoValueInNextStepId As Boolean
Dim result As String
Dim baseColumnLetter As String
Dim stepIdColumnLetter As String
callerRow = Application.Caller.row
baseColumnLetter = "U"
stepIdColumnLetter = "Q"
Debug.Print "processed row is: " & callerRow
isValueInStepId = (Range(stepIdColumnLetter & callerRow).Value <> "")
isNoValueInNextStepId = (Range(stepIdColumnLetter & (callerRow + 1)).Value = "")
If isValueInStepId And isNoValueInNextStepId Then
Dim i As Integer
i = 1
result = Range(baseColumnLetter & callerRow).Value
Do While Range(stepIdColumnLetter & (callerRow + i)).Value = "" And (callerRow + i) <= lastTableRow
result = result & " " & Range(baseColumnLetter & (callerRow + i)).Value
i = i + 1
Loop
ConvertResult = result
Else
If Range(baseColumnLetter & (callerRow)).Value = "" Then
ConvertResult = ""
Else
ConvertResult = Range(baseColumnLetter & (callerRow)).Value
End If
End If
End Function
Public Sub DeleteBlankRows()
Dim SourceRange As Range
Dim EntireRow As Range
Set SourceRange = Range("Q1", "Q" & lastTableRow)
If Not (SourceRange Is Nothing) Then
Application.ScreenUpdating = False
For i = SourceRange.Rows.Count To 1 Step -1
Set EntireRow = SourceRange.Cells(i, 1).EntireRow
Debug.Print SourceRange.Cells(i, 1).Value
If SourceRange.Cells(i, 1).Value = 0 Then
EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
End If
End Sub
Let's open Excel file and save it in .xlsm format to apply custom functions.
Import functions to Excel
in the top of the code set in variable lastTableRow last row with Test Case step in your Excel.
Now we need 3 new columns to save transferred Step, Test Data and Result fields. For this purpose we can use last column Comments, copy and past it two times. Now we have 3 empty column W, X, Y for our purpose.
For all rows in column W apply formula =ConvertSteps() to agregate steps (it can take some time)
For all rows in column X apply formula =ConvertTestData() to agregate test data (it can take some time)
For all rows in column Y apply formula =ConvertResult() to agregate results (it can take some time)
Now we have to convert values in new columns from formula to their string value. To do it select all table and press Ctrl+C. Then press right button and choose past values.
Run DeleteBlankRows macros to delete all rows that we do not need to import.
Save file in .xml format.
Choose this file in Utility and press Start Import
In cmd you can see a few errors. In my case they were releted to situation when there is no step description but there is expected result. If they are quite seldom as in my case, it's easier to change it mannualy in Execel file. If there a lot of them you can handle this case in custom function.
So thats it, this solution helped me to import 1800+ Test Cases.
I have exported them partially, by 500 and for me it takes about 3 hour to import all Test Cases.

Match Data In Two Files Then Email Each Person

For simplicity, file1.txt is a log file for which I extract logonIds into an array. File2.txt contains rows of logonID,emailAddress,other,needless,data
I need to take all of the logonIDs read into my array from file1 and extract their email addresses from file2. Once I have this information, I can then send each person in file1 an email. Can't just use file2.txt because it contains users who should not receive an email.
I wrote vbscript that extracts logonIDs from file1.txt into array and pulls logonID and email from file2.txt
inFile1 = "C:\Scripts\testvbs\wscreatestatus.txt"
inFile2 = "C:\Scripts\testvbs\WSBatchCreateBuildsList.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile1 = objFSO.OpenTextFile(inFile1, ForReading)
Set objInFile2 = objFSO.OpenTextFile(inFile2, ForReading)
'Creates Array of all DomainIDs for successful deployments
Do Until objInFile1.AtEndOfStream
strNextLine = objInFile1.Readline
arrLogons = Split(strNextLine , vbTab)
If arrLogons(0) = "DEPLOYSUCCESS" Then
arrUserIDList = arrUserIDList & arrLogons(5) & vbCrLf
End If
Loop
Do Until objInFile2.AtEndOfStream
strNextLine = objInFile2.Readline
arrAddressList = Split(strNextLine , ",")
arrMailList = arrMailList & arrAddressList(0) & vbTab & arrAddressList(1) & vbCrLf
Loop
What I need to do next is take my list of user IDs "arrUserIDList", and extract their email address from arrMailList. With this information I can send each user in file1.txt (wscreatestatus.txt) an email.
Thanks!
From the way you construct your arrMailList, I presume you want the selected LogonID's and corresponding email addresses output to a new Tab delimited text file.
If that is the case, I recommend using ArrayList objects to store the values in. ArrayLists have an easy to use Add method and for testing if an item is in an ArrayList, there is the Contains method.
In Code:
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim inFile1, inFile2, outFile, objFSO, objInFile, objOutFile
Dim strNextLine, fields, arrUserIDList, arrMailList
inFile1 = "C:\Scripts\testvbs\wscreatestatus.txt"
inFile2 = "C:\Scripts\testvbs\WSBatchCreateBuildsList.txt"
outFile = "C:\Scripts\testvbs\WSEmailDeploySuccess.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(inFile1, ForReading)
'Create an ArrayList of all DomainIDs for successful deployments
Set arrUserIDList = CreateObject( "System.Collections.ArrayList" )
Do Until objInFile.AtEndOfStream
strNextLine = objInFile.Readline
fields = Split(strNextLine , vbTab)
If fields(0) = "DEPLOYSUCCESS" Then
arrUserIDList.Add fields(5)
End If
Loop
'close the first input file
objInFile.Close
'Now read the second file and read the logonID's from it
Set objInFile = objFSO.OpenTextFile(inFile2, ForReading)
'Create an ArrayList of all LogonID's, a TAB character and the EmailAddress
Set arrMailList = CreateObject( "System.Collections.ArrayList" )
Do Until objInFile.AtEndOfStream
strNextLine = objInFile.Readline
fields = Split(strNextLine , ",")
If arrUserIDList.Contains(fields(0)) Then
' store the values in arrMailList as TAB separated values
arrMailList.Add fields(0) & vbTab & fields(1)
End If
Loop
'close the file and destroy the object
objInFile.Close
Set objInFile = Nothing
Set objOutFile = objFSO.OpenTextFile(outFile, ForWriting, True)
For Each strNextLine In arrMailList
objOutFile.WriteLine(strNextLine)
Next
'close the file and destroy the object
objOutFile.Close
Set objOutFile = Nothing
'clean up the other objects
Set objFSO = Nothing
Set arrUserIDList = Nothing
Set arrMailList = Nothing
Hope that helps
This is how I solved my problem, but I think Theo took a better approach.
Const ForReading = 1
Const ForWriting = 2
Dim inFile1, inFile2, strNextLine, arrServiceList, arrUserList
Dim arrUserDeployList, strLine, arrList, outFile, strItem1, strItem2
inFile1 = Wscript.Arguments.Item(0) 'wscreatestatus.txt file (tab delimited)
inFile2 = Wscript.Arguments.Item(1) 'WSBatchCreateBuildsList.txt (comma delimited)
outFile = Wscript.Arguments.Item(2) 'SuccessWSMailList###.txt (for Welcome emails)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile1 = objFSO.OpenTextFile(inFile1, ForReading)
Set objInFile2 = objFSO.OpenTextFile(inFile2, ForReading)
Set objOutFile = objFSO.CreateTextFile(outFile, ForWriting, True)
'Extracts Logon ID's for successfull deployments into an Array
'#================================================================
i = 0
Do Until objInFile1.AtEndOfStream
ReDim Preserve arrUsers(i)
strNextLine = objInFile1.Readline
arrLogons = Split(strNextLine , vbTab)
If arrLogons(0) = "PENDINGREQUESTS" Then
arrUsers(i) = arrLogons(5)
i = i + 1
End If
Loop
'Extracts success deploy email addresses and writes to file
'#================================================================
Do Until objInFile2.AtEndOfStream
ReDim Preserve arrMailList(i)
strNextLine = objInFile2.Readline
arrAddressList = Split(strNextLine , ",")
strItem1 = arrAddressList(0)
strItem2 = arrAddressList(1)
For Each strArrayEntry In arrUsers
If strArrayEntry = strItem1 Then
objOutFile.WriteLine strItem1 & "," & strItem2
End If
Next
i = i + 1
Loop
objOutFile.Close
objInFile1.Close
objInFile2.Close

Open Office Spreadsheet (Calc) - Concatenate text cells with delimiters

I am using Open Office's spreadsheet program and am trying to concatenate several text cells together with delimeters. For example, suppose I have the cells below:
+--------+
| cell 1 |
+--------+
| cell 2 |
+--------+
| cell 3 |
+--------+
| cell 4 |
+--------+
| cell 5 |
+--------+
I would like to concatenate them with delimiters so that the result is in one cell like this one:
+----------------------------------------------+
| (cell 1),(cell 2),(cell 3),(cell 4),(cell 5) |
+----------------------------------------------+
My first thought was to try and make a macro or something, but I don't think open office supports those. Any ideas?
Thanks a lot Markus for finding a solution to this.
Here are some slightly more detailed instructions for the benefit of OpenOffice Basic newbies like myself. This applies to version 3.1:
Tools -> Macros -> Organize Macros -> OpenOffice.org Basic...
Now select from the explorer tree where you want your function live,
e.g. it can be in your own macro library (My Macros / Standard) or
stored directly in the current spreadsheet.
Now enter a new Macro name and click New to open the OO.org Basic IDE. You'll see a REM
statement and some stub Sub definitions. Delete all that and replace
it with:
Function STRJOIN(range, Optional delimiter As String, Optional before As String, Optional after As String)
Dim row, col As Integer
Dim result, cell As String
result = ""
If IsMissing(delimiter) Then
delimiter = ","
End If
If IsMissing(before) Then
before = ""
End If
If IsMissing(after) Then
after = ""
End If
If NOT IsMissing(range) Then
If NOT IsArray(range) Then
result = before & range & after
Else
For row = LBound(range, 1) To UBound(range, 1)
For col = LBound(range, 2) To UBound(range, 2)
cell = range(row, col)
If cell <> 0 AND Len(Trim(cell)) <> 0 Then
If result <> "" Then
result = result & delimiter
End If
result = result & before & range(row, col) & after
End If
Next
Next
End If
End If
STRJOIN = result
End Function
The above code has some slight improvements from Markus' original:
Doesn't start with a delimiter when the first cell in the range is empty.
Allows optional choice of the delimiter (defaults to ","), and the
strings which go before and after each non-blank entry in the range
(default to "").
I renamed it STRJOIN since "join" is the typical name of this
function in several popular languages, such as Perl, Python, and Ruby.
Variables all lowercase
Now save the macro, go to the cell where you want the join to appear,
and type:
=STRJOIN(C3:C50)
replacing C3:C50 with the range of strings you want to join.
To customise the delimiter, instead use something like:
=STRJOIN(C3:C50; " / ")
If you wanted to join a bunch of email addresses, you could use:
=STRJOIN(C3:C50; ", "; "<"; ">")
and the result would be something like
<foo#bar.com>, <baz#qux.org>, <another#email.address>, <and#so.on>
Well, after a lot more searching and experimenting, I found you can make your own functions in calc. This is a function I made that does what I want:
Function STRCONCAT(range)
Dim Row, Col As Integer
Dim Result As String
Dim Temp As String
Result = ""
Temp = ""
If NOT IsMissing(range) Then
If NOT IsArray(range) Then
Result = "(" & range & ")"
Else
For Row = LBound(range, 1) To UBound(range, 1)
For Col = LBound(range, 2) To UBound(range, 2)
Temp = range(Row, Col)
Temp = Trim(Temp)
If range(Row, Col) <> 0 AND Len(Temp) <> 0 Then
If(NOT (Row = 1 AND Col = 1)) Then Result = Result & ", "
Result = Result & "(" & range(Row, Col) & ") "
End If
Next
Next
End If
End If
STRCONCAT = Result
End Function
Ever so often I'd enjoy the ease and quickness of replace & calculation Options as well as in general the quick handling & modifying Options, when once again sitting in front of a dumped-file-lists or whatsoever.
I never understood why they didn't include such an essential function right from the start, really.
It's based on Adam's script, but with the extension to swap CONCAT from horizontal to vertical, while still keeping the delimiters in order.
Function CONCAT2D(Optional range, Optional delx As String, Optional dely As String, _
Optional xcell As String, Optional cellx As String, _
Optional swop As Integer)
Dim xy(1), xyi(1), s(1) As Integer
Dim out, cell, del, dxy(1) As String
'ReDim range(2, 1) 'Gen.RandomMatrix 4 Debugging
'For i = LBound(range, 1) To UBound(range, 1)
' For j = LBound(range, 2) To UBound(range, 2)
' Randomize
' range(i,j) = Int((100 * Rnd) )
' Next
'Next
out = ""
If IsMissing(delx) Then : delx = "," : End If
If IsMissing(dely) Then : dely = delx() : End If
If IsMissing(xcell) Then : xcell = "" : End If
If IsMissing(cellx) Then : cellx = xcell() : End If
If IsMissing(swop) Then : swop = 0 : End If
dxy(0) = delx() : dxy(1) = dely()
xyi(0) = 1 : xyi(1) = 2
If swop = 0 Then : s(0) = 0 : s(1) = 1
Else s(0) = 1 : s(1) = 0 : End If
If NOT IsMissing(range) Then
If NOT IsArray(range) _
Then : out = xcell & range & cellx
Else del = delx
For xy(s(0)) = LBound(range, xyi(s(0))) To UBound(range, xyi(s(0))
For xy(s(1)) = LBound(range, xyi(s(1))) To UBound(range, xyi(s(1))
cell = range(xy(0), xy(1))
If cell <> 0 AND Len(Trim(cell)) <> 0 _
Then : If out <> "" Then : out = out & del : End If
out = out & xcell & cell & cellx
del = dxy(s(0))
End If
Next : del = dxy(s(1))
Next
End If
Else out = "ERR"
End If
CONCAT2D = out
End Function

Resources